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>(
54 new ChromeTemplateURLServiceClient(profile)),
55 GoogleURLTrackerFactory::GetForProfile(profile),
56 g_browser_process->rappor_service(),
60 TemplateURLServiceFactory::TemplateURLServiceFactory()
61 : BrowserContextKeyedServiceFactory(
62 "TemplateURLServiceFactory",
63 BrowserContextDependencyManager::GetInstance()) {
64 DependsOn(GoogleURLTrackerFactory::GetInstance());
65 DependsOn(HistoryServiceFactory::GetInstance());
66 DependsOn(WebDataServiceFactory::GetInstance());
69 TemplateURLServiceFactory::~TemplateURLServiceFactory() {}
71 KeyedService* TemplateURLServiceFactory::BuildServiceInstanceFor(
72 content::BrowserContext* profile) const {
73 return BuildInstanceFor(static_cast<Profile*>(profile));
76 void TemplateURLServiceFactory::RegisterProfilePrefs(
77 user_prefs::PrefRegistrySyncable* registry) {
78 DefaultSearchManager::RegisterProfilePrefs(registry);
79 registry->RegisterStringPref(prefs::kSyncedDefaultSearchProviderGUID,
81 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
82 registry->RegisterBooleanPref(
83 prefs::kDefaultSearchProviderEnabled,
85 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
86 registry->RegisterStringPref(
87 prefs::kDefaultSearchProviderName,
89 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
90 registry->RegisterStringPref(
91 prefs::kDefaultSearchProviderID,
93 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
94 registry->RegisterStringPref(
95 prefs::kDefaultSearchProviderPrepopulateID,
97 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
98 registry->RegisterStringPref(
99 prefs::kDefaultSearchProviderSuggestURL,
101 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
102 registry->RegisterStringPref(
103 prefs::kDefaultSearchProviderSearchURL,
105 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
106 registry->RegisterStringPref(
107 prefs::kDefaultSearchProviderInstantURL,
109 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
110 registry->RegisterStringPref(
111 prefs::kDefaultSearchProviderImageURL,
113 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
114 registry->RegisterStringPref(
115 prefs::kDefaultSearchProviderNewTabURL,
117 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
118 registry->RegisterStringPref(
119 prefs::kDefaultSearchProviderSearchURLPostParams,
121 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
122 registry->RegisterStringPref(
123 prefs::kDefaultSearchProviderSuggestURLPostParams,
125 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
126 registry->RegisterStringPref(
127 prefs::kDefaultSearchProviderInstantURLPostParams,
129 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
130 registry->RegisterStringPref(
131 prefs::kDefaultSearchProviderImageURLPostParams,
133 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
134 registry->RegisterStringPref(
135 prefs::kDefaultSearchProviderKeyword,
137 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
138 registry->RegisterStringPref(
139 prefs::kDefaultSearchProviderIconURL,
141 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
142 registry->RegisterStringPref(
143 prefs::kDefaultSearchProviderEncodings,
145 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
146 registry->RegisterListPref(prefs::kDefaultSearchProviderAlternateURLs,
147 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
148 registry->RegisterStringPref(
149 prefs::kDefaultSearchProviderSearchTermsReplacementKey,
151 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
154 content::BrowserContext* TemplateURLServiceFactory::GetBrowserContextToUse(
155 content::BrowserContext* context) const {
156 return chrome::GetBrowserContextRedirectedInIncognito(context);
159 bool TemplateURLServiceFactory::ServiceIsNULLWhileTesting() const {