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

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: 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 } 61 }
62 62
63 // static 63 // static
64 int HotwordServiceFactory::GetCurrentError(BrowserContext* context) { 64 int HotwordServiceFactory::GetCurrentError(BrowserContext* context) {
65 HotwordService* hotword_service = GetForProfile(context); 65 HotwordService* hotword_service = GetForProfile(context);
66 if (!hotword_service) 66 if (!hotword_service)
67 return 0; 67 return 0;
68 return hotword_service->error_message(); 68 return hotword_service->error_message();
69 } 69 }
70 70
71 // static
72 bool HotwordServiceFactory::IsMicrophoneAvailable() {
73 return GetInstance()->microphone_available();
74 }
75
76 // static
77 bool HotwordServiceFactory::IsAudioDeviceStateUpdated() {
78 return GetInstance()->audio_device_state_updated();
79 }
80
81 HotwordServiceFactory::HotwordServiceFactory() 71 HotwordServiceFactory::HotwordServiceFactory()
82 : BrowserContextKeyedServiceFactory( 72 : BrowserContextKeyedServiceFactory(
83 "HotwordService", 73 "HotwordService",
84 BrowserContextDependencyManager::GetInstance()), 74 BrowserContextDependencyManager::GetInstance()) {
85 microphone_available_(false),
86 audio_device_state_updated_(false) {
87 // No dependencies. 75 // No dependencies.
88
89 // Register with the device observer list to update the microphone
90 // availability.
91 BrowserThread::PostTask(
92 BrowserThread::UI, FROM_HERE,
93 base::Bind(&HotwordServiceFactory::InitializeMicrophoneObserver,
94 base::Unretained(this)));
95 } 76 }
96 77
97 HotwordServiceFactory::~HotwordServiceFactory() { 78 HotwordServiceFactory::~HotwordServiceFactory() {
98 } 79 }
99 80
100 void HotwordServiceFactory::InitializeMicrophoneObserver() {
101 MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this);
102 }
103
104 void HotwordServiceFactory::OnUpdateAudioDevices(
105 const content::MediaStreamDevices& devices) {
106 microphone_available_ = !devices.empty();
107 audio_device_state_updated_ = true;
108 }
109
110 void HotwordServiceFactory::UpdateMicrophoneState() { 81 void HotwordServiceFactory::UpdateMicrophoneState() {
111 // In order to trigger the monitor, just call getAudioCaptureDevices. 82 // In order to trigger the monitor, just call getAudioCaptureDevices.
112 content::MediaStreamDevices devices = 83 content::MediaStreamDevices devices =
113 MediaCaptureDevicesDispatcher::GetInstance()->GetAudioCaptureDevices(); 84 MediaCaptureDevicesDispatcher::GetInstance()->GetAudioCaptureDevices();
114 } 85 }
115 86
116 void HotwordServiceFactory::RegisterProfilePrefs( 87 void HotwordServiceFactory::RegisterProfilePrefs(
117 user_prefs::PrefRegistrySyncable* prefs) { 88 user_prefs::PrefRegistrySyncable* prefs) {
118 prefs->RegisterBooleanPref(prefs::kHotwordAudioLoggingEnabled, 89 prefs->RegisterBooleanPref(prefs::kHotwordAudioLoggingEnabled,
119 false, 90 false,
(...skipping 10 matching lines...) Expand all
130 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 101 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
131 prefs->RegisterBooleanPref(prefs::kHotwordAlwaysOnNotificationSeen, 102 prefs->RegisterBooleanPref(prefs::kHotwordAlwaysOnNotificationSeen,
132 false, 103 false,
133 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 104 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
134 } 105 }
135 106
136 KeyedService* HotwordServiceFactory::BuildServiceInstanceFor( 107 KeyedService* HotwordServiceFactory::BuildServiceInstanceFor(
137 BrowserContext* context) const { 108 BrowserContext* context) const {
138 return new HotwordService(Profile::FromBrowserContext(context)); 109 return new HotwordService(Profile::FromBrowserContext(context));
139 } 110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698