1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ios/chrome/browser/autocomplete/in_memory_url_index_factory.h"
7 #include "base/memory/singleton.h"
8 #include "base/prefs/pref_service.h"
9 #include "components/keyed_service/core/service_access_type.h"
10 #include "components/keyed_service/ios/browser_state_dependency_manager.h"
11 #include "components/omnibox/browser/in_memory_url_index.h"
12 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
13 #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h"
14 #include "ios/chrome/browser/history/history_service_factory.h"
15 #include "ios/chrome/browser/pref_names.h"
16 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
17 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
18 #include "ios/web/public/web_thread.h"
23 InMemoryURLIndex
* InMemoryURLIndexFactory::GetForBrowserState(
24 ios::ChromeBrowserState
* browser_state
) {
25 return static_cast<InMemoryURLIndex
*>(
26 GetInstance()->GetServiceForBrowserState(browser_state
, true));
30 InMemoryURLIndexFactory
* InMemoryURLIndexFactory::GetInstance() {
31 return Singleton
<InMemoryURLIndexFactory
>::get();
34 InMemoryURLIndexFactory::InMemoryURLIndexFactory()
35 : BrowserStateKeyedServiceFactory(
37 BrowserStateDependencyManager::GetInstance()) {
38 DependsOn(ios::BookmarkModelFactory::GetInstance());
39 DependsOn(ios::HistoryServiceFactory::GetInstance());
42 InMemoryURLIndexFactory::~InMemoryURLIndexFactory() {}
44 scoped_ptr
<KeyedService
> InMemoryURLIndexFactory::BuildServiceInstanceFor(
45 web::BrowserState
* context
) const {
46 ios::ChromeBrowserState
* browser_state
=
47 ios::ChromeBrowserState::FromBrowserState(context
);
49 SchemeSet schemes_to_whilelist
;
50 schemes_to_whilelist
.insert(
51 ios::GetChromeBrowserProvider()->GetChromeUIScheme());
53 // Do not force creation of the HistoryService if saving history is disabled.
54 scoped_ptr
<InMemoryURLIndex
> in_memory_url_index(new InMemoryURLIndex(
55 ios::BookmarkModelFactory::GetForBrowserState(browser_state
),
56 ios::HistoryServiceFactory::GetForBrowserState(
57 browser_state
, ServiceAccessType::IMPLICIT_ACCESS
),
58 web::WebThread::GetBlockingPool(), browser_state
->GetStatePath(),
59 browser_state
->GetPrefs()->GetString(ios::prefs::kAcceptLanguages
),
60 schemes_to_whilelist
));
61 in_memory_url_index
->Init();
62 return in_memory_url_index
.Pass();
65 web::BrowserState
* InMemoryURLIndexFactory::GetBrowserStateToUse(
66 web::BrowserState
* context
) const {
67 return GetBrowserStateRedirectedInIncognito(context
);
70 bool InMemoryURLIndexFactory::ServiceIsNULLWhileTesting() const {