| 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/history/history_service_factory.h" | 11 #include "chrome/browser/history/history_service_factory.h" |
| 11 #include "chrome/browser/profiles/incognito_helpers.h" | 12 #include "chrome/browser/profiles/incognito_helpers.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 14 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 15 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 15 #include "components/keyed_service/core/service_access_type.h" | 16 #include "components/keyed_service/core/service_access_type.h" |
| 16 | 17 |
| 17 // static | 18 // static |
| 18 InMemoryURLIndex* InMemoryURLIndexFactory::GetForProfile(Profile* profile) { | 19 InMemoryURLIndex* InMemoryURLIndexFactory::GetForProfile(Profile* profile) { |
| 19 return static_cast<InMemoryURLIndex*>( | 20 return static_cast<InMemoryURLIndex*>( |
| 20 GetInstance()->GetServiceForBrowserContext(profile, true)); | 21 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 21 } | 22 } |
| 22 | 23 |
| 23 // static | 24 // static |
| 24 InMemoryURLIndexFactory* InMemoryURLIndexFactory::GetInstance() { | 25 InMemoryURLIndexFactory* InMemoryURLIndexFactory::GetInstance() { |
| 25 return Singleton<InMemoryURLIndexFactory>::get(); | 26 return Singleton<InMemoryURLIndexFactory>::get(); |
| 26 } | 27 } |
| 27 | 28 |
| 28 InMemoryURLIndexFactory::InMemoryURLIndexFactory() | 29 InMemoryURLIndexFactory::InMemoryURLIndexFactory() |
| 29 : BrowserContextKeyedServiceFactory( | 30 : BrowserContextKeyedServiceFactory( |
| 30 "InMemoryURLIndex", | 31 "InMemoryURLIndex", |
| 31 BrowserContextDependencyManager::GetInstance()) { | 32 BrowserContextDependencyManager::GetInstance()) { |
| 33 DependsOn(BookmarkModelFactory::GetInstance()); |
| 32 DependsOn(HistoryServiceFactory::GetInstance()); | 34 DependsOn(HistoryServiceFactory::GetInstance()); |
| 33 } | 35 } |
| 34 | 36 |
| 35 InMemoryURLIndexFactory::~InMemoryURLIndexFactory() { | 37 InMemoryURLIndexFactory::~InMemoryURLIndexFactory() { |
| 36 } | 38 } |
| 37 | 39 |
| 38 KeyedService* InMemoryURLIndexFactory::BuildServiceInstanceFor( | 40 KeyedService* InMemoryURLIndexFactory::BuildServiceInstanceFor( |
| 39 content::BrowserContext* context) const { | 41 content::BrowserContext* context) const { |
| 40 Profile* profile = Profile::FromBrowserContext(context); | 42 Profile* profile = Profile::FromBrowserContext(context); |
| 41 InMemoryURLIndex* in_memory_url_index = new InMemoryURLIndex( | 43 InMemoryURLIndex* in_memory_url_index = new InMemoryURLIndex( |
| 44 BookmarkModelFactory::GetForProfile(profile), |
| 42 HistoryServiceFactory::GetForProfile(profile, | 45 HistoryServiceFactory::GetForProfile(profile, |
| 43 ServiceAccessType::IMPLICIT_ACCESS), | 46 ServiceAccessType::IMPLICIT_ACCESS), |
| 44 profile->GetPath(), | 47 profile->GetPath(), |
| 45 profile->GetPrefs()->GetString(prefs::kAcceptLanguages)); | 48 profile->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
| 46 in_memory_url_index->Init(); | 49 in_memory_url_index->Init(); |
| 47 return in_memory_url_index; | 50 return in_memory_url_index; |
| 48 } | 51 } |
| 49 | 52 |
| 50 content::BrowserContext* InMemoryURLIndexFactory::GetBrowserContextToUse( | 53 content::BrowserContext* InMemoryURLIndexFactory::GetBrowserContextToUse( |
| 51 content::BrowserContext* context) const { | 54 content::BrowserContext* context) const { |
| 52 return chrome::GetBrowserContextRedirectedInIncognito(context); | 55 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 53 } | 56 } |
| 54 | 57 |
| 55 bool InMemoryURLIndexFactory::ServiceIsNULLWhileTesting() const { | 58 bool InMemoryURLIndexFactory::ServiceIsNULLWhileTesting() const { |
| 56 return true; | 59 return true; |
| 57 } | 60 } |
| OLD | NEW |