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"
16 HotwordService
* HotwordServiceFactory::GetForProfile(Profile
* profile
) {
17 if (!profile
->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled
) ||
18 (profile
->IsOffTheRecord() &&
19 !profile
->GetPrefs()->GetBoolean(prefs::kHotwordSearchIncognitoEnabled
)))
22 return static_cast<HotwordService
*>(
23 GetInstance()->GetServiceForBrowserContext(profile
, true));
27 HotwordServiceFactory
* HotwordServiceFactory::GetInstance() {
28 return Singleton
<HotwordServiceFactory
>::get();
31 HotwordServiceFactory::HotwordServiceFactory()
32 : BrowserContextKeyedServiceFactory(
34 BrowserContextDependencyManager::GetInstance()) {
38 HotwordServiceFactory::~HotwordServiceFactory() {
41 void HotwordServiceFactory::RegisterProfilePrefs(
42 user_prefs::PrefRegistrySyncable
* prefs
) {
43 prefs
->RegisterBooleanPref(prefs::kHotwordSearchEnabled
,
45 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
46 prefs
->RegisterBooleanPref(prefs::kHotwordSearchIncognitoEnabled
,
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
));