blob: c51102961d2e7a8d0d01f9f6f07a1a3d062efc36 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ios/chrome/browser/history/history_service_factory.h"
#include <utility>
#include "base/memory/singleton.h"
#include "components/history/core/browser/history_database_params.h"
#include "components/history/core/browser/history_service.h"
#include "components/history/core/browser/visit_delegate.h"
#include "components/history/ios/browser/history_database_helper.h"
#include "components/keyed_service/core/service_access_type.h"
#include "components/keyed_service/ios/browser_state_dependency_manager.h"
#include "components/prefs/pref_service.h"
#include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
#include "ios/chrome/browser/browser_state/browser_state_otr_helper.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/history/history_client_impl.h"
#include "ios/chrome/browser/pref_names.h"
namespace ios {
// static
history::HistoryService* HistoryServiceFactory::GetForBrowserState(
ios::ChromeBrowserState* browser_state,
ServiceAccessType access_type) {
// If saving history is disabled, only allow explicit access.
if (access_type != ServiceAccessType::EXPLICIT_ACCESS &&
browser_state->GetPrefs()->GetBoolean(
prefs::kSavingBrowserHistoryDisabled)) {
return nullptr;
}
return static_cast<history::HistoryService*>(
GetInstance()->GetServiceForBrowserState(browser_state, true));
}
// static
history::HistoryService* HistoryServiceFactory::GetForBrowserStateIfExists(
ios::ChromeBrowserState* browser_state,
ServiceAccessType access_type) {
// If saving history is disabled, only allow explicit access.
if (access_type != ServiceAccessType::EXPLICIT_ACCESS &&
browser_state->GetPrefs()->GetBoolean(
prefs::kSavingBrowserHistoryDisabled)) {
return nullptr;
}
return static_cast<history::HistoryService*>(
GetInstance()->GetServiceForBrowserState(browser_state, true));
}
// static
HistoryServiceFactory* HistoryServiceFactory::GetInstance() {
return base::Singleton<HistoryServiceFactory>::get();
}
HistoryServiceFactory::HistoryServiceFactory()
: BrowserStateKeyedServiceFactory(
"HistoryService",
BrowserStateDependencyManager::GetInstance()) {
DependsOn(ios::BookmarkModelFactory::GetInstance());
}
HistoryServiceFactory::~HistoryServiceFactory() {
}
scoped_ptr<KeyedService> HistoryServiceFactory::BuildServiceInstanceFor(
web::BrowserState* context) const {
ios::ChromeBrowserState* browser_state =
ios::ChromeBrowserState::FromBrowserState(context);
scoped_ptr<history::HistoryService> history_service(
new history::HistoryService(
make_scoped_ptr(new HistoryClientImpl(
ios::BookmarkModelFactory::GetForBrowserState(browser_state))),
nullptr));
if (!history_service->Init(
browser_state->GetPrefs()->GetString(prefs::kAcceptLanguages),
history::HistoryDatabaseParamsForPath(
browser_state->GetStatePath()))) {
return nullptr;
}
return std::move(history_service);
}
web::BrowserState* HistoryServiceFactory::GetBrowserStateToUse(
web::BrowserState* context) const {
return GetBrowserStateRedirectedInIncognito(context);
}
bool HistoryServiceFactory::ServiceIsNULLWhileTesting() const {
return true;
}
} // namespace ios
|