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"
10 #include "base/prefs/pref_service.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/google/google_url_tracker_factory.h"
13 #include "chrome/browser/history/history_service_factory.h"
14 #include "chrome/browser/profiles/incognito_helpers.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/rlz/rlz.h"
17 #include "chrome/browser/search_engines/chrome_template_url_service_client.h"
18 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
19 #include "chrome/browser/webdata/web_data_service_factory.h"
20 #include "components/keyed_service/content/browser_context_dependency_manager.h"
21 #include "components/pref_registry/pref_registry_syncable.h"
22 #include "components/search_engines/default_search_manager.h"
23 #include "components/search_engines/search_engines_pref_names.h"
24 #include "components/search_engines/template_url_service.h"
27 TemplateURLService
* TemplateURLServiceFactory::GetForProfile(Profile
* profile
) {
28 return static_cast<TemplateURLService
*>(
29 GetInstance()->GetServiceForBrowserContext(profile
, true));
33 TemplateURLServiceFactory
* TemplateURLServiceFactory::GetInstance() {
34 return Singleton
<TemplateURLServiceFactory
>::get();
38 KeyedService
* TemplateURLServiceFactory::BuildInstanceFor(
39 content::BrowserContext
* context
) {
40 base::Closure dsp_change_callback
;
41 #if defined(ENABLE_RLZ)
43 base::Bind(base::IgnoreResult(&RLZTracker::RecordProductEvent
),
45 RLZTracker::ChromeOmnibox(),
46 rlz_lib::SET_TO_GOOGLE
);
48 Profile
* profile
= static_cast<Profile
*>(context
);
49 return new TemplateURLService(
51 scoped_ptr
<SearchTermsData
>(new UIThreadSearchTermsData(profile
)),
52 WebDataServiceFactory::GetKeywordWebDataForProfile(
53 profile
, ServiceAccessType::EXPLICIT_ACCESS
),
54 scoped_ptr
<TemplateURLServiceClient
>(new ChromeTemplateURLServiceClient(
55 HistoryServiceFactory::GetForProfile(
56 profile
, ServiceAccessType::EXPLICIT_ACCESS
))),
57 GoogleURLTrackerFactory::GetForProfile(profile
),
58 g_browser_process
->rappor_service(),
62 TemplateURLServiceFactory::TemplateURLServiceFactory()
63 : BrowserContextKeyedServiceFactory(
64 "TemplateURLServiceFactory",
65 BrowserContextDependencyManager::GetInstance()) {
66 DependsOn(GoogleURLTrackerFactory::GetInstance());
67 DependsOn(HistoryServiceFactory::GetInstance());
68 DependsOn(WebDataServiceFactory::GetInstance());
71 TemplateURLServiceFactory::~TemplateURLServiceFactory() {}
73 KeyedService
* TemplateURLServiceFactory::BuildServiceInstanceFor(
74 content::BrowserContext
* profile
) const {
75 return BuildInstanceFor(static_cast<Profile
*>(profile
));
78 void TemplateURLServiceFactory::RegisterProfilePrefs(
79 user_prefs::PrefRegistrySyncable
* registry
) {
80 DefaultSearchManager::RegisterProfilePrefs(registry
);
81 registry
->RegisterStringPref(prefs::kSyncedDefaultSearchProviderGUID
,
83 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
84 registry
->RegisterBooleanPref(
85 prefs::kDefaultSearchProviderEnabled
,
87 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
88 registry
->RegisterStringPref(
89 prefs::kDefaultSearchProviderName
,
91 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
92 registry
->RegisterStringPref(
93 prefs::kDefaultSearchProviderID
,
95 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
96 registry
->RegisterStringPref(
97 prefs::kDefaultSearchProviderPrepopulateID
,
99 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
100 registry
->RegisterStringPref(
101 prefs::kDefaultSearchProviderSuggestURL
,
103 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
104 registry
->RegisterStringPref(
105 prefs::kDefaultSearchProviderSearchURL
,
107 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
108 registry
->RegisterStringPref(
109 prefs::kDefaultSearchProviderInstantURL
,
111 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
112 registry
->RegisterStringPref(
113 prefs::kDefaultSearchProviderImageURL
,
115 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
116 registry
->RegisterStringPref(
117 prefs::kDefaultSearchProviderNewTabURL
,
119 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
120 registry
->RegisterStringPref(
121 prefs::kDefaultSearchProviderSearchURLPostParams
,
123 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
124 registry
->RegisterStringPref(
125 prefs::kDefaultSearchProviderSuggestURLPostParams
,
127 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
128 registry
->RegisterStringPref(
129 prefs::kDefaultSearchProviderInstantURLPostParams
,
131 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
132 registry
->RegisterStringPref(
133 prefs::kDefaultSearchProviderImageURLPostParams
,
135 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
136 registry
->RegisterStringPref(
137 prefs::kDefaultSearchProviderKeyword
,
139 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
140 registry
->RegisterStringPref(
141 prefs::kDefaultSearchProviderIconURL
,
143 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
144 registry
->RegisterStringPref(
145 prefs::kDefaultSearchProviderEncodings
,
147 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
148 registry
->RegisterListPref(prefs::kDefaultSearchProviderAlternateURLs
,
149 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
150 registry
->RegisterStringPref(
151 prefs::kDefaultSearchProviderSearchTermsReplacementKey
,
153 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
156 content::BrowserContext
* TemplateURLServiceFactory::GetBrowserContextToUse(
157 content::BrowserContext
* context
) const {
158 return chrome::GetBrowserContextRedirectedInIncognito(context
);
161 bool TemplateURLServiceFactory::ServiceIsNULLWhileTesting() const {