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/command_line.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/search/hotword_service.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/pref_names.h"
13 #include "components/keyed_service/content/browser_context_dependency_manager.h"
14 #include "components/pref_registry/pref_registry_syncable.h"
15 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/browser_thread.h"
18 using content::BrowserContext
;
19 using content::BrowserThread
;
22 HotwordService
* HotwordServiceFactory::GetForProfile(BrowserContext
* context
) {
23 return static_cast<HotwordService
*>(
24 GetInstance()->GetServiceForBrowserContext(context
, true));
28 HotwordServiceFactory
* HotwordServiceFactory::GetInstance() {
29 return Singleton
<HotwordServiceFactory
>::get();
33 bool HotwordServiceFactory::IsServiceAvailable(BrowserContext
* context
) {
34 HotwordService
* hotword_service
= GetForProfile(context
);
35 return hotword_service
&& hotword_service
->IsServiceAvailable();
39 bool HotwordServiceFactory::IsHotwordAllowed(BrowserContext
* context
) {
40 HotwordService
* hotword_service
= GetForProfile(context
);
41 return hotword_service
&& hotword_service
->IsHotwordAllowed();
45 bool HotwordServiceFactory::IsAlwaysOnAvailable() {
46 #if defined(OS_CHROMEOS)
47 if (HotwordService::IsHotwordHardwareAvailable())
50 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
51 return command_line
->HasSwitch(switches::kEnableExperimentalHotwordHardware
);
55 int HotwordServiceFactory::GetCurrentError(BrowserContext
* context
) {
56 HotwordService
* hotword_service
= GetForProfile(context
);
59 return hotword_service
->error_message();
62 HotwordServiceFactory::HotwordServiceFactory()
63 : BrowserContextKeyedServiceFactory(
65 BrowserContextDependencyManager::GetInstance()) {
69 HotwordServiceFactory::~HotwordServiceFactory() {
72 void HotwordServiceFactory::UpdateMicrophoneState() {
73 // In order to trigger the monitor, just call getAudioCaptureDevices.
74 content::MediaStreamDevices devices
=
75 MediaCaptureDevicesDispatcher::GetInstance()->GetAudioCaptureDevices();
78 void HotwordServiceFactory::RegisterProfilePrefs(
79 user_prefs::PrefRegistrySyncable
* prefs
) {
80 prefs
->RegisterBooleanPref(prefs::kHotwordAudioLoggingEnabled
,
82 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
83 prefs
->RegisterStringPref(prefs::kHotwordPreviousLanguage
,
85 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
86 // Per-device settings (do not sync).
87 prefs
->RegisterBooleanPref(prefs::kHotwordSearchEnabled
,
89 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
90 prefs
->RegisterBooleanPref(prefs::kHotwordAlwaysOnSearchEnabled
,
92 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
93 prefs
->RegisterBooleanPref(prefs::kHotwordAlwaysOnNotificationSeen
,
95 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
98 KeyedService
* HotwordServiceFactory::BuildServiceInstanceFor(
99 BrowserContext
* context
) const {
100 return new HotwordService(Profile::FromBrowserContext(context
));