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/rlz/rlz.h"
16 #include "chrome/browser/search_engines/chrome_template_url_service_client.h"
17 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
18 #include "chrome/browser/webdata/web_data_service_factory.h"
19 #include "components/keyed_service/content/browser_context_dependency_manager.h"
20 #include "components/pref_registry/pref_registry_syncable.h"
21 #include "components/search_engines/default_search_manager.h"
22 #include "components/search_engines/search_engines_pref_names.h"
23 #include "components/search_engines/template_url_service.h"
26 TemplateURLService
* TemplateURLServiceFactory::GetForProfile(Profile
* profile
) {
27 return static_cast<TemplateURLService
*>(
28 GetInstance()->GetServiceForBrowserContext(profile
, true));
32 TemplateURLServiceFactory
* TemplateURLServiceFactory::GetInstance() {
33 return Singleton
<TemplateURLServiceFactory
>::get();
37 KeyedService
* TemplateURLServiceFactory::BuildInstanceFor(
38 content::BrowserContext
* context
) {
39 base::Closure dsp_change_callback
;
40 #if defined(ENABLE_RLZ)
42 base::Bind(base::IgnoreResult(&RLZTracker::RecordProductEvent
),
44 RLZTracker::ChromeOmnibox(),
45 rlz_lib::SET_TO_GOOGLE
);
47 Profile
* profile
= static_cast<Profile
*>(context
);
48 return new TemplateURLService(
50 scoped_ptr
<SearchTermsData
>(new UIThreadSearchTermsData(profile
)),
51 WebDataServiceFactory::GetKeywordWebDataForProfile(
52 profile
, Profile::EXPLICIT_ACCESS
),
53 scoped_ptr
<TemplateURLServiceClient
>(new ChromeTemplateURLServiceClient(
54 HistoryServiceFactory::GetForProfile(profile
,
55 Profile::EXPLICIT_ACCESS
))),
56 GoogleURLTrackerFactory::GetForProfile(profile
),
57 g_browser_process
->rappor_service(),
61 TemplateURLServiceFactory::TemplateURLServiceFactory()
62 : BrowserContextKeyedServiceFactory(
63 "TemplateURLServiceFactory",
64 BrowserContextDependencyManager::GetInstance()) {
65 DependsOn(GoogleURLTrackerFactory::GetInstance());
66 DependsOn(HistoryServiceFactory::GetInstance());
67 DependsOn(WebDataServiceFactory::GetInstance());
70 TemplateURLServiceFactory::~TemplateURLServiceFactory() {}
72 KeyedService
* TemplateURLServiceFactory::BuildServiceInstanceFor(
73 content::BrowserContext
* profile
) const {
74 return BuildInstanceFor(static_cast<Profile
*>(profile
));
77 void TemplateURLServiceFactory::RegisterProfilePrefs(
78 user_prefs::PrefRegistrySyncable
* registry
) {
79 DefaultSearchManager::RegisterProfilePrefs(registry
);
80 registry
->RegisterStringPref(prefs::kSyncedDefaultSearchProviderGUID
,
82 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
83 registry
->RegisterBooleanPref(
84 prefs::kDefaultSearchProviderEnabled
,
86 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
87 registry
->RegisterStringPref(
88 prefs::kDefaultSearchProviderName
,
90 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
91 registry
->RegisterStringPref(
92 prefs::kDefaultSearchProviderID
,
94 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
95 registry
->RegisterStringPref(
96 prefs::kDefaultSearchProviderPrepopulateID
,
98 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
99 registry
->RegisterStringPref(
100 prefs::kDefaultSearchProviderSuggestURL
,
102 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
103 registry
->RegisterStringPref(
104 prefs::kDefaultSearchProviderSearchURL
,
106 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
107 registry
->RegisterStringPref(
108 prefs::kDefaultSearchProviderInstantURL
,
110 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
111 registry
->RegisterStringPref(
112 prefs::kDefaultSearchProviderImageURL
,
114 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
115 registry
->RegisterStringPref(
116 prefs::kDefaultSearchProviderNewTabURL
,
118 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
119 registry
->RegisterStringPref(
120 prefs::kDefaultSearchProviderSearchURLPostParams
,
122 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
123 registry
->RegisterStringPref(
124 prefs::kDefaultSearchProviderSuggestURLPostParams
,
126 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
127 registry
->RegisterStringPref(
128 prefs::kDefaultSearchProviderInstantURLPostParams
,
130 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
131 registry
->RegisterStringPref(
132 prefs::kDefaultSearchProviderImageURLPostParams
,
134 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
135 registry
->RegisterStringPref(
136 prefs::kDefaultSearchProviderKeyword
,
138 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
139 registry
->RegisterStringPref(
140 prefs::kDefaultSearchProviderIconURL
,
142 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
143 registry
->RegisterStringPref(
144 prefs::kDefaultSearchProviderEncodings
,
146 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
147 registry
->RegisterListPref(prefs::kDefaultSearchProviderAlternateURLs
,
148 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
149 registry
->RegisterStringPref(
150 prefs::kDefaultSearchProviderSearchTermsReplacementKey
,
152 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
155 content::BrowserContext
* TemplateURLServiceFactory::GetBrowserContextToUse(
156 content::BrowserContext
* context
) const {
157 return chrome::GetBrowserContextRedirectedInIncognito(context
);
160 bool TemplateURLServiceFactory::ServiceIsNULLWhileTesting() const {