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.
5 #include "chrome/browser/search_engines/template_url_service_factory.h"
9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/google/google_url_tracker_factory.h"
11 #include "chrome/browser/history/history_service_factory.h"
12 #include "chrome/browser/profiles/incognito_helpers.h"
13 #include "chrome/browser/search_engines/template_url_service.h"
14 #include "chrome/browser/webdata/web_data_service_factory.h"
15 #include "chrome/common/pref_names.h"
16 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
17 #include "components/user_prefs/pref_registry_syncable.h"
20 TemplateURLService
* TemplateURLServiceFactory::GetForProfile(Profile
* profile
) {
21 return static_cast<TemplateURLService
*>(
22 GetInstance()->GetServiceForBrowserContext(profile
, true));
26 TemplateURLServiceFactory
* TemplateURLServiceFactory::GetInstance() {
27 return Singleton
<TemplateURLServiceFactory
>::get();
31 BrowserContextKeyedService
* TemplateURLServiceFactory::BuildInstanceFor(
32 content::BrowserContext
* profile
) {
33 return new TemplateURLService(static_cast<Profile
*>(profile
));
36 TemplateURLServiceFactory::TemplateURLServiceFactory()
37 : BrowserContextKeyedServiceFactory(
38 "TemplateURLServiceFactory",
39 BrowserContextDependencyManager::GetInstance()) {
40 DependsOn(GoogleURLTrackerFactory::GetInstance());
41 DependsOn(HistoryServiceFactory::GetInstance());
42 DependsOn(WebDataServiceFactory::GetInstance());
45 TemplateURLServiceFactory::~TemplateURLServiceFactory() {}
47 BrowserContextKeyedService
* TemplateURLServiceFactory::BuildServiceInstanceFor(
48 content::BrowserContext
* profile
) const {
49 return BuildInstanceFor(static_cast<Profile
*>(profile
));
52 void TemplateURLServiceFactory::RegisterProfilePrefs(
53 user_prefs::PrefRegistrySyncable
* registry
) {
54 registry
->RegisterStringPref(prefs::kSyncedDefaultSearchProviderGUID
,
56 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
57 registry
->RegisterBooleanPref(
58 prefs::kDefaultSearchProviderEnabled
,
60 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
61 registry
->RegisterStringPref(
62 prefs::kDefaultSearchProviderName
,
64 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
65 registry
->RegisterStringPref(
66 prefs::kDefaultSearchProviderID
,
68 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
69 registry
->RegisterStringPref(
70 prefs::kDefaultSearchProviderPrepopulateID
,
72 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
73 registry
->RegisterStringPref(
74 prefs::kDefaultSearchProviderSuggestURL
,
76 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
77 registry
->RegisterStringPref(
78 prefs::kDefaultSearchProviderSearchURL
,
80 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
81 registry
->RegisterStringPref(
82 prefs::kDefaultSearchProviderInstantURL
,
84 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
85 registry
->RegisterStringPref(
86 prefs::kDefaultSearchProviderImageURL
,
88 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
89 registry
->RegisterStringPref(
90 prefs::kDefaultSearchProviderNewTabURL
,
92 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
93 registry
->RegisterStringPref(
94 prefs::kDefaultSearchProviderSearchURLPostParams
,
96 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
97 registry
->RegisterStringPref(
98 prefs::kDefaultSearchProviderSuggestURLPostParams
,
100 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
101 registry
->RegisterStringPref(
102 prefs::kDefaultSearchProviderInstantURLPostParams
,
104 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
105 registry
->RegisterStringPref(
106 prefs::kDefaultSearchProviderImageURLPostParams
,
108 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
109 registry
->RegisterStringPref(
110 prefs::kDefaultSearchProviderKeyword
,
112 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
113 registry
->RegisterStringPref(
114 prefs::kDefaultSearchProviderIconURL
,
116 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
117 registry
->RegisterStringPref(
118 prefs::kDefaultSearchProviderEncodings
,
120 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
121 registry
->RegisterListPref(prefs::kDefaultSearchProviderAlternateURLs
,
122 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
123 registry
->RegisterStringPref(
124 prefs::kDefaultSearchProviderSearchTermsReplacementKey
,
126 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
129 content::BrowserContext
* TemplateURLServiceFactory::GetBrowserContextToUse(
130 content::BrowserContext
* context
) const {
131 return chrome::GetBrowserContextRedirectedInIncognito(context
);
134 bool TemplateURLServiceFactory::ServiceIsNULLWhileTesting() const {