Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / search_engines / template_url_service_factory.cc
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.
4
5 #include "chrome/browser/search_engines/template_url_service_factory.h"
6
7 #include <string>
8
9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/google/google_url_tracker_factory.h"
11 #include "chrome/browser/history/history_service_factory.h"
12 #include "chrome/browser/profiles/incognito_helpers.h"
13 #include "chrome/browser/search_engines/default_search_manager.h"
14 #include "chrome/browser/search_engines/template_url_service.h"
15 #include "chrome/browser/webdata/web_data_service_factory.h"
16 #include "chrome/common/pref_names.h"
17 #include "components/keyed_service/content/browser_context_dependency_manager.h"
18 #include "components/user_prefs/pref_registry_syncable.h"
19
20 // static
21 TemplateURLService* TemplateURLServiceFactory::GetForProfile(Profile* profile) {
22   return static_cast<TemplateURLService*>(
23       GetInstance()->GetServiceForBrowserContext(profile, true));
24 }
25
26 // static
27 TemplateURLServiceFactory* TemplateURLServiceFactory::GetInstance() {
28   return Singleton<TemplateURLServiceFactory>::get();
29 }
30
31 // static
32 KeyedService* TemplateURLServiceFactory::BuildInstanceFor(
33     content::BrowserContext* profile) {
34   return new TemplateURLService(static_cast<Profile*>(profile));
35 }
36
37 TemplateURLServiceFactory::TemplateURLServiceFactory()
38     : BrowserContextKeyedServiceFactory(
39         "TemplateURLServiceFactory",
40         BrowserContextDependencyManager::GetInstance()) {
41   DependsOn(GoogleURLTrackerFactory::GetInstance());
42   DependsOn(HistoryServiceFactory::GetInstance());
43   DependsOn(WebDataServiceFactory::GetInstance());
44 }
45
46 TemplateURLServiceFactory::~TemplateURLServiceFactory() {}
47
48 KeyedService* TemplateURLServiceFactory::BuildServiceInstanceFor(
49     content::BrowserContext* profile) const {
50   return BuildInstanceFor(static_cast<Profile*>(profile));
51 }
52
53 void TemplateURLServiceFactory::RegisterProfilePrefs(
54     user_prefs::PrefRegistrySyncable* registry) {
55   DefaultSearchManager::RegisterProfilePrefs(registry);
56   registry->RegisterStringPref(prefs::kSyncedDefaultSearchProviderGUID,
57                                std::string(),
58                                user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
59   registry->RegisterBooleanPref(
60       prefs::kDefaultSearchProviderEnabled,
61       true,
62       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
63   registry->RegisterStringPref(
64       prefs::kDefaultSearchProviderName,
65       std::string(),
66       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
67   registry->RegisterStringPref(
68       prefs::kDefaultSearchProviderID,
69       std::string(),
70       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
71   registry->RegisterStringPref(
72       prefs::kDefaultSearchProviderPrepopulateID,
73       std::string(),
74       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
75   registry->RegisterStringPref(
76       prefs::kDefaultSearchProviderSuggestURL,
77       std::string(),
78       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
79   registry->RegisterStringPref(
80       prefs::kDefaultSearchProviderSearchURL,
81       std::string(),
82       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
83   registry->RegisterStringPref(
84       prefs::kDefaultSearchProviderInstantURL,
85       std::string(),
86       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
87   registry->RegisterStringPref(
88       prefs::kDefaultSearchProviderImageURL,
89       std::string(),
90       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
91   registry->RegisterStringPref(
92       prefs::kDefaultSearchProviderNewTabURL,
93       std::string(),
94       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
95   registry->RegisterStringPref(
96       prefs::kDefaultSearchProviderSearchURLPostParams,
97       std::string(),
98       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
99   registry->RegisterStringPref(
100       prefs::kDefaultSearchProviderSuggestURLPostParams,
101       std::string(),
102       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
103   registry->RegisterStringPref(
104       prefs::kDefaultSearchProviderInstantURLPostParams,
105       std::string(),
106       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
107   registry->RegisterStringPref(
108       prefs::kDefaultSearchProviderImageURLPostParams,
109       std::string(),
110       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
111   registry->RegisterStringPref(
112       prefs::kDefaultSearchProviderKeyword,
113       std::string(),
114       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
115   registry->RegisterStringPref(
116       prefs::kDefaultSearchProviderIconURL,
117       std::string(),
118       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
119   registry->RegisterStringPref(
120       prefs::kDefaultSearchProviderEncodings,
121       std::string(),
122       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
123   registry->RegisterListPref(prefs::kDefaultSearchProviderAlternateURLs,
124                              user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
125   registry->RegisterStringPref(
126       prefs::kDefaultSearchProviderSearchTermsReplacementKey,
127       std::string(),
128       user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
129 }
130
131 content::BrowserContext* TemplateURLServiceFactory::GetBrowserContextToUse(
132     content::BrowserContext* context) const {
133   return chrome::GetBrowserContextRedirectedInIncognito(context);
134 }
135
136 bool TemplateURLServiceFactory::ServiceIsNULLWhileTesting() const {
137   return true;
138 }