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

Unified Diff: chrome/browser/ui/app_list/start_page_service.cc

Issue 752253002: Updates the mic icon status based on the device's audio state. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 6 years, 1 month 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/ui/app_list/start_page_service.cc
diff --git a/chrome/browser/ui/app_list/start_page_service.cc b/chrome/browser/ui/app_list/start_page_service.cc
index 1ee794255773efdb5ffccb4a582da489a8ec423c..eddd064f8ceb443ee1f74e1ef5a3e1ffb4fc6ce7 100644
--- a/chrome/browser/ui/app_list/start_page_service.cc
+++ b/chrome/browser/ui/app_list/start_page_service.cc
@@ -48,7 +48,7 @@ bool InSpeechRecognition(SpeechRecognitionState state) {
state == SPEECH_RECOGNITION_IN_SPEECH;
}
-}
+} // namespace
class StartPageService::ProfileDestroyObserver
: public content::NotificationObserver {
@@ -102,6 +102,49 @@ class StartPageService::StartPageWebContentsDelegate
DISALLOW_COPY_AND_ASSIGN(StartPageWebContentsDelegate);
};
+#if defined(OS_CHROMEOS)
+
+class StartPageService::AudioStatus
+ : public chromeos::CrasAudioHandler::AudioObserver {
+ public:
+ explicit AudioStatus(StartPageService* start_page_service)
+ : start_page_service_(start_page_service) {
+ chromeos::CrasAudioHandler::Get()->AddAudioObserver(this);
+ CheckAndUpdate();
+ }
+
+ ~AudioStatus() override {
+ chromeos::CrasAudioHandler::Get()->RemoveAudioObserver(this);
+ }
+
+ bool CanListen() {
+ chromeos::CrasAudioHandler* audio_handler =
+ chromeos::CrasAudioHandler::Get();
+ return (audio_handler->GetPrimaryActiveInputNode() != 0) &&
+ !audio_handler->IsInputMuted();
+ }
+
+ private:
+ void CheckAndUpdate() {
+ if (CanListen()) {
tapted 2014/11/26 02:05:59 nit: perhaps start_page_service_->OnSpeechRecogni
Jun Mukai 2014/11/26 23:29:51 Done.
+ start_page_service_->OnSpeechRecognitionStateChanged(
+ SPEECH_RECOGNITION_READY);
+ } else {
+ start_page_service_->OnSpeechRecognitionStateChanged(
+ SPEECH_RECOGNITION_OFF);
+ }
+ }
+
+ // chromeos::CrasAudioHandler::AudioObserver:
+ void OnInputMuteChanged() override { CheckAndUpdate(); }
+
+ void OnActiveInputNodeChanged() override { CheckAndUpdate(); }
+
+ StartPageService* start_page_service_;
+};
tapted 2014/11/26 02:05:59 nit: DISALLOW_COPY_AND_ASSIGN
Jun Mukai 2014/11/26 23:29:51 Done.
+
+#endif // OS_CHROMEOS
+
// static
StartPageService* StartPageService::Get(Profile* profile) {
return StartPageServiceFactory::GetForProfile(profile);
@@ -119,8 +162,9 @@ StartPageService::StartPageService(Profile* profile)
// If experimental hotwording is enabled, then we're always "ready".
// Transitioning into the "hotword recognizing" state is handled by the
// hotword extension.
- if (HotwordService::IsExperimentalHotwordingEnabled())
+ if (HotwordService::IsExperimentalHotwordingEnabled()) {
state_ = app_list::SPEECH_RECOGNITION_READY;
+ }
if (app_list::switches::IsExperimentalAppListEnabled())
LoadContents();
@@ -148,6 +192,10 @@ void StartPageService::AppListShown() {
"appList.startPage.onAppListShown",
base::FundamentalValue(HotwordEnabled()));
}
+
+#if defined(OS_CHROMEOS)
+ audio_status_.reset(new AudioStatus(this));
+#endif
}
void StartPageService::AppListHidden() {
@@ -162,6 +210,10 @@ void StartPageService::AppListHidden() {
speech_recognizer_) {
speech_recognizer_->Stop();
}
+
+#if defined(OS_CHROMEOS)
+ audio_status_.reset();
+#endif
}
void StartPageService::ToggleSpeechRecognition() {
@@ -252,6 +304,14 @@ void StartPageService::OnSpeechSoundLevelChanged(int16_t level) {
void StartPageService::OnSpeechRecognitionStateChanged(
SpeechRecognitionState new_state) {
+#if defined(OS_CHROMEOS)
+ // Sometimes this can be called even though there are no audio input devices.
+ if (!audio_status_->CanListen())
+ new_state = SPEECH_RECOGNITION_OFF;
+#endif
+
+ if (state_ == new_state)
+ return;
if (HotwordService::IsExperimentalHotwordingEnabled() &&
new_state == SPEECH_RECOGNITION_READY &&
@@ -284,6 +344,9 @@ content::WebContents* StartPageService::GetSpeechContents() {
void StartPageService::Shutdown() {
UnloadContents();
+#if defined(OS_CHROMEOS)
+ audio_status_.reset();
+#endif
}
void StartPageService::WebUILoaded() {

Powered by Google App Engine
This is Rietveld 408576698