Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / search_engines / template_url_service_factory.cc
blob6d524478d4e44a50c31565ff961c4a0c8bf3a511
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/search_engines/chrome_template_url_service_client.h"
17 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
18 #include "chrome/browser/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 #if defined(ENABLE_RLZ)
26 #include "components/rlz/rlz_tracker.h"
27 #endif
29 // static
30 TemplateURLService* TemplateURLServiceFactory::GetForProfile(Profile* profile) {
31 return static_cast<TemplateURLService*>(
32 GetInstance()->GetServiceForBrowserContext(profile, true));
35 // static
36 TemplateURLServiceFactory* TemplateURLServiceFactory::GetInstance() {
37 return Singleton<TemplateURLServiceFactory>::get();
40 // static
41 scoped_ptr<KeyedService> TemplateURLServiceFactory::BuildInstanceFor(
42 content::BrowserContext* context) {
43 base::Closure dsp_change_callback;
44 #if defined(ENABLE_RLZ)
45 dsp_change_callback = base::Bind(
46 base::IgnoreResult(&rlz::RLZTracker::RecordProductEvent), rlz_lib::CHROME,
47 rlz::RLZTracker::ChromeOmnibox(), rlz_lib::SET_TO_GOOGLE);
48 #endif
49 Profile* profile = static_cast<Profile*>(context);
50 return make_scoped_ptr(new TemplateURLService(
51 profile->GetPrefs(),
52 scoped_ptr<SearchTermsData>(new UIThreadSearchTermsData(profile)),
53 WebDataServiceFactory::GetKeywordWebDataForProfile(
54 profile, ServiceAccessType::EXPLICIT_ACCESS),
55 scoped_ptr<TemplateURLServiceClient>(new ChromeTemplateURLServiceClient(
56 HistoryServiceFactory::GetForProfile(
57 profile, ServiceAccessType::EXPLICIT_ACCESS))),
58 GoogleURLTrackerFactory::GetForProfile(profile),
59 g_browser_process->rappor_service(), 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)).release();
78 void TemplateURLServiceFactory::RegisterProfilePrefs(
79 user_prefs::PrefRegistrySyncable* registry) {
80 DefaultSearchManager::RegisterProfilePrefs(registry);
81 TemplateURLService::RegisterProfilePrefs(registry);
84 content::BrowserContext* TemplateURLServiceFactory::GetBrowserContextToUse(
85 content::BrowserContext* context) const {
86 return chrome::GetBrowserContextRedirectedInIncognito(context);
89 bool TemplateURLServiceFactory::ServiceIsNULLWhileTesting() const {
90 return true;