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

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

Issue 676593003: Implement native speech recognition for the launcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Pass in WeakPtr<Delegate>. 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
« no previous file with comments | « chrome/browser/ui/app_list/start_page_service.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 3bf52716cae76ce23a0fb9bb3b43a12a1d3d475b..09c66ca0cf5e9bd799579033518de37491075e47 100644
--- a/chrome/browser/ui/app_list/start_page_service.cc
+++ b/chrome/browser/ui/app_list/start_page_service.cc
@@ -11,12 +11,14 @@
#include "base/memory/singleton.h"
#include "base/metrics/user_metrics.h"
#include "base/prefs/pref_service.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/media/media_stream_infobar_delegate.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/hotword_service.h"
#include "chrome/browser/search/hotword_service_factory.h"
#include "chrome/browser/ui/app_list/recommended_apps.h"
+#include "chrome/browser/ui/app_list/speech_recognizer.h"
#include "chrome/browser/ui/app_list/start_page_observer.h"
#include "chrome/browser/ui/app_list/start_page_service_factory.h"
#include "chrome/common/chrome_switches.h"
@@ -112,7 +114,8 @@ StartPageService::StartPageService(Profile* profile)
state_(app_list::SPEECH_RECOGNITION_OFF),
speech_button_toggled_manually_(false),
speech_result_obtained_(false),
- webui_finished_loading_(false) {
+ webui_finished_loading_(false),
+ weak_factory_(this) {
// If experimental hotwording is enabled, then we're always "ready".
// Transitioning into the "hotword recognizing" state is handled by the
// hotword extension.
@@ -136,14 +139,14 @@ void StartPageService::RemoveObserver(StartPageObserver* observer) {
void StartPageService::AppListShown() {
if (!contents_) {
LoadContents();
- } else if (contents_->GetWebUI()) {
- // If experimental hotwording is enabled, don't enable hotwording in the
- // start page, since the hotword extension is taking care of this.
- bool hotword_enabled = HotwordEnabled() &&
- !HotwordService::IsExperimentalHotwordingEnabled();
+ } else if (contents_->GetWebUI() &&
+ !HotwordService::IsExperimentalHotwordingEnabled()) {
+ // If experimental hotwording is enabled, don't call onAppListShown.
+ // onAppListShown() initializes the web speech API, which is not used with
+ // experimental hotwording.
contents_->GetWebUI()->CallJavascriptFunction(
"appList.startPage.onAppListShown",
- base::FundamentalValue(hotword_enabled));
+ base::FundamentalValue(HotwordEnabled()));
}
}
@@ -154,6 +157,11 @@ void StartPageService::AppListHidden() {
}
if (!app_list::switches::IsExperimentalAppListEnabled())
UnloadContents();
+
+ if (HotwordService::IsExperimentalHotwordingEnabled() &&
+ speech_recognizer_) {
+ speech_recognizer_->Stop();
+ }
}
void StartPageService::ToggleSpeechRecognition() {
@@ -162,14 +170,35 @@ void StartPageService::ToggleSpeechRecognition() {
if (!contents_->GetWebUI())
return;
- if (webui_finished_loading_) {
- contents_->GetWebUI()->CallJavascriptFunction(
- "appList.startPage.toggleSpeechRecognition");
- } else {
+ if (!webui_finished_loading_) {
pending_webui_callbacks_.push_back(
base::Bind(&StartPageService::ToggleSpeechRecognition,
base::Unretained(this)));
+ return;
}
+
+ if (HotwordService::IsExperimentalHotwordingEnabled()) {
+ if (!speech_recognizer_) {
+ std::string profile_locale;
+#if defined(OS_CHROMEOS)
+ profile_locale = profile_->GetPrefs()->GetString(
+ prefs::kApplicationLocale);
+#endif
+ if (profile_locale.empty())
+ profile_locale = g_browser_process->GetApplicationLocale();
+
+ speech_recognizer_.reset(
+ new SpeechRecognizer(weak_factory_.GetWeakPtr(),
+ profile_->GetRequestContext(),
+ profile_locale));
+ }
+
+ speech_recognizer_->Start();
+ return;
+ }
+
+ contents_->GetWebUI()->CallJavascriptFunction(
+ "appList.startPage.toggleSpeechRecognition");
}
bool StartPageService::HotwordEnabled() {
@@ -212,7 +241,7 @@ void StartPageService::OnSpeechResult(
OnSpeechResult(query, is_final));
}
-void StartPageService::OnSpeechSoundLevelChanged(int16 level) {
+void StartPageService::OnSpeechSoundLevelChanged(int16_t level) {
FOR_EACH_OBSERVER(StartPageObserver,
observers_,
OnSpeechSoundLevelChanged(level));
@@ -220,6 +249,13 @@ void StartPageService::OnSpeechSoundLevelChanged(int16 level) {
void StartPageService::OnSpeechRecognitionStateChanged(
SpeechRecognitionState new_state) {
+
+ if (HotwordService::IsExperimentalHotwordingEnabled() &&
+ new_state == SPEECH_RECOGNITION_READY &&
+ speech_recognizer_) {
+ speech_recognizer_->Stop();
+ }
+
if (!InSpeechRecognition(state_) && InSpeechRecognition(new_state)) {
if (!speech_button_toggled_manually_ &&
state_ == SPEECH_RECOGNITION_HOTWORD_LISTENING) {
@@ -239,6 +275,10 @@ void StartPageService::OnSpeechRecognitionStateChanged(
OnSpeechRecognitionStateChanged(new_state));
}
+content::WebContents* StartPageService::GetSpeechContents() {
+ return GetSpeechRecognitionContents();
+}
+
void StartPageService::Shutdown() {
UnloadContents();
}
« no previous file with comments | « chrome/browser/ui/app_list/start_page_service.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698