1 // Copyright (c) 2012 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/autocomplete/autocomplete_classifier_factory.h" 6 7 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 8 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" 9 #include "chrome/browser/profiles/incognito_helpers.h" 10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/search_engines/template_url_service_factory.h" 12 #include "components/keyed_service/content/browser_context_dependency_manager.h" 13 #include "extensions/browser/extension_system_provider.h" 14 #include "extensions/browser/extensions_browser_client.h" 15 16 // static 17 AutocompleteClassifier* AutocompleteClassifierFactory::GetForProfile( 18 Profile* profile) { 19 return static_cast<AutocompleteClassifier*>( 20 GetInstance()->GetServiceForBrowserContext(profile, true)); 21 } 22 23 // static 24 AutocompleteClassifierFactory* AutocompleteClassifierFactory::GetInstance() { 25 return Singleton<AutocompleteClassifierFactory>::get(); 26 } 27 28 // static 29 KeyedService* AutocompleteClassifierFactory::BuildInstanceFor( 30 content::BrowserContext* profile) { 31 return new AutocompleteClassifier(static_cast<Profile*>(profile)); 32 } 33 34 AutocompleteClassifierFactory::AutocompleteClassifierFactory() 35 : BrowserContextKeyedServiceFactory( 36 "AutocompleteClassifier", 37 BrowserContextDependencyManager::GetInstance()) { 38 DependsOn( 39 extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); 40 DependsOn(TemplateURLServiceFactory::GetInstance()); 41 // TODO(pkasting): Uncomment these once they exist. 42 // DependsOn(PrefServiceFactory::GetInstance()); 43 DependsOn(ShortcutsBackendFactory::GetInstance()); 44 } 45 46 AutocompleteClassifierFactory::~AutocompleteClassifierFactory() { 47 } 48 49 content::BrowserContext* AutocompleteClassifierFactory::GetBrowserContextToUse( 50 content::BrowserContext* context) const { 51 return chrome::GetBrowserContextRedirectedInIncognito(context); 52 } 53 54 bool AutocompleteClassifierFactory::ServiceIsNULLWhileTesting() const { 55 return true; 56 } 57 58 KeyedService* AutocompleteClassifierFactory::BuildServiceInstanceFor( 59 content::BrowserContext* profile) const { 60 return BuildInstanceFor(static_cast<Profile*>(profile)); 61 } 62