Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / search / hotword_service_factory.cc
blob675d86c24d4c6bcad392e1e20abca312a53ab473
1 // Copyright 2013 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/hotword_service_factory.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/profiles/incognito_helpers.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/search/hotword_service.h"
11 #include "chrome/common/pref_names.h"
12 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
13 #include "components/user_prefs/pref_registry_syncable.h"
15 // static
16 HotwordService* HotwordServiceFactory::GetForProfile(Profile* profile) {
17 if (!profile->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled) ||
18 (profile->IsOffTheRecord() &&
19 !profile->GetPrefs()->GetBoolean(prefs::kHotwordSearchIncognitoEnabled)))
20 return NULL;
22 return static_cast<HotwordService*>(
23 GetInstance()->GetServiceForBrowserContext(profile, true));
26 // static
27 HotwordServiceFactory* HotwordServiceFactory::GetInstance() {
28 return Singleton<HotwordServiceFactory>::get();
31 HotwordServiceFactory::HotwordServiceFactory()
32 : BrowserContextKeyedServiceFactory(
33 "HotwordService",
34 BrowserContextDependencyManager::GetInstance()) {
35 // No dependencies.
38 HotwordServiceFactory::~HotwordServiceFactory() {
41 void HotwordServiceFactory::RegisterProfilePrefs(
42 user_prefs::PrefRegistrySyncable* prefs) {
43 prefs->RegisterBooleanPref(prefs::kHotwordSearchEnabled,
44 false,
45 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
46 prefs->RegisterBooleanPref(prefs::kHotwordSearchIncognitoEnabled,
47 false,
48 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
51 content::BrowserContext* HotwordServiceFactory::GetBrowserContextToUse(
52 content::BrowserContext* context) const {
53 return chrome::GetBrowserContextOwnInstanceInIncognito(context);
56 BrowserContextKeyedService* HotwordServiceFactory::BuildServiceInstanceFor(
57 content::BrowserContext* profile) const {
58 return new HotwordService(static_cast<Profile*>(profile));