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

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: 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..a932bc7a9bdc3a255ba70f398310e32bd2aceebe 100644
--- a/chrome/browser/ui/app_list/start_page_service.cc
+++ b/chrome/browser/ui/app_list/start_page_service.cc
@@ -43,12 +43,27 @@ namespace app_list {
namespace {
+bool IsVoiceSearchEnabled() {
tapted 2014/11/25 05:03:10 It's a bit confusing having standalone `IsVoiceSea
Jun Mukai 2014/11/26 01:39:21 Done to rename it to CanListen. Not so sure about
+ if (!app_list::switches::IsVoiceSearchEnabled())
+ return false;
+#if defined(OS_CHROMEOS)
+ if (!chromeos::CrasAudioHandler::IsInitialized())
+ return false;
+ chromeos::CrasAudioHandler* audio_handler = chromeos::CrasAudioHandler::Get();
+ if (!audio_handler->GetPrimaryActiveInputNode())
+ return false;
+ if (audio_handler->IsInputMuted())
+ return false;
+#endif
+ return true;
+}
+
bool InSpeechRecognition(SpeechRecognitionState state) {
return state == SPEECH_RECOGNITION_RECOGNIZING ||
state == SPEECH_RECOGNITION_IN_SPEECH;
}
-}
+} // namespace
class StartPageService::ProfileDestroyObserver
: public content::NotificationObserver {
@@ -119,8 +134,10 @@ 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 (IsVoiceSearchEnabled() &&
+ HotwordService::IsExperimentalHotwordingEnabled()) {
state_ = app_list::SPEECH_RECOGNITION_READY;
+ }
if (app_list::switches::IsExperimentalAppListEnabled())
LoadContents();
@@ -148,6 +165,9 @@ void StartPageService::AppListShown() {
"appList.startPage.onAppListShown",
base::FundamentalValue(HotwordEnabled()));
}
+#if defined(OS_CHROMEOS)
+ chromeos::CrasAudioHandler::Get()->AddAudioObserver(this);
tapted 2014/11/25 11:07:52 Also, what are the implications for always-on-hotw
Jun Mukai 2014/11/26 01:39:21 If that flag is specified, indeed it attempts to r
tapted 2014/11/26 02:05:58 So long as always-on isn't worse with it like this
Anand Mistry (off Chromium) 2014/11/26 10:49:58 If I understand this change correctly, under the n
Jun Mukai 2014/11/26 21:59:44 That is right. But I guess the hotworder will stop
Jun Mukai 2014/11/26 23:29:50 After thinking again, I've realized that this is s
+#endif
}
void StartPageService::AppListHidden() {
@@ -162,6 +182,9 @@ void StartPageService::AppListHidden() {
speech_recognizer_) {
speech_recognizer_->Stop();
}
+#if defined(OS_CHROMEOS)
+ chromeos::CrasAudioHandler::Get()->RemoveAudioObserver(this);
+#endif
}
void StartPageService::ToggleSpeechRecognition() {
@@ -225,7 +248,7 @@ content::WebContents* StartPageService::GetStartPageContents() {
}
content::WebContents* StartPageService::GetSpeechRecognitionContents() {
- if (app_list::switches::IsVoiceSearchEnabled()) {
+ if (IsVoiceSearchEnabled()) {
tapted 2014/11/25 05:03:10 Why this change? It doesn't seem robust to return
Jun Mukai 2014/11/26 01:39:21 Reverted back to the original. The original motiv
if (!contents_)
LoadContents();
return contents_.get();
@@ -252,6 +275,9 @@ void StartPageService::OnSpeechSoundLevelChanged(int16_t level) {
void StartPageService::OnSpeechRecognitionStateChanged(
SpeechRecognitionState new_state) {
+ // Sometimes this can be called even though there are no audio input devices.
+ if (!IsVoiceSearchEnabled())
+ new_state = SPEECH_RECOGNITION_OFF;
tapted 2014/11/25 05:03:10 This can leave new_state == state_ -- should that
Jun Mukai 2014/11/26 01:39:21 Done.
if (HotwordService::IsExperimentalHotwordingEnabled() &&
new_state == SPEECH_RECOGNITION_READY &&
@@ -286,6 +312,19 @@ void StartPageService::Shutdown() {
UnloadContents();
}
+#if defined(OS_CHROMEOS)
+void StartPageService::OnInputMuteChanged() {
+ if (IsVoiceSearchEnabled())
+ OnSpeechRecognitionStateChanged(SPEECH_RECOGNITION_READY);
+ else
+ OnSpeechRecognitionStateChanged(SPEECH_RECOGNITION_OFF);
+}
+
+void StartPageService::OnActiveInputNodeChanged() {
+ OnInputMuteChanged();
+}
+#endif
+
void StartPageService::WebUILoaded() {
// There's a race condition between the WebUI loading, and calling its JS
// functions. Specifically, calling LoadContents() doesn't mean that the page

Powered by Google App Engine
This is Rietveld 408576698