| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/app_list/start_page_service.h" | 5 #include "chrome/browser/ui/app_list/start_page_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 } | 217 } |
| 218 | 218 |
| 219 #if defined(OS_CHROMEOS) | 219 #if defined(OS_CHROMEOS) |
| 220 audio_status_.reset(); | 220 audio_status_.reset(); |
| 221 #endif | 221 #endif |
| 222 } | 222 } |
| 223 | 223 |
| 224 void StartPageService::ToggleSpeechRecognition() { | 224 void StartPageService::ToggleSpeechRecognition() { |
| 225 DCHECK(contents_); | 225 DCHECK(contents_); |
| 226 speech_button_toggled_manually_ = true; | 226 speech_button_toggled_manually_ = true; |
| 227 if (!contents_->GetWebUI()) | |
| 228 return; | |
| 229 | 227 |
| 230 if (!webui_finished_loading_) { | 228 // Speech recognition under V2 hotwording does not depend in any way on the |
| 231 pending_webui_callbacks_.push_back( | 229 // start page web contents. Do this code path first to make this explicit and |
| 232 base::Bind(&StartPageService::ToggleSpeechRecognition, | 230 // easier to identify what code needs to be deleted when V2 hotwording is |
| 233 base::Unretained(this))); | 231 // stable. |
| 234 return; | |
| 235 } | |
| 236 | |
| 237 if (HotwordService::IsExperimentalHotwordingEnabled()) { | 232 if (HotwordService::IsExperimentalHotwordingEnabled()) { |
| 238 if (!speech_recognizer_) { | 233 if (!speech_recognizer_) { |
| 239 std::string profile_locale; | 234 std::string profile_locale; |
| 240 #if defined(OS_CHROMEOS) | 235 #if defined(OS_CHROMEOS) |
| 241 profile_locale = profile_->GetPrefs()->GetString( | 236 profile_locale = profile_->GetPrefs()->GetString( |
| 242 prefs::kApplicationLocale); | 237 prefs::kApplicationLocale); |
| 243 #endif | 238 #endif |
| 244 if (profile_locale.empty()) | 239 if (profile_locale.empty()) |
| 245 profile_locale = g_browser_process->GetApplicationLocale(); | 240 profile_locale = g_browser_process->GetApplicationLocale(); |
| 246 | 241 |
| 247 speech_recognizer_.reset( | 242 speech_recognizer_.reset( |
| 248 new SpeechRecognizer(weak_factory_.GetWeakPtr(), | 243 new SpeechRecognizer(weak_factory_.GetWeakPtr(), |
| 249 profile_->GetRequestContext(), | 244 profile_->GetRequestContext(), |
| 250 profile_locale)); | 245 profile_locale)); |
| 251 } | 246 } |
| 252 | 247 |
| 253 speech_recognizer_->Start(); | 248 speech_recognizer_->Start(); |
| 254 return; | 249 return; |
| 255 } | 250 } |
| 256 | 251 |
| 252 if (!contents_->GetWebUI()) |
| 253 return; |
| 254 |
| 255 if (!webui_finished_loading_) { |
| 256 pending_webui_callbacks_.push_back( |
| 257 base::Bind(&StartPageService::ToggleSpeechRecognition, |
| 258 base::Unretained(this))); |
| 259 return; |
| 260 } |
| 261 |
| 257 contents_->GetWebUI()->CallJavascriptFunction( | 262 contents_->GetWebUI()->CallJavascriptFunction( |
| 258 "appList.startPage.toggleSpeechRecognition"); | 263 "appList.startPage.toggleSpeechRecognition"); |
| 259 } | 264 } |
| 260 | 265 |
| 261 bool StartPageService::HotwordEnabled() { | 266 bool StartPageService::HotwordEnabled() { |
| 262 // Voice input for the launcher is unsupported on non-ChromeOS platforms. | 267 // Voice input for the launcher is unsupported on non-ChromeOS platforms. |
| 263 // TODO(amistry): Make speech input, and hotwording, work on non-ChromeOS. | 268 // TODO(amistry): Make speech input, and hotwording, work on non-ChromeOS. |
| 264 #if defined(OS_CHROMEOS) | 269 #if defined(OS_CHROMEOS) |
| 265 if (HotwordService::IsExperimentalHotwordingEnabled()) { | 270 if (HotwordService::IsExperimentalHotwordingEnabled()) { |
| 266 HotwordService* service = HotwordServiceFactory::GetForProfile(profile_); | 271 HotwordService* service = HotwordServiceFactory::GetForProfile(profile_); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 RecordAction(UserMetricsAction("AppList_VoiceSearchCanceled")); | 340 RecordAction(UserMetricsAction("AppList_VoiceSearchCanceled")); |
| 336 } | 341 } |
| 337 speech_button_toggled_manually_ = false; | 342 speech_button_toggled_manually_ = false; |
| 338 speech_result_obtained_ = false; | 343 speech_result_obtained_ = false; |
| 339 state_ = new_state; | 344 state_ = new_state; |
| 340 FOR_EACH_OBSERVER(StartPageObserver, | 345 FOR_EACH_OBSERVER(StartPageObserver, |
| 341 observers_, | 346 observers_, |
| 342 OnSpeechRecognitionStateChanged(new_state)); | 347 OnSpeechRecognitionStateChanged(new_state)); |
| 343 } | 348 } |
| 344 | 349 |
| 345 content::WebContents* StartPageService::GetSpeechContents() { | |
| 346 return GetSpeechRecognitionContents(); | |
| 347 } | |
| 348 | |
| 349 void StartPageService::GetSpeechAuthParameters(std::string* auth_scope, | 350 void StartPageService::GetSpeechAuthParameters(std::string* auth_scope, |
| 350 std::string* auth_token) { | 351 std::string* auth_token) { |
| 351 if (HotwordService::IsExperimentalHotwordingEnabled()) { | 352 if (HotwordService::IsExperimentalHotwordingEnabled()) { |
| 352 HotwordService* service = HotwordServiceFactory::GetForProfile(profile_); | 353 HotwordService* service = HotwordServiceFactory::GetForProfile(profile_); |
| 353 if (service && | 354 if (service && |
| 354 service->IsOptedIntoAudioLogging() && | 355 service->IsOptedIntoAudioLogging() && |
| 355 !speech_auth_helper_->GetToken().empty()) { | 356 !speech_auth_helper_->GetToken().empty()) { |
| 356 *auth_scope = speech_auth_helper_->GetScope(); | 357 *auth_scope = speech_auth_helper_->GetScope(); |
| 357 *auth_token = speech_auth_helper_->GetToken(); | 358 *auth_token = speech_auth_helper_->GetToken(); |
| 358 } | 359 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 393 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 393 std::string()); | 394 std::string()); |
| 394 } | 395 } |
| 395 | 396 |
| 396 void StartPageService::UnloadContents() { | 397 void StartPageService::UnloadContents() { |
| 397 contents_.reset(); | 398 contents_.reset(); |
| 398 webui_finished_loading_ = false; | 399 webui_finished_loading_ = false; |
| 399 } | 400 } |
| 400 | 401 |
| 401 } // namespace app_list | 402 } // namespace app_list |
| OLD | NEW |