Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: ios/chrome/browser/autocomplete/in_memory_url_index_factory.cc

Issue 1405093012: [iOS] Add InMemoryURLIndexFactory::GetDefaultFactory() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ios/chrome/browser/autocomplete/in_memory_url_index_factory.h" 5 #include "ios/chrome/browser/autocomplete/in_memory_url_index_factory.h"
6 6
7 #include "base/memory/singleton.h" 7 #include "base/memory/singleton.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "components/keyed_service/core/service_access_type.h" 9 #include "components/keyed_service/core/service_access_type.h"
10 #include "components/keyed_service/ios/browser_state_dependency_manager.h" 10 #include "components/keyed_service/ios/browser_state_dependency_manager.h"
11 #include "components/omnibox/browser/in_memory_url_index.h" 11 #include "components/omnibox/browser/in_memory_url_index.h"
12 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" 12 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
13 #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h" 13 #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h"
14 #include "ios/chrome/browser/chrome_url_constants.h" 14 #include "ios/chrome/browser/chrome_url_constants.h"
15 #include "ios/chrome/browser/history/history_service_factory.h" 15 #include "ios/chrome/browser/history/history_service_factory.h"
16 #include "ios/chrome/browser/pref_names.h" 16 #include "ios/chrome/browser/pref_names.h"
17 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state. h" 17 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state. h"
18 #include "ios/web/public/web_thread.h" 18 #include "ios/web/public/web_thread.h"
19 19
20 namespace ios { 20 namespace ios {
21 21
22 namespace {
23
24 scoped_ptr<KeyedService> BuildInMemoryURLIndex(web::BrowserState* context) {
25 ios::ChromeBrowserState* browser_state =
26 ios::ChromeBrowserState::FromBrowserState(context);
27
28 SchemeSet schemes_to_whilelist;
29 schemes_to_whilelist.insert(kChromeUIScheme);
30
31 // Do not force creation of the HistoryService if saving history is disabled.
32 scoped_ptr<InMemoryURLIndex> in_memory_url_index(new InMemoryURLIndex(
33 ios::BookmarkModelFactory::GetForBrowserState(browser_state),
34 ios::HistoryServiceFactory::GetForBrowserState(
35 browser_state, ServiceAccessType::IMPLICIT_ACCESS),
36 web::WebThread::GetBlockingPool(), browser_state->GetStatePath(),
37 browser_state->GetPrefs()->GetString(ios::prefs::kAcceptLanguages),
38 schemes_to_whilelist));
39 in_memory_url_index->Init();
40 return in_memory_url_index.Pass();
41 }
42 }
sdefresne 2015/11/05 14:58:59 You need "// namespace" and I'd prefer if you eith
43
22 // static 44 // static
23 InMemoryURLIndex* InMemoryURLIndexFactory::GetForBrowserState( 45 InMemoryURLIndex* InMemoryURLIndexFactory::GetForBrowserState(
24 ios::ChromeBrowserState* browser_state) { 46 ios::ChromeBrowserState* browser_state) {
25 return static_cast<InMemoryURLIndex*>( 47 return static_cast<InMemoryURLIndex*>(
26 GetInstance()->GetServiceForBrowserState(browser_state, true)); 48 GetInstance()->GetServiceForBrowserState(browser_state, true));
27 } 49 }
28 50
29 // static 51 // static
30 InMemoryURLIndexFactory* InMemoryURLIndexFactory::GetInstance() { 52 InMemoryURLIndexFactory* InMemoryURLIndexFactory::GetInstance() {
31 return base::Singleton<InMemoryURLIndexFactory>::get(); 53 return base::Singleton<InMemoryURLIndexFactory>::get();
32 } 54 }
33 55
34 InMemoryURLIndexFactory::InMemoryURLIndexFactory() 56 InMemoryURLIndexFactory::InMemoryURLIndexFactory()
35 : BrowserStateKeyedServiceFactory( 57 : BrowserStateKeyedServiceFactory(
36 "InMemoryURLIndex", 58 "InMemoryURLIndex",
37 BrowserStateDependencyManager::GetInstance()) { 59 BrowserStateDependencyManager::GetInstance()) {
38 DependsOn(ios::BookmarkModelFactory::GetInstance()); 60 DependsOn(ios::BookmarkModelFactory::GetInstance());
39 DependsOn(ios::HistoryServiceFactory::GetInstance()); 61 DependsOn(ios::HistoryServiceFactory::GetInstance());
40 } 62 }
41 63
42 InMemoryURLIndexFactory::~InMemoryURLIndexFactory() {} 64 InMemoryURLIndexFactory::~InMemoryURLIndexFactory() {}
43 65
66 // static
67 BrowserStateKeyedServiceFactory::TestingFactoryFunction
68 InMemoryURLIndexFactory::GetDefaultFactory() {
69 return &BuildInMemoryURLIndex;
70 }
71
44 scoped_ptr<KeyedService> InMemoryURLIndexFactory::BuildServiceInstanceFor( 72 scoped_ptr<KeyedService> InMemoryURLIndexFactory::BuildServiceInstanceFor(
45 web::BrowserState* context) const { 73 web::BrowserState* context) const {
46 ios::ChromeBrowserState* browser_state = 74 return BuildInMemoryURLIndex(context);
47 ios::ChromeBrowserState::FromBrowserState(context);
48
49 SchemeSet schemes_to_whilelist;
50 schemes_to_whilelist.insert(kChromeUIScheme);
51
52 // Do not force creation of the HistoryService if saving history is disabled.
53 scoped_ptr<InMemoryURLIndex> in_memory_url_index(new InMemoryURLIndex(
54 ios::BookmarkModelFactory::GetForBrowserState(browser_state),
55 ios::HistoryServiceFactory::GetForBrowserState(
56 browser_state, ServiceAccessType::IMPLICIT_ACCESS),
57 web::WebThread::GetBlockingPool(), browser_state->GetStatePath(),
58 browser_state->GetPrefs()->GetString(ios::prefs::kAcceptLanguages),
59 schemes_to_whilelist));
60 in_memory_url_index->Init();
61 return in_memory_url_index.Pass();
62 } 75 }
63 76
64 web::BrowserState* InMemoryURLIndexFactory::GetBrowserStateToUse( 77 web::BrowserState* InMemoryURLIndexFactory::GetBrowserStateToUse(
65 web::BrowserState* context) const { 78 web::BrowserState* context) const {
66 return GetBrowserStateRedirectedInIncognito(context); 79 return GetBrowserStateRedirectedInIncognito(context);
67 } 80 }
68 81
69 bool InMemoryURLIndexFactory::ServiceIsNULLWhileTesting() const { 82 bool InMemoryURLIndexFactory::ServiceIsNULLWhileTesting() const {
70 return true; 83 return true;
71 } 84 }
72 85
73 } // namespace ios 86 } // namespace ios
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698