1 // Copyright 2014 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. 4 5 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" 6 7 #include "base/prefs/pref_service.h" 8 #include "chrome/browser/profiles/incognito_helpers.h" 9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/search/suggestions/suggestions_service.h" 11 #include "chrome/browser/search/suggestions/suggestions_store.h" 12 #include "chrome/common/pref_names.h" 13 #include "components/keyed_service/content/browser_context_dependency_manager.h" 14 #include "components/pref_registry/pref_registry_syncable.h" 15 16 namespace suggestions { 17 18 // static 19 SuggestionsService* SuggestionsServiceFactory::GetForProfile(Profile* profile) { 20 if (!SuggestionsService::IsEnabled()) return NULL; 21 22 return static_cast<SuggestionsService*>( 23 GetInstance()->GetServiceForBrowserContext(profile, true)); 24 } 25 26 // static 27 SuggestionsServiceFactory* SuggestionsServiceFactory::GetInstance() { 28 return Singleton<SuggestionsServiceFactory>::get(); 29 } 30 31 SuggestionsServiceFactory::SuggestionsServiceFactory() 32 : BrowserContextKeyedServiceFactory( 33 "SuggestionsService", 34 BrowserContextDependencyManager::GetInstance()) { 35 // No dependencies. 36 } 37 38 SuggestionsServiceFactory::~SuggestionsServiceFactory() {} 39 40 content::BrowserContext* SuggestionsServiceFactory::GetBrowserContextToUse( 41 content::BrowserContext* context) const { 42 return chrome::GetBrowserContextRedirectedInIncognito(context); 43 } 44 45 KeyedService* SuggestionsServiceFactory::BuildServiceInstanceFor( 46 content::BrowserContext* profile) const { 47 Profile* the_profile = static_cast<Profile*>(profile); 48 scoped_ptr<SuggestionsStore> suggestions_store( 49 new SuggestionsStore(the_profile->GetPrefs())); 50 return new SuggestionsService(the_profile, suggestions_store.Pass()); 51 } 52 53 void SuggestionsServiceFactory::RegisterProfilePrefs( 54 user_prefs::PrefRegistrySyncable* registry) { 55 SuggestionsService::RegisterProfilePrefs(registry); 56 } 57 58 } // namespace suggestions 59