OLD | NEW |
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 |
| 43 } // namespace |
| 44 |
22 // static | 45 // static |
23 InMemoryURLIndex* InMemoryURLIndexFactory::GetForBrowserState( | 46 InMemoryURLIndex* InMemoryURLIndexFactory::GetForBrowserState( |
24 ios::ChromeBrowserState* browser_state) { | 47 ios::ChromeBrowserState* browser_state) { |
25 return static_cast<InMemoryURLIndex*>( | 48 return static_cast<InMemoryURLIndex*>( |
26 GetInstance()->GetServiceForBrowserState(browser_state, true)); | 49 GetInstance()->GetServiceForBrowserState(browser_state, true)); |
27 } | 50 } |
28 | 51 |
29 // static | 52 // static |
30 InMemoryURLIndexFactory* InMemoryURLIndexFactory::GetInstance() { | 53 InMemoryURLIndexFactory* InMemoryURLIndexFactory::GetInstance() { |
31 return base::Singleton<InMemoryURLIndexFactory>::get(); | 54 return base::Singleton<InMemoryURLIndexFactory>::get(); |
32 } | 55 } |
33 | 56 |
34 InMemoryURLIndexFactory::InMemoryURLIndexFactory() | 57 InMemoryURLIndexFactory::InMemoryURLIndexFactory() |
35 : BrowserStateKeyedServiceFactory( | 58 : BrowserStateKeyedServiceFactory( |
36 "InMemoryURLIndex", | 59 "InMemoryURLIndex", |
37 BrowserStateDependencyManager::GetInstance()) { | 60 BrowserStateDependencyManager::GetInstance()) { |
38 DependsOn(ios::BookmarkModelFactory::GetInstance()); | 61 DependsOn(ios::BookmarkModelFactory::GetInstance()); |
39 DependsOn(ios::HistoryServiceFactory::GetInstance()); | 62 DependsOn(ios::HistoryServiceFactory::GetInstance()); |
40 } | 63 } |
41 | 64 |
42 InMemoryURLIndexFactory::~InMemoryURLIndexFactory() {} | 65 InMemoryURLIndexFactory::~InMemoryURLIndexFactory() {} |
43 | 66 |
| 67 // static |
| 68 BrowserStateKeyedServiceFactory::TestingFactoryFunction |
| 69 InMemoryURLIndexFactory::GetDefaultFactory() { |
| 70 return &BuildInMemoryURLIndex; |
| 71 } |
| 72 |
44 scoped_ptr<KeyedService> InMemoryURLIndexFactory::BuildServiceInstanceFor( | 73 scoped_ptr<KeyedService> InMemoryURLIndexFactory::BuildServiceInstanceFor( |
45 web::BrowserState* context) const { | 74 web::BrowserState* context) const { |
46 ios::ChromeBrowserState* browser_state = | 75 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 } | 76 } |
63 | 77 |
64 web::BrowserState* InMemoryURLIndexFactory::GetBrowserStateToUse( | 78 web::BrowserState* InMemoryURLIndexFactory::GetBrowserStateToUse( |
65 web::BrowserState* context) const { | 79 web::BrowserState* context) const { |
66 return GetBrowserStateRedirectedInIncognito(context); | 80 return GetBrowserStateRedirectedInIncognito(context); |
67 } | 81 } |
68 | 82 |
69 bool InMemoryURLIndexFactory::ServiceIsNULLWhileTesting() const { | 83 bool InMemoryURLIndexFactory::ServiceIsNULLWhileTesting() const { |
70 return true; | 84 return true; |
71 } | 85 } |
72 | 86 |
73 } // namespace ios | 87 } // namespace ios |
OLD | NEW |