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

Side by Side Diff: chrome/browser/ui/app_list/start_page_service.cc

Issue 992173002: Delete the old hotwording integration. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hotword-remove-disable-option
Patch Set: Rebase 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 unified diff | Download patch
OLDNEW
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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 }; 274 };
275 275
276 // static 276 // static
277 StartPageService* StartPageService::Get(Profile* profile) { 277 StartPageService* StartPageService::Get(Profile* profile) {
278 return StartPageServiceFactory::GetForProfile(profile); 278 return StartPageServiceFactory::GetForProfile(profile);
279 } 279 }
280 280
281 StartPageService::StartPageService(Profile* profile) 281 StartPageService::StartPageService(Profile* profile)
282 : profile_(profile), 282 : profile_(profile),
283 profile_destroy_observer_(new ProfileDestroyObserver(this)), 283 profile_destroy_observer_(new ProfileDestroyObserver(this)),
284 state_(app_list::SPEECH_RECOGNITION_OFF), 284 state_(app_list::SPEECH_RECOGNITION_READY),
285 speech_button_toggled_manually_(false), 285 speech_button_toggled_manually_(false),
286 speech_result_obtained_(false), 286 speech_result_obtained_(false),
287 webui_finished_loading_(false), 287 webui_finished_loading_(false),
288 speech_auth_helper_(new SpeechAuthHelper(profile, &clock_)), 288 speech_auth_helper_(new SpeechAuthHelper(profile, &clock_)),
289 network_available_(true), 289 network_available_(true),
290 microphone_available_(true), 290 microphone_available_(true),
291 search_engine_is_google_(false), 291 search_engine_is_google_(false),
292 weak_factory_(this) { 292 weak_factory_(this) {
293 // If experimental hotwording is enabled, then we're always "ready".
294 // Transitioning into the "hotword recognizing" state is handled by the
295 // hotword extension.
296 if (HotwordService::IsExperimentalHotwordingEnabled()) {
297 state_ = app_list::SPEECH_RECOGNITION_READY;
298 }
299 if (switches::IsExperimentalAppListEnabled()) { 293 if (switches::IsExperimentalAppListEnabled()) {
300 TemplateURLService* template_url_service = 294 TemplateURLService* template_url_service =
301 TemplateURLServiceFactory::GetForProfile(profile_); 295 TemplateURLServiceFactory::GetForProfile(profile_);
302 const TemplateURL* default_provider = 296 const TemplateURL* default_provider =
303 template_url_service->GetDefaultSearchProvider(); 297 template_url_service->GetDefaultSearchProvider();
304 search_engine_is_google_ = 298 search_engine_is_google_ =
305 TemplateURLPrepopulateData::GetEngineType( 299 TemplateURLPrepopulateData::GetEngineType(
306 *default_provider, template_url_service->search_terms_data()) == 300 *default_provider, template_url_service->search_terms_data()) ==
307 SEARCH_ENGINE_GOOGLE; 301 SEARCH_ENGINE_GOOGLE;
308 } 302 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 void StartPageService::AppListShown() { 360 void StartPageService::AppListShown() {
367 if (!contents_) { 361 if (!contents_) {
368 LoadContents(); 362 LoadContents();
369 } else if (contents_->IsCrashed()) { 363 } else if (contents_->IsCrashed()) {
370 LoadStartPageURL(); 364 LoadStartPageURL();
371 } else if (contents_->GetWebUI()) { 365 } else if (contents_->GetWebUI()) {
372 // If experimental hotwording is enabled, don't initialize the web speech 366 // If experimental hotwording is enabled, don't initialize the web speech
373 // API, which is not used with 367 // API, which is not used with
374 // experimental hotwording. 368 // experimental hotwording.
375 contents_->GetWebUI()->CallJavascriptFunction( 369 contents_->GetWebUI()->CallJavascriptFunction(
376 "appList.startPage.onAppListShown", 370 "appList.startPage.onAppListShown");
377 base::FundamentalValue(HotwordEnabled()),
378 base::FundamentalValue(
379 !HotwordService::IsExperimentalHotwordingEnabled()));
380 } 371 }
381 372
382 #if defined(OS_CHROMEOS) 373 #if defined(OS_CHROMEOS)
383 audio_status_.reset(new AudioStatus(this)); 374 audio_status_.reset(new AudioStatus(this));
384 #endif 375 #endif
385 } 376 }
386 377
387 void StartPageService::AppListHidden() { 378 void StartPageService::AppListHidden() {
388 if (contents_->GetWebUI()) { 379 if (contents_->GetWebUI()) {
389 contents_->GetWebUI()->CallJavascriptFunction( 380 contents_->GetWebUI()->CallJavascriptFunction(
390 "appList.startPage.onAppListHidden"); 381 "appList.startPage.onAppListHidden");
Matt Giuca 2015/03/19 00:46:05 You deleted this function; I think you have to del
Anand Mistry (off Chromium) 2015/03/19 05:09:16 Done.
391 } 382 }
392 if (!app_list::switches::IsExperimentalAppListEnabled()) 383 if (!app_list::switches::IsExperimentalAppListEnabled())
393 UnloadContents(); 384 UnloadContents();
394 385
395 if (HotwordService::IsExperimentalHotwordingEnabled() && 386 if (speech_recognizer_) {
396 speech_recognizer_) {
397 speech_recognizer_->Stop(); 387 speech_recognizer_->Stop();
398 speech_recognizer_.reset(); 388 speech_recognizer_.reset();
399 389
400 // When the SpeechRecognizer is destroyed above, we get stuck in the current 390 // When the SpeechRecognizer is destroyed above, we get stuck in the current
401 // speech state instead of being reset into the READY state. Reset the 391 // speech state instead of being reset into the READY state. Reset the
402 // speech state explicitly so that speech works when the launcher is opened 392 // speech state explicitly so that speech works when the launcher is opened
403 // again. 393 // again.
404 OnSpeechRecognitionStateChanged(SPEECH_RECOGNITION_READY); 394 OnSpeechRecognitionStateChanged(SPEECH_RECOGNITION_READY);
405 } 395 }
406 396
407 #if defined(OS_CHROMEOS) 397 #if defined(OS_CHROMEOS)
408 audio_status_.reset(); 398 audio_status_.reset();
409 #endif 399 #endif
410 } 400 }
411 401
412 void StartPageService::ToggleSpeechRecognition( 402 void StartPageService::ToggleSpeechRecognition(
413 const scoped_refptr<content::SpeechRecognitionSessionPreamble>& preamble) { 403 const scoped_refptr<content::SpeechRecognitionSessionPreamble>& preamble) {
414 DCHECK(contents_); 404 DCHECK(contents_);
415 speech_button_toggled_manually_ = true; 405 speech_button_toggled_manually_ = true;
416 406
417 // Speech recognition under V2 hotwording does not depend in any way on the 407 if (!speech_recognizer_) {
418 // start page web contents. Do this code path first to make this explicit and 408 std::string profile_locale;
419 // easier to identify what code needs to be deleted when V2 hotwording is
420 // stable.
421 if (HotwordService::IsExperimentalHotwordingEnabled()) {
422 if (!speech_recognizer_) {
423 std::string profile_locale;
424 #if defined(OS_CHROMEOS) 409 #if defined(OS_CHROMEOS)
425 profile_locale = profile_->GetPrefs()->GetString( 410 profile_locale = profile_->GetPrefs()->GetString(
426 prefs::kApplicationLocale); 411 prefs::kApplicationLocale);
427 #endif 412 #endif
428 if (profile_locale.empty()) 413 if (profile_locale.empty())
429 profile_locale = g_browser_process->GetApplicationLocale(); 414 profile_locale = g_browser_process->GetApplicationLocale();
430 415
431 speech_recognizer_.reset( 416 speech_recognizer_.reset(
432 new SpeechRecognizer(weak_factory_.GetWeakPtr(), 417 new SpeechRecognizer(weak_factory_.GetWeakPtr(),
433 profile_->GetRequestContext(), 418 profile_->GetRequestContext(),
434 profile_locale)); 419 profile_locale));
435 }
436
437 speech_recognizer_->Start(preamble);
438 return;
439 } 420 }
440 421
441 if (!contents_->GetWebUI()) 422 speech_recognizer_->Start(preamble);
442 return;
443
444 if (!webui_finished_loading_) {
445 pending_webui_callbacks_.push_back(
446 base::Bind(&StartPageService::ToggleSpeechRecognition,
447 base::Unretained(this),
448 preamble));
449 return;
450 }
451
452 contents_->GetWebUI()->CallJavascriptFunction(
453 "appList.startPage.toggleSpeechRecognition");
454 } 423 }
455 424
456 bool StartPageService::HotwordEnabled() { 425 bool StartPageService::HotwordEnabled() {
457 // Voice input for the launcher is unsupported on non-ChromeOS platforms. 426 // Voice input for the launcher is unsupported on non-ChromeOS platforms.
458 // TODO(amistry): Make speech input, and hotwording, work on non-ChromeOS. 427 // TODO(amistry): Make speech input, and hotwording, work on non-ChromeOS.
459 #if defined(OS_CHROMEOS) 428 #if defined(OS_CHROMEOS)
460 if (HotwordService::IsExperimentalHotwordingEnabled()) { 429 HotwordService* service = HotwordServiceFactory::GetForProfile(profile_);
461 HotwordService* service = HotwordServiceFactory::GetForProfile(profile_); 430 return state_ != SPEECH_RECOGNITION_OFF &&
462 return state_ != SPEECH_RECOGNITION_OFF && 431 service &&
463 service && 432 (service->IsSometimesOnEnabled() || service->IsAlwaysOnEnabled()) &&
464 (service->IsSometimesOnEnabled() || service->IsAlwaysOnEnabled()) && 433 service->IsServiceAvailable();
465 service->IsServiceAvailable();
466 }
467 return HotwordServiceFactory::IsServiceAvailable(profile_) &&
468 profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled);
469 #else 434 #else
470 return false; 435 return false;
471 #endif 436 #endif
472 } 437 }
473 438
474 content::WebContents* StartPageService::GetStartPageContents() { 439 content::WebContents* StartPageService::GetStartPageContents() {
475 return app_list::switches::IsExperimentalAppListEnabled() ? contents_.get() 440 return app_list::switches::IsExperimentalAppListEnabled() ? contents_.get()
476 : NULL; 441 : NULL;
477 } 442 }
478 443
(...skipping 29 matching lines...) Expand all
508 // Sometimes this can be called even though there are no audio input devices. 473 // Sometimes this can be called even though there are no audio input devices.
509 if (audio_status_ && !audio_status_->CanListen()) 474 if (audio_status_ && !audio_status_->CanListen())
510 new_state = SPEECH_RECOGNITION_OFF; 475 new_state = SPEECH_RECOGNITION_OFF;
511 #endif 476 #endif
512 if (!ShouldEnableSpeechRecognition()) 477 if (!ShouldEnableSpeechRecognition())
513 new_state = SPEECH_RECOGNITION_OFF; 478 new_state = SPEECH_RECOGNITION_OFF;
514 479
515 if (state_ == new_state) 480 if (state_ == new_state)
516 return; 481 return;
517 482
518 if (HotwordService::IsExperimentalHotwordingEnabled() && 483 if ((new_state == SPEECH_RECOGNITION_READY ||
519 (new_state == SPEECH_RECOGNITION_READY ||
520 new_state == SPEECH_RECOGNITION_OFF) && 484 new_state == SPEECH_RECOGNITION_OFF) &&
521 speech_recognizer_) { 485 speech_recognizer_) {
522 speech_recognizer_->Stop(); 486 speech_recognizer_->Stop();
523 } 487 }
524 488
525 if (!InSpeechRecognition(state_) && InSpeechRecognition(new_state)) { 489 if (!InSpeechRecognition(state_) && InSpeechRecognition(new_state)) {
526 if (!speech_button_toggled_manually_ && 490 if (!speech_button_toggled_manually_ &&
527 state_ == SPEECH_RECOGNITION_HOTWORD_LISTENING) { 491 state_ == SPEECH_RECOGNITION_HOTWORD_LISTENING) {
528 RecordAction(UserMetricsAction("AppList_HotwordRecognized")); 492 RecordAction(UserMetricsAction("AppList_HotwordRecognized"));
529 } else { 493 } else {
530 RecordAction(UserMetricsAction("AppList_VoiceSearchStartedManually")); 494 RecordAction(UserMetricsAction("AppList_VoiceSearchStartedManually"));
531 } 495 }
532 } else if (InSpeechRecognition(state_) && !InSpeechRecognition(new_state) && 496 } else if (InSpeechRecognition(state_) && !InSpeechRecognition(new_state) &&
533 !speech_result_obtained_) { 497 !speech_result_obtained_) {
534 RecordAction(UserMetricsAction("AppList_VoiceSearchCanceled")); 498 RecordAction(UserMetricsAction("AppList_VoiceSearchCanceled"));
535 } 499 }
536 speech_button_toggled_manually_ = false; 500 speech_button_toggled_manually_ = false;
537 speech_result_obtained_ = false; 501 speech_result_obtained_ = false;
538 state_ = new_state; 502 state_ = new_state;
539 FOR_EACH_OBSERVER(StartPageObserver, 503 FOR_EACH_OBSERVER(StartPageObserver,
540 observers_, 504 observers_,
541 OnSpeechRecognitionStateChanged(new_state)); 505 OnSpeechRecognitionStateChanged(new_state));
542 } 506 }
543 507
544 void StartPageService::GetSpeechAuthParameters(std::string* auth_scope, 508 void StartPageService::GetSpeechAuthParameters(std::string* auth_scope,
545 std::string* auth_token) { 509 std::string* auth_token) {
546 if (HotwordService::IsExperimentalHotwordingEnabled()) { 510 HotwordService* service = HotwordServiceFactory::GetForProfile(profile_);
547 HotwordService* service = HotwordServiceFactory::GetForProfile(profile_); 511 if (service &&
548 if (service && 512 service->IsOptedIntoAudioLogging() &&
549 service->IsOptedIntoAudioLogging() && 513 service->IsAlwaysOnEnabled() &&
550 service->IsAlwaysOnEnabled() && 514 !speech_auth_helper_->GetToken().empty()) {
551 !speech_auth_helper_->GetToken().empty()) { 515 *auth_scope = speech_auth_helper_->GetScope();
552 *auth_scope = speech_auth_helper_->GetScope(); 516 *auth_token = speech_auth_helper_->GetToken();
553 *auth_token = speech_auth_helper_->GetToken();
554 }
555 } 517 }
556 } 518 }
557 519
558 void StartPageService::Shutdown() { 520 void StartPageService::Shutdown() {
559 UnloadContents(); 521 UnloadContents();
560 #if defined(OS_CHROMEOS) 522 #if defined(OS_CHROMEOS)
561 audio_status_.reset(); 523 audio_status_.reset();
562 #endif 524 #endif
563 525
564 speech_auth_helper_.reset(); 526 speech_auth_helper_.reset();
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 653
692 // Check for a new doodle. 654 // Check for a new doodle.
693 content::BrowserThread::PostDelayedTask( 655 content::BrowserThread::PostDelayedTask(
694 content::BrowserThread::UI, FROM_HERE, 656 content::BrowserThread::UI, FROM_HERE,
695 base::Bind(&StartPageService::FetchDoodleJson, 657 base::Bind(&StartPageService::FetchDoodleJson,
696 weak_factory_.GetWeakPtr()), 658 weak_factory_.GetWeakPtr()),
697 recheck_delay); 659 recheck_delay);
698 } 660 }
699 661
700 } // namespace app_list 662 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698