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/extensions/extension_system_factory.h" 9 #include "chrome/browser/history/shortcuts_backend_factory.h" 10 #include "chrome/browser/profiles/incognito_helpers.h" 11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/search_engines/template_url_service_factory.h" 13 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h" 14 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 BrowserContextKeyedService* 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(extensions::ExtensionSystemFactory::GetInstance()); 39 DependsOn(TemplateURLServiceFactory::GetInstance()); 40 // TODO(pkasting): Uncomment these once they exist. 41 // DependsOn(PrefServiceFactory::GetInstance()); 42 DependsOn(ShortcutsBackendFactory::GetInstance()); 43 } 44 45 AutocompleteClassifierFactory::~AutocompleteClassifierFactory() { 46 } 47 48 content::BrowserContext* AutocompleteClassifierFactory::GetBrowserContextToUse( 49 content::BrowserContext* context) const { 50 return chrome::GetBrowserContextRedirectedInIncognito(context); 51 } 52 53 bool AutocompleteClassifierFactory::ServiceIsNULLWhileTesting() const { 54 return true; 55 } 56 57 BrowserContextKeyedService* 58 AutocompleteClassifierFactory::BuildServiceInstanceFor( 59 content::BrowserContext* profile) const { 60 return BuildInstanceFor(static_cast<Profile*>(profile)); 61 } 62