Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / search / hotword_service_factory.cc
blob1aa72ac258af6fefc989411bca8b1360bb83ad63
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;
21 // static
22 HotwordService* HotwordServiceFactory::GetForProfile(BrowserContext* context) {
23 return static_cast<HotwordService*>(
24 GetInstance()->GetServiceForBrowserContext(context, true));
27 // static
28 HotwordServiceFactory* HotwordServiceFactory::GetInstance() {
29 return Singleton<HotwordServiceFactory>::get();
32 // static
33 bool HotwordServiceFactory::IsServiceAvailable(BrowserContext* context) {
34 HotwordService* hotword_service = GetForProfile(context);
35 return hotword_service && hotword_service->IsServiceAvailable();
38 // static
39 bool HotwordServiceFactory::IsHotwordAllowed(BrowserContext* context) {
40 HotwordService* hotword_service = GetForProfile(context);
41 return hotword_service && hotword_service->IsHotwordAllowed();
44 // static
45 bool HotwordServiceFactory::IsAlwaysOnAvailable() {
46 #if defined(OS_CHROMEOS)
47 if (HotwordService::IsHotwordHardwareAvailable())
48 return true;
49 #endif
50 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
51 return command_line->HasSwitch(switches::kEnableExperimentalHotwordHardware);
54 // static
55 int HotwordServiceFactory::GetCurrentError(BrowserContext* context) {
56 HotwordService* hotword_service = GetForProfile(context);
57 if (!hotword_service)
58 return 0;
59 return hotword_service->error_message();
62 HotwordServiceFactory::HotwordServiceFactory()
63 : BrowserContextKeyedServiceFactory(
64 "HotwordService",
65 BrowserContextDependencyManager::GetInstance()) {
66 // No dependencies.
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,
81 false,
82 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
83 prefs->RegisterStringPref(prefs::kHotwordPreviousLanguage,
84 std::string(),
85 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
86 // Per-device settings (do not sync).
87 prefs->RegisterBooleanPref(prefs::kHotwordSearchEnabled,
88 false,
89 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
90 prefs->RegisterBooleanPref(prefs::kHotwordAlwaysOnSearchEnabled,
91 false,
92 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
93 prefs->RegisterBooleanPref(prefs::kHotwordAlwaysOnNotificationSeen,
94 false,
95 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
98 KeyedService* HotwordServiceFactory::BuildServiceInstanceFor(
99 BrowserContext* context) const {
100 return new HotwordService(Profile::FromBrowserContext(context));