blob: d7967ccf3312d01f510ad292b9d36e23ea28e298 (
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
|
// 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/autocomplete/in_memory_url_index_factory.h"
#include <utility>
#include "base/memory/singleton.h"
#include "components/keyed_service/core/service_access_type.h"
#include "components/keyed_service/ios/browser_state_dependency_manager.h"
#include "components/omnibox/browser/in_memory_url_index.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/chrome_url_constants.h"
#include "ios/chrome/browser/history/history_service_factory.h"
#include "ios/chrome/browser/pref_names.h"
#include "ios/chrome/browser/search_engines/template_url_service_factory.h"
#include "ios/web/public/web_thread.h"
namespace ios {
namespace {
scoped_ptr<KeyedService> BuildInMemoryURLIndex(web::BrowserState* context) {
ios::ChromeBrowserState* browser_state =
ios::ChromeBrowserState::FromBrowserState(context);
SchemeSet schemes_to_whilelist;
schemes_to_whilelist.insert(kChromeUIScheme);
// Do not force creation of the HistoryService if saving history is disabled.
scoped_ptr<InMemoryURLIndex> in_memory_url_index(new InMemoryURLIndex(
ios::BookmarkModelFactory::GetForBrowserState(browser_state),
ios::HistoryServiceFactory::GetForBrowserState(
browser_state, ServiceAccessType::IMPLICIT_ACCESS),
ios::TemplateURLServiceFactory::GetForBrowserState(browser_state),
web::WebThread::GetBlockingPool(), browser_state->GetStatePath(),
browser_state->GetPrefs()->GetString(prefs::kAcceptLanguages),
schemes_to_whilelist));
in_memory_url_index->Init();
return std::move(in_memory_url_index);
}
} // namespace
// static
InMemoryURLIndex* InMemoryURLIndexFactory::GetForBrowserState(
ios::ChromeBrowserState* browser_state) {
return static_cast<InMemoryURLIndex*>(
GetInstance()->GetServiceForBrowserState(browser_state, true));
}
// static
InMemoryURLIndexFactory* InMemoryURLIndexFactory::GetInstance() {
return base::Singleton<InMemoryURLIndexFactory>::get();
}
InMemoryURLIndexFactory::InMemoryURLIndexFactory()
: BrowserStateKeyedServiceFactory(
"InMemoryURLIndex",
BrowserStateDependencyManager::GetInstance()) {
DependsOn(ios::BookmarkModelFactory::GetInstance());
DependsOn(ios::HistoryServiceFactory::GetInstance());
DependsOn(ios::TemplateURLServiceFactory::GetInstance());
}
InMemoryURLIndexFactory::~InMemoryURLIndexFactory() {}
// static
BrowserStateKeyedServiceFactory::TestingFactoryFunction
InMemoryURLIndexFactory::GetDefaultFactory() {
return &BuildInMemoryURLIndex;
}
scoped_ptr<KeyedService> InMemoryURLIndexFactory::BuildServiceInstanceFor(
web::BrowserState* context) const {
return BuildInMemoryURLIndex(context);
}
web::BrowserState* InMemoryURLIndexFactory::GetBrowserStateToUse(
web::BrowserState* context) const {
return GetBrowserStateRedirectedInIncognito(context);
}
bool InMemoryURLIndexFactory::ServiceIsNULLWhileTesting() const {
return true;
}
} // namespace ios
|