hotword_service_factory.cc revision 1e9bf3e0803691d0a228da41fc608347b6db4340
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. 4 5#include "chrome/browser/search/hotword_service_factory.h" 6 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" 14 15// static 16HotwordService* HotwordServiceFactory::GetForProfile(Profile* profile) { 17 if (!profile->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled) || 18 (profile->IsOffTheRecord() && 19 !profile->GetPrefs()->GetBoolean(prefs::kHotwordSearchIncognitoEnabled))) 20 return NULL; 21 22 return static_cast<HotwordService*>( 23 GetInstance()->GetServiceForBrowserContext(profile, true)); 24} 25 26// static 27HotwordServiceFactory* HotwordServiceFactory::GetInstance() { 28 return Singleton<HotwordServiceFactory>::get(); 29} 30 31HotwordServiceFactory::HotwordServiceFactory() 32 : BrowserContextKeyedServiceFactory( 33 "HotwordService", 34 BrowserContextDependencyManager::GetInstance()) { 35 // No dependencies. 36} 37 38HotwordServiceFactory::~HotwordServiceFactory() { 39} 40 41void 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); 49} 50 51content::BrowserContext* HotwordServiceFactory::GetBrowserContextToUse( 52 content::BrowserContext* context) const { 53 return chrome::GetBrowserContextOwnInstanceInIncognito(context); 54} 55 56BrowserContextKeyedService* HotwordServiceFactory::BuildServiceInstanceFor( 57 content::BrowserContext* profile) const { 58 return new HotwordService(static_cast<Profile*>(profile)); 59} 60