Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(409)

Side by Side Diff: chrome/browser/search/hotword_service_factory.cc

Issue 1047973003: Notify hotwording extension of microphone state change. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/search/hotword_service_factory.h" 5 #include "chrome/browser/search/hotword_service_factory.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/search/hotword_service.h" 10 #include "chrome/browser/search/hotword_service.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } 52 }
53 53
54 // static 54 // static
55 int HotwordServiceFactory::GetCurrentError(BrowserContext* context) { 55 int HotwordServiceFactory::GetCurrentError(BrowserContext* context) {
56 HotwordService* hotword_service = GetForProfile(context); 56 HotwordService* hotword_service = GetForProfile(context);
57 if (!hotword_service) 57 if (!hotword_service)
58 return 0; 58 return 0;
59 return hotword_service->error_message(); 59 return hotword_service->error_message();
60 } 60 }
61 61
62 // static
63 bool HotwordServiceFactory::IsMicrophoneAvailable() {
64 return GetInstance()->microphone_available();
65 }
66
67 // static
68 bool HotwordServiceFactory::IsAudioDeviceStateUpdated() {
69 return GetInstance()->audio_device_state_updated();
70 }
71
72 HotwordServiceFactory::HotwordServiceFactory() 62 HotwordServiceFactory::HotwordServiceFactory()
73 : BrowserContextKeyedServiceFactory( 63 : BrowserContextKeyedServiceFactory(
74 "HotwordService", 64 "HotwordService",
75 BrowserContextDependencyManager::GetInstance()), 65 BrowserContextDependencyManager::GetInstance()) {
76 microphone_available_(false),
77 audio_device_state_updated_(false) {
78 // No dependencies. 66 // No dependencies.
79
80 // Register with the device observer list to update the microphone
81 // availability.
82 BrowserThread::PostTask(
83 BrowserThread::UI, FROM_HERE,
84 base::Bind(&HotwordServiceFactory::InitializeMicrophoneObserver,
85 base::Unretained(this)));
86 } 67 }
87 68
88 HotwordServiceFactory::~HotwordServiceFactory() { 69 HotwordServiceFactory::~HotwordServiceFactory() {
89 } 70 }
90 71
91 void HotwordServiceFactory::InitializeMicrophoneObserver() {
92 MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this);
93 }
94
95 void HotwordServiceFactory::OnUpdateAudioDevices(
96 const content::MediaStreamDevices& devices) {
97 microphone_available_ = !devices.empty();
98 audio_device_state_updated_ = true;
99 }
100
101 void HotwordServiceFactory::UpdateMicrophoneState() { 72 void HotwordServiceFactory::UpdateMicrophoneState() {
102 // In order to trigger the monitor, just call getAudioCaptureDevices. 73 // In order to trigger the monitor, just call getAudioCaptureDevices.
103 content::MediaStreamDevices devices = 74 content::MediaStreamDevices devices =
104 MediaCaptureDevicesDispatcher::GetInstance()->GetAudioCaptureDevices(); 75 MediaCaptureDevicesDispatcher::GetInstance()->GetAudioCaptureDevices();
105 } 76 }
106 77
107 void HotwordServiceFactory::RegisterProfilePrefs( 78 void HotwordServiceFactory::RegisterProfilePrefs(
108 user_prefs::PrefRegistrySyncable* prefs) { 79 user_prefs::PrefRegistrySyncable* prefs) {
109 prefs->RegisterBooleanPref(prefs::kHotwordAudioLoggingEnabled, 80 prefs->RegisterBooleanPref(prefs::kHotwordAudioLoggingEnabled,
110 false, 81 false,
(...skipping 10 matching lines...) Expand all
121 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 92 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
122 prefs->RegisterBooleanPref(prefs::kHotwordAlwaysOnNotificationSeen, 93 prefs->RegisterBooleanPref(prefs::kHotwordAlwaysOnNotificationSeen,
123 false, 94 false,
124 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 95 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
125 } 96 }
126 97
127 KeyedService* HotwordServiceFactory::BuildServiceInstanceFor( 98 KeyedService* HotwordServiceFactory::BuildServiceInstanceFor(
128 BrowserContext* context) const { 99 BrowserContext* context) const {
129 return new HotwordService(Profile::FromBrowserContext(context)); 100 return new HotwordService(Profile::FromBrowserContext(context));
130 } 101 }
OLDNEW
« no previous file with comments | « chrome/browser/search/hotword_service_factory.h ('k') | chrome/browser/ui/webui/voice_search_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698