Chromium Code Reviews| 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/search/hotword_service.h" | 5 #include "chrome/browser/search/hotword_service.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/i18n/case_conversion.h" | 8 #include "base/i18n/case_conversion.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 ExtensionService* extension_service) { | 445 ExtensionService* extension_service) { |
| 446 if (extension_service) { | 446 if (extension_service) { |
| 447 extension_service->DisableExtension( | 447 extension_service->DisableExtension( |
| 448 extension_misc::kHotwordExtensionId, | 448 extension_misc::kHotwordExtensionId, |
| 449 extensions::Extension::DISABLE_USER_ACTION); | 449 extensions::Extension::DISABLE_USER_ACTION); |
| 450 } | 450 } |
| 451 } | 451 } |
| 452 | 452 |
| 453 void HotwordService::OnHotwordAlwaysOnSearchEnabledChanged( | 453 void HotwordService::OnHotwordAlwaysOnSearchEnabledChanged( |
| 454 const std::string& pref_name) { | 454 const std::string& pref_name) { |
| 455 DCHECK_EQ(pref_name, std::string(prefs::kHotwordAlwaysOnSearchEnabled)); | 455 DCHECK_EQ(pref_name, std::string(prefs::kHotwordAlwaysOnSearchEnabled)); |
|
benwells
2014/09/09 20:57:30
The indenting was correct before.
kcarattini
2014/09/10 08:14:28
Done.
| |
| 456 | 456 |
| 457 ExtensionService* extension_service = GetExtensionService(profile_); | 457 ExtensionService* extension_service = GetExtensionService(profile_); |
| 458 if (!extension_service) | 458 if (!extension_service) |
| 459 return; | 459 return; |
| 460 | 460 |
| 461 const extensions::Extension* extension = extension_service->GetExtensionById( | 461 const extensions::Extension* extension = extension_service->GetExtensionById( |
| 462 extension_misc::kHotwordAudioVerificationAppId, true); | 462 extension_misc::kHotwordAudioVerificationAppId, true); |
| 463 if (!extension) | 463 if (!extension) |
| 464 return; | 464 return; |
| 465 | 465 |
| 466 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled)) { | 466 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled)) { |
| 467 // TODO(kcarattini): Check if the app is already running. If so, bring it | |
|
benwells
2014/09/09 20:57:31
This TODO is valid but should be in the app itself
kcarattini
2014/09/10 08:14:28
Done.
| |
| 468 // to focus rather than launching it. | |
| 469 SetHotwordAudioVerificationLaunchState(pref_name); | |
| 467 OpenApplication(AppLaunchParams( | 470 OpenApplication(AppLaunchParams( |
| 468 profile_, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW)); | 471 profile_, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW)); |
| 469 } | 472 } |
| 470 } | 473 } |
| 471 | 474 |
| 475 void HotwordService::SetHotwordAudioVerificationLaunchState( | |
| 476 const std::string& pref_name) { | |
| 477 if (pref_name == std::string(prefs::kHotwordAlwaysOnSearchEnabled)) { | |
| 478 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordAudioLoggingEnabled)) { | |
| 479 hotword_audio_verification_launch_state_ = HOTWORD_ONLY; | |
| 480 } else { | |
| 481 hotword_audio_verification_launch_state_ = HOTWORD_AND_AUDIO_HISTORY; | |
| 482 } | |
| 483 } else if (pref_name == std::string(prefs::kHotwordAudioLoggingEnabled)){ | |
|
rpetterson
2014/09/09 20:07:32
Does this function (SetHotwordAudioVerificationLau
benwells
2014/09/09 20:57:31
I think it would be clearer if this function didn'
kcarattini
2014/09/10 08:14:28
Yes, it will be called when the user retrains the
kcarattini
2014/09/10 08:14:28
Refactored this. Please let me know if it makes mo
| |
| 484 hotword_audio_verification_launch_state_ = AUDIO_HISTORY_ONLY; | |
| 485 } | |
| 486 } | |
| 487 | |
| 488 HotwordService::LaunchMode | |
| 489 HotwordService::GetHotwordAudioVerificationLaunchState() { | |
| 490 return hotword_audio_verification_launch_state_; | |
| 491 } | |
| 492 | |
| 472 void HotwordService::OnHotwordSearchEnabledChanged( | 493 void HotwordService::OnHotwordSearchEnabledChanged( |
| 473 const std::string& pref_name) { | 494 const std::string& pref_name) { |
| 474 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled)); | 495 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled)); |
| 475 | 496 |
| 476 ExtensionService* extension_service = GetExtensionService(profile_); | 497 ExtensionService* extension_service = GetExtensionService(profile_); |
| 477 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled)) | 498 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled)) |
| 478 EnableHotwordExtension(extension_service); | 499 EnableHotwordExtension(extension_service); |
| 479 else | 500 else |
| 480 DisableHotwordExtension(extension_service); | 501 DisableHotwordExtension(extension_service); |
| 481 } | 502 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 return false; | 538 return false; |
| 518 | 539 |
| 519 std::string previous_locale = | 540 std::string previous_locale = |
| 520 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage); | 541 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage); |
| 521 std::string locale = GetCurrentLocale(profile_); | 542 std::string locale = GetCurrentLocale(profile_); |
| 522 | 543 |
| 523 // If it's a new locale, then the old extension should be uninstalled. | 544 // If it's a new locale, then the old extension should be uninstalled. |
| 524 return locale != previous_locale && | 545 return locale != previous_locale && |
| 525 HotwordService::DoesHotwordSupportLanguage(profile_); | 546 HotwordService::DoesHotwordSupportLanguage(profile_); |
| 526 } | 547 } |
| OLD | NEW |