Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / search_engines / template_url_service_factory.cc
blobffab5b4692cd0fc880c0cd6287a118710e7a5f3a
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"
7 #include <string>
9 #include "base/bind.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"
26 // static
27 TemplateURLService* TemplateURLServiceFactory::GetForProfile(Profile* profile) {
28 return static_cast<TemplateURLService*>(
29 GetInstance()->GetServiceForBrowserContext(profile, true));
32 // static
33 TemplateURLServiceFactory* TemplateURLServiceFactory::GetInstance() {
34 return Singleton<TemplateURLServiceFactory>::get();
37 // static
38 KeyedService* TemplateURLServiceFactory::BuildInstanceFor(
39 content::BrowserContext* context) {
40 base::Closure dsp_change_callback;
41 #if defined(ENABLE_RLZ)
42 dsp_change_callback =
43 base::Bind(base::IgnoreResult(&RLZTracker::RecordProductEvent),
44 rlz_lib::CHROME,
45 RLZTracker::ChromeOmnibox(),
46 rlz_lib::SET_TO_GOOGLE);
47 #endif
48 Profile* profile = static_cast<Profile*>(context);
49 return new TemplateURLService(
50 profile->GetPrefs(),
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(),
59 dsp_change_callback);
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,
82 std::string(),
83 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
84 registry->RegisterBooleanPref(
85 prefs::kDefaultSearchProviderEnabled,
86 true,
87 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
88 registry->RegisterStringPref(
89 prefs::kDefaultSearchProviderName,
90 std::string(),
91 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
92 registry->RegisterStringPref(
93 prefs::kDefaultSearchProviderID,
94 std::string(),
95 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
96 registry->RegisterStringPref(
97 prefs::kDefaultSearchProviderPrepopulateID,
98 std::string(),
99 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
100 registry->RegisterStringPref(
101 prefs::kDefaultSearchProviderSuggestURL,
102 std::string(),
103 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
104 registry->RegisterStringPref(
105 prefs::kDefaultSearchProviderSearchURL,
106 std::string(),
107 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
108 registry->RegisterStringPref(
109 prefs::kDefaultSearchProviderInstantURL,
110 std::string(),
111 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
112 registry->RegisterStringPref(
113 prefs::kDefaultSearchProviderImageURL,
114 std::string(),
115 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
116 registry->RegisterStringPref(
117 prefs::kDefaultSearchProviderNewTabURL,
118 std::string(),
119 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
120 registry->RegisterStringPref(
121 prefs::kDefaultSearchProviderSearchURLPostParams,
122 std::string(),
123 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
124 registry->RegisterStringPref(
125 prefs::kDefaultSearchProviderSuggestURLPostParams,
126 std::string(),
127 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
128 registry->RegisterStringPref(
129 prefs::kDefaultSearchProviderInstantURLPostParams,
130 std::string(),
131 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
132 registry->RegisterStringPref(
133 prefs::kDefaultSearchProviderImageURLPostParams,
134 std::string(),
135 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
136 registry->RegisterStringPref(
137 prefs::kDefaultSearchProviderKeyword,
138 std::string(),
139 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
140 registry->RegisterStringPref(
141 prefs::kDefaultSearchProviderIconURL,
142 std::string(),
143 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
144 registry->RegisterStringPref(
145 prefs::kDefaultSearchProviderEncodings,
146 std::string(),
147 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
148 registry->RegisterListPref(prefs::kDefaultSearchProviderAlternateURLs,
149 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
150 registry->RegisterStringPref(
151 prefs::kDefaultSearchProviderSearchTermsReplacementKey,
152 std::string(),
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 {
162 return true;