| 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 "chrome/browser/autocomplete/in_memory_url_index_factory.h" | 5 #include "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 "chrome/browser/autocomplete/in_memory_url_index.h" | 9 #include "chrome/browser/autocomplete/in_memory_url_index.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 11 #include "chrome/browser/history/history_service_factory.h" | 11 #include "chrome/browser/history/history_service_factory.h" |
| 12 #include "chrome/browser/profiles/incognito_helpers.h" | 12 #include "chrome/browser/profiles/incognito_helpers.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 15 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 15 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 16 #include "components/keyed_service/core/service_access_type.h" | 16 #include "components/keyed_service/core/service_access_type.h" |
| 17 #include "content/public/browser/browser_thread.h" | |
| 18 #include "content/public/common/url_constants.h" | |
| 19 | 17 |
| 20 // static | 18 // static |
| 21 InMemoryURLIndex* InMemoryURLIndexFactory::GetForProfile(Profile* profile) { | 19 InMemoryURLIndex* InMemoryURLIndexFactory::GetForProfile(Profile* profile) { |
| 22 return static_cast<InMemoryURLIndex*>( | 20 return static_cast<InMemoryURLIndex*>( |
| 23 GetInstance()->GetServiceForBrowserContext(profile, true)); | 21 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 24 } | 22 } |
| 25 | 23 |
| 26 // static | 24 // static |
| 27 InMemoryURLIndexFactory* InMemoryURLIndexFactory::GetInstance() { | 25 InMemoryURLIndexFactory* InMemoryURLIndexFactory::GetInstance() { |
| 28 return Singleton<InMemoryURLIndexFactory>::get(); | 26 return Singleton<InMemoryURLIndexFactory>::get(); |
| 29 } | 27 } |
| 30 | 28 |
| 31 InMemoryURLIndexFactory::InMemoryURLIndexFactory() | 29 InMemoryURLIndexFactory::InMemoryURLIndexFactory() |
| 32 : BrowserContextKeyedServiceFactory( | 30 : BrowserContextKeyedServiceFactory( |
| 33 "InMemoryURLIndex", | 31 "InMemoryURLIndex", |
| 34 BrowserContextDependencyManager::GetInstance()) { | 32 BrowserContextDependencyManager::GetInstance()) { |
| 35 DependsOn(BookmarkModelFactory::GetInstance()); | 33 DependsOn(BookmarkModelFactory::GetInstance()); |
| 36 DependsOn(HistoryServiceFactory::GetInstance()); | 34 DependsOn(HistoryServiceFactory::GetInstance()); |
| 37 } | 35 } |
| 38 | 36 |
| 39 InMemoryURLIndexFactory::~InMemoryURLIndexFactory() { | 37 InMemoryURLIndexFactory::~InMemoryURLIndexFactory() { |
| 40 } | 38 } |
| 41 | 39 |
| 42 KeyedService* InMemoryURLIndexFactory::BuildServiceInstanceFor( | 40 KeyedService* InMemoryURLIndexFactory::BuildServiceInstanceFor( |
| 43 content::BrowserContext* context) const { | 41 content::BrowserContext* context) const { |
| 44 // Do not force creation of the HistoryService if saving history is disabled. | 42 // Do not force creation of the HistoryService if saving history is disabled. |
| 45 Profile* profile = Profile::FromBrowserContext(context); | 43 Profile* profile = Profile::FromBrowserContext(context); |
| 46 SchemeSet chrome_schemes_to_whitelist; | |
| 47 chrome_schemes_to_whitelist.insert(content::kChromeUIScheme); | |
| 48 InMemoryURLIndex* in_memory_url_index = new InMemoryURLIndex( | 44 InMemoryURLIndex* in_memory_url_index = new InMemoryURLIndex( |
| 49 BookmarkModelFactory::GetForProfile(profile), | 45 BookmarkModelFactory::GetForProfile(profile), |
| 50 HistoryServiceFactory::GetForProfile(profile, | 46 HistoryServiceFactory::GetForProfile(profile, |
| 51 ServiceAccessType::IMPLICIT_ACCESS), | 47 ServiceAccessType::IMPLICIT_ACCESS), |
| 52 content::BrowserThread::GetBlockingPool(), profile->GetPath(), | 48 profile->GetPath(), |
| 53 profile->GetPrefs()->GetString(prefs::kAcceptLanguages), | 49 profile->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
| 54 chrome_schemes_to_whitelist); | |
| 55 in_memory_url_index->Init(); | 50 in_memory_url_index->Init(); |
| 56 return in_memory_url_index; | 51 return in_memory_url_index; |
| 57 } | 52 } |
| 58 | 53 |
| 59 content::BrowserContext* InMemoryURLIndexFactory::GetBrowserContextToUse( | 54 content::BrowserContext* InMemoryURLIndexFactory::GetBrowserContextToUse( |
| 60 content::BrowserContext* context) const { | 55 content::BrowserContext* context) const { |
| 61 return chrome::GetBrowserContextRedirectedInIncognito(context); | 56 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 62 } | 57 } |
| 63 | 58 |
| 64 bool InMemoryURLIndexFactory::ServiceIsNULLWhileTesting() const { | 59 bool InMemoryURLIndexFactory::ServiceIsNULLWhileTesting() const { |
| 65 return true; | 60 return true; |
| 66 } | 61 } |
| OLD | NEW |