| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/search_engines/template_url_service_factory.h" | 5 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/browser/google/google_url_tracker_factory.h" | 8 #include "chrome/browser/google/google_url_tracker_factory.h" |
| 9 #include "chrome/browser/history/history_service_factory.h" | 9 #include "chrome/browser/history/history_service_factory.h" |
| 10 #include "chrome/browser/profiles/profile_dependency_manager.h" | 10 #include "chrome/browser/profiles/profile_dependency_manager.h" |
| 11 #include "chrome/browser/search_engines/template_url_service.h" | 11 #include "chrome/browser/search_engines/template_url_service.h" |
| 12 #include "chrome/browser/webdata/web_data_service_factory.h" | 12 #include "chrome/browser/webdata/web_data_service_factory.h" |
| 13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 14 #include "components/user_prefs/pref_registry_syncable.h" | 14 #include "components/user_prefs/pref_registry_syncable.h" |
| 15 | 15 |
| 16 // static | 16 // static |
| 17 TemplateURLService* TemplateURLServiceFactory::GetForProfile(Profile* profile) { | 17 TemplateURLService* TemplateURLServiceFactory::GetForProfile(Profile* profile) { |
| 18 return static_cast<TemplateURLService*>( | 18 return static_cast<TemplateURLService*>( |
| 19 GetInstance()->GetServiceForProfile(profile, true)); | 19 GetInstance()->GetServiceForProfile(profile, true)); |
| 20 } | 20 } |
| 21 | 21 |
| 22 // static | 22 // static |
| 23 TemplateURLServiceFactory* TemplateURLServiceFactory::GetInstance() { | 23 TemplateURLServiceFactory* TemplateURLServiceFactory::GetInstance() { |
| 24 return Singleton<TemplateURLServiceFactory>::get(); | 24 return Singleton<TemplateURLServiceFactory>::get(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 // static | 27 // static |
| 28 ProfileKeyedService* TemplateURLServiceFactory::BuildInstanceFor( | 28 ProfileKeyedService* TemplateURLServiceFactory::BuildInstanceFor( |
| 29 Profile* profile) { | 29 content::BrowserContext* profile) { |
| 30 return new TemplateURLService(profile); | 30 return new TemplateURLService(static_cast<Profile*>(profile)); |
| 31 } | 31 } |
| 32 | 32 |
| 33 TemplateURLServiceFactory::TemplateURLServiceFactory() | 33 TemplateURLServiceFactory::TemplateURLServiceFactory() |
| 34 : ProfileKeyedServiceFactory("TemplateURLServiceFactory", | 34 : ProfileKeyedServiceFactory("TemplateURLServiceFactory", |
| 35 ProfileDependencyManager::GetInstance()) { | 35 ProfileDependencyManager::GetInstance()) { |
| 36 DependsOn(GoogleURLTrackerFactory::GetInstance()); | 36 DependsOn(GoogleURLTrackerFactory::GetInstance()); |
| 37 DependsOn(HistoryServiceFactory::GetInstance()); | 37 DependsOn(HistoryServiceFactory::GetInstance()); |
| 38 DependsOn(WebDataServiceFactory::GetInstance()); | 38 DependsOn(WebDataServiceFactory::GetInstance()); |
| 39 } | 39 } |
| 40 | 40 |
| 41 TemplateURLServiceFactory::~TemplateURLServiceFactory() {} | 41 TemplateURLServiceFactory::~TemplateURLServiceFactory() {} |
| 42 | 42 |
| 43 ProfileKeyedService* TemplateURLServiceFactory::BuildServiceInstanceFor( | 43 ProfileKeyedService* TemplateURLServiceFactory::BuildServiceInstanceFor( |
| 44 Profile* profile) const { | 44 content::BrowserContext* profile) const { |
| 45 return BuildInstanceFor(profile); | 45 return BuildInstanceFor(static_cast<Profile*>(profile)); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void TemplateURLServiceFactory::RegisterUserPrefs( | 48 void TemplateURLServiceFactory::RegisterUserPrefs( |
| 49 PrefRegistrySyncable* registry) { | 49 PrefRegistrySyncable* registry) { |
| 50 registry->RegisterStringPref(prefs::kSyncedDefaultSearchProviderGUID, | 50 registry->RegisterStringPref(prefs::kSyncedDefaultSearchProviderGUID, |
| 51 std::string(), | 51 std::string(), |
| 52 PrefRegistrySyncable::SYNCABLE_PREF); | 52 PrefRegistrySyncable::SYNCABLE_PREF); |
| 53 registry->RegisterBooleanPref(prefs::kDefaultSearchProviderEnabled, | 53 registry->RegisterBooleanPref(prefs::kDefaultSearchProviderEnabled, |
| 54 true, | 54 true, |
| 55 PrefRegistrySyncable::UNSYNCABLE_PREF); | 55 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 } | 89 } |
| 90 | 90 |
| 91 bool TemplateURLServiceFactory::ServiceRedirectedInIncognito() const { | 91 bool TemplateURLServiceFactory::ServiceRedirectedInIncognito() const { |
| 92 return true; | 92 return true; |
| 93 } | 93 } |
| 94 | 94 |
| 95 bool TemplateURLServiceFactory::ServiceIsNULLWhileTesting() const { | 95 bool TemplateURLServiceFactory::ServiceIsNULLWhileTesting() const { |
| 96 return true; | 96 return true; |
| 97 } | 97 } |
| 98 | 98 |
| 99 void TemplateURLServiceFactory::ProfileShutdown(Profile* profile) { | 99 void TemplateURLServiceFactory::ProfileShutdown( |
| 100 content::BrowserContext* profile) { |
| 100 // We shutdown AND destroy the TemplateURLService during this pass. | 101 // We shutdown AND destroy the TemplateURLService during this pass. |
| 101 // TemplateURLService schedules a task on the WebDataService from its | 102 // TemplateURLService schedules a task on the WebDataService from its |
| 102 // destructor. Delete it first to ensure the task gets scheduled before we | 103 // destructor. Delete it first to ensure the task gets scheduled before we |
| 103 // shut down the database. | 104 // shut down the database. |
| 104 ProfileKeyedServiceFactory::ProfileShutdown(profile); | 105 ProfileKeyedServiceFactory::ProfileShutdown(profile); |
| 105 ProfileKeyedServiceFactory::ProfileDestroyed(profile); | 106 ProfileKeyedServiceFactory::ProfileDestroyed(profile); |
| 106 } | 107 } |
| 107 | 108 |
| 108 void TemplateURLServiceFactory::ProfileDestroyed(Profile* profile) { | 109 void TemplateURLServiceFactory::ProfileDestroyed( |
| 110 content::BrowserContext* profile) { |
| 109 // Don't double delete. | 111 // Don't double delete. |
| 110 } | 112 } |
| OLD | NEW |