Move StartsWith[ASCII] to base namespace.
[chromium-blink-merge.git] / chrome / browser / search_engines / template_url_service_factory.cc
blob4d6709a0dbeac96415755faced0616c8ebc5bf01
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 scoped_ptr<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 make_scoped_ptr(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(), 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)).release();
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(prefs::kDefaultSearchProviderEnabled, true);
84 registry->RegisterStringPref(prefs::kDefaultSearchProviderName,
85 std::string());
86 registry->RegisterStringPref(prefs::kDefaultSearchProviderID, std::string());
87 registry->RegisterStringPref(prefs::kDefaultSearchProviderPrepopulateID,
88 std::string());
89 registry->RegisterStringPref(prefs::kDefaultSearchProviderSuggestURL,
90 std::string());
91 registry->RegisterStringPref(prefs::kDefaultSearchProviderSearchURL,
92 std::string());
93 registry->RegisterStringPref(prefs::kDefaultSearchProviderInstantURL,
94 std::string());
95 registry->RegisterStringPref(prefs::kDefaultSearchProviderImageURL,
96 std::string());
97 registry->RegisterStringPref(prefs::kDefaultSearchProviderNewTabURL,
98 std::string());
99 registry->RegisterStringPref(prefs::kDefaultSearchProviderSearchURLPostParams,
100 std::string());
101 registry->RegisterStringPref(
102 prefs::kDefaultSearchProviderSuggestURLPostParams, std::string());
103 registry->RegisterStringPref(
104 prefs::kDefaultSearchProviderInstantURLPostParams, std::string());
105 registry->RegisterStringPref(prefs::kDefaultSearchProviderImageURLPostParams,
106 std::string());
107 registry->RegisterStringPref(prefs::kDefaultSearchProviderKeyword,
108 std::string());
109 registry->RegisterStringPref(prefs::kDefaultSearchProviderIconURL,
110 std::string());
111 registry->RegisterStringPref(prefs::kDefaultSearchProviderEncodings,
112 std::string());
113 registry->RegisterListPref(prefs::kDefaultSearchProviderAlternateURLs);
114 registry->RegisterStringPref(
115 prefs::kDefaultSearchProviderSearchTermsReplacementKey, std::string());
118 content::BrowserContext* TemplateURLServiceFactory::GetBrowserContextToUse(
119 content::BrowserContext* context) const {
120 return chrome::GetBrowserContextRedirectedInIncognito(context);
123 bool TemplateURLServiceFactory::ServiceIsNULLWhileTesting() const {
124 return true;