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

Unified Diff: chrome/browser/search/hotword_service.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/search/hotword_service.h ('k') | chrome/browser/search/hotword_service_factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/search/hotword_service.cc
diff --git a/chrome/browser/search/hotword_service.cc b/chrome/browser/search/hotword_service.cc
index 6ee699fbab60557b516e3eacf3c55bf23447f387..db9d85faa3bde9292d20191cc704ce296d722528 100644
--- a/chrome/browser/search/hotword_service.cc
+++ b/chrome/browser/search/hotword_service.cc
@@ -323,6 +323,8 @@ void HotwordService::HotwordWebstoreInstaller::Shutdown() {
HotwordService::HotwordService(Profile* profile)
: profile_(profile),
extension_registry_observer_(this),
+ microphone_available_(false),
+ audio_device_state_updated_(false),
client_(NULL),
error_message_(0),
reinstall_pending_(false),
@@ -386,6 +388,13 @@ HotwordService::HotwordService(Profile* profile)
session_observer_.get());
}
#endif
+
+ // Register with the device observer list to update the microphone
+ // availability.
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&HotwordService::InitializeMicrophoneObserver,
+ base::Unretained(this)));
}
HotwordService::~HotwordService() {
@@ -456,6 +465,10 @@ std::string HotwordService::ReinstalledExtensionId() {
return extension_misc::kHotwordSharedModuleId;
}
+void HotwordService::InitializeMicrophoneObserver() {
+ MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this);
+}
+
void HotwordService::InstalledFromWebstoreCallback(
int num_tries,
bool success,
@@ -605,19 +618,16 @@ bool HotwordService::IsServiceAvailable() {
RecordErrorMetrics(error_message_);
- // Determine if the proper audio capabilities exist.
- // The first time this is called, it probably won't return in time, but that's
- // why it won't be included in the error calculation (i.e., the call to
- // IsAudioDeviceStateUpdated()). However, this use case is rare and typically
- // the devices will be initialized by the time a user goes to settings.
- bool audio_device_state_updated =
- HotwordServiceFactory::IsAudioDeviceStateUpdated();
+ // Determine if the proper audio capabilities exist. The first time this is
+ // called, it probably won't return in time, but that's why it won't be
+ // included in the error calculation. However, this use case is rare and
+ // typically the devices will be initialized by the time a user goes to
+ // settings.
HotwordServiceFactory::GetInstance()->UpdateMicrophoneState();
- if (audio_device_state_updated) {
+ if (audio_device_state_updated_) {
bool audio_capture_allowed =
profile_->GetPrefs()->GetBoolean(prefs::kAudioCaptureAllowed);
- if (!audio_capture_allowed ||
- !HotwordServiceFactory::IsMicrophoneAvailable())
+ if (!audio_capture_allowed || !microphone_available_)
error_message_ = IDS_HOTWORD_MICROPHONE_ERROR_MESSAGE;
}
@@ -772,6 +782,17 @@ void HotwordService::DisableHotwordPreferences() {
}
}
+void HotwordService::OnUpdateAudioDevices(
+ const content::MediaStreamDevices& devices) {
+ bool microphone_was_available = microphone_available_;
+ microphone_available_ = !devices.empty();
+ audio_device_state_updated_ = true;
+ HotwordPrivateEventService* event_service =
+ BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_);
+ if (event_service && microphone_was_available != microphone_available_)
+ event_service->OnMicrophoneStateChanged(microphone_available_);
+}
+
void HotwordService::OnHotwordAlwaysOnSearchEnabledChanged(
const std::string& pref_name) {
// If the pref for always on has been changed in some way, that means that
« no previous file with comments | « chrome/browser/search/hotword_service.h ('k') | chrome/browser/search/hotword_service_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698