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/default_search_manager.h"
14 #include "chrome/browser/search_engines/template_url_service.h"
15 #include "chrome/browser/webdata/web_data_service_factory.h"
16 #include "chrome/common/pref_names.h"
17 #include "components/keyed_service/content/browser_context_dependency_manager.h"
18 #include "components/user_prefs/pref_registry_syncable.h"
21 TemplateURLService
* TemplateURLServiceFactory::GetForProfile(Profile
* profile
) {
22 return static_cast<TemplateURLService
*>(
23 GetInstance()->GetServiceForBrowserContext(profile
, true));
27 TemplateURLServiceFactory
* TemplateURLServiceFactory::GetInstance() {
28 return Singleton
<TemplateURLServiceFactory
>::get();
32 KeyedService
* TemplateURLServiceFactory::BuildInstanceFor(
33 content::BrowserContext
* profile
) {
34 return new TemplateURLService(static_cast<Profile
*>(profile
));
37 TemplateURLServiceFactory::TemplateURLServiceFactory()
38 : BrowserContextKeyedServiceFactory(
39 "TemplateURLServiceFactory",
40 BrowserContextDependencyManager::GetInstance()) {
41 DependsOn(GoogleURLTrackerFactory::GetInstance());
42 DependsOn(HistoryServiceFactory::GetInstance());
43 DependsOn(WebDataServiceFactory::GetInstance());
46 TemplateURLServiceFactory::~TemplateURLServiceFactory() {}
48 KeyedService
* TemplateURLServiceFactory::BuildServiceInstanceFor(
49 content::BrowserContext
* profile
) const {
50 return BuildInstanceFor(static_cast<Profile
*>(profile
));
53 void TemplateURLServiceFactory::RegisterProfilePrefs(
54 user_prefs::PrefRegistrySyncable
* registry
) {
55 DefaultSearchManager::RegisterProfilePrefs(registry
);
56 registry
->RegisterStringPref(prefs::kSyncedDefaultSearchProviderGUID
,
58 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
59 registry
->RegisterBooleanPref(
60 prefs::kDefaultSearchProviderEnabled
,
62 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
63 registry
->RegisterStringPref(
64 prefs::kDefaultSearchProviderName
,
66 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
67 registry
->RegisterStringPref(
68 prefs::kDefaultSearchProviderID
,
70 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
71 registry
->RegisterStringPref(
72 prefs::kDefaultSearchProviderPrepopulateID
,
74 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
75 registry
->RegisterStringPref(
76 prefs::kDefaultSearchProviderSuggestURL
,
78 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
79 registry
->RegisterStringPref(
80 prefs::kDefaultSearchProviderSearchURL
,
82 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
83 registry
->RegisterStringPref(
84 prefs::kDefaultSearchProviderInstantURL
,
86 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
87 registry
->RegisterStringPref(
88 prefs::kDefaultSearchProviderImageURL
,
90 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
91 registry
->RegisterStringPref(
92 prefs::kDefaultSearchProviderNewTabURL
,
94 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
95 registry
->RegisterStringPref(
96 prefs::kDefaultSearchProviderSearchURLPostParams
,
98 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
99 registry
->RegisterStringPref(
100 prefs::kDefaultSearchProviderSuggestURLPostParams
,
102 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
103 registry
->RegisterStringPref(
104 prefs::kDefaultSearchProviderInstantURLPostParams
,
106 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
107 registry
->RegisterStringPref(
108 prefs::kDefaultSearchProviderImageURLPostParams
,
110 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
111 registry
->RegisterStringPref(
112 prefs::kDefaultSearchProviderKeyword
,
114 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
115 registry
->RegisterStringPref(
116 prefs::kDefaultSearchProviderIconURL
,
118 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
119 registry
->RegisterStringPref(
120 prefs::kDefaultSearchProviderEncodings
,
122 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
123 registry
->RegisterListPref(prefs::kDefaultSearchProviderAlternateURLs
,
124 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
125 registry
->RegisterStringPref(
126 prefs::kDefaultSearchProviderSearchTermsReplacementKey
,
128 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
131 content::BrowserContext
* TemplateURLServiceFactory::GetBrowserContextToUse(
132 content::BrowserContext
* context
) const {
133 return chrome::GetBrowserContextRedirectedInIncognito(context
);
136 bool TemplateURLServiceFactory::ServiceIsNULLWhileTesting() const {