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