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

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: Created 5 years, 9 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
Index: chrome/browser/search/hotword_service.cc
diff --git a/chrome/browser/search/hotword_service.cc b/chrome/browser/search/hotword_service.cc
index e6881665f254051e0f8d97acdb6e047e631b86a1..c34e6831d88fb5b52218cb0d08782c8cf49da0f0 100644
--- a/chrome/browser/search/hotword_service.cc
+++ b/chrome/browser/search/hotword_service.cc
@@ -325,6 +325,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),
@@ -395,6 +397,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() {
@@ -465,6 +474,10 @@ std::string HotwordService::ReinstalledExtensionId() {
return extension_misc::kHotwordSharedModuleId;
}
+void HotwordService::InitializeMicrophoneObserver() {
+ MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this);
+}
+
void HotwordService::InstalledFromWebstoreCallback(
int num_tries,
bool success,
@@ -614,19 +627,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;
}
@@ -781,6 +791,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

Powered by Google App Engine
This is Rietveld 408576698