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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 } | 208 } |
209 UMA_HISTOGRAM_ENUMERATION("Hotword.Enabled", enabled_state, | 209 UMA_HISTOGRAM_ENUMERATION("Hotword.Enabled", enabled_state, |
210 NUM_HOTWORD_ENABLED_METRICS); | 210 NUM_HOTWORD_ENABLED_METRICS); |
211 | 211 |
212 pref_registrar_.Init(profile_->GetPrefs()); | 212 pref_registrar_.Init(profile_->GetPrefs()); |
213 pref_registrar_.Add( | 213 pref_registrar_.Add( |
214 prefs::kHotwordSearchEnabled, | 214 prefs::kHotwordSearchEnabled, |
215 base::Bind(&HotwordService::OnHotwordSearchEnabledChanged, | 215 base::Bind(&HotwordService::OnHotwordSearchEnabledChanged, |
216 base::Unretained(this))); | 216 base::Unretained(this))); |
217 | 217 |
218 // TODO(kcarattini): Control the enabling of the pref with the Hotword | |
219 // Audio Verification app, rather than listening for a change in the | |
220 // enabled state. | |
221 pref_registrar_.Add( | |
222 prefs::kHotwordAlwaysOnSearchEnabled, | |
223 base::Bind(&HotwordService::OnHotwordAlwaysOnSearchEnabledChanged, | |
224 base::Unretained(this))); | |
225 | |
226 registrar_.Add(this, | 218 registrar_.Add(this, |
227 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 219 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
228 content::NotificationService::AllSources()); | 220 content::NotificationService::AllSources()); |
229 | 221 |
230 extensions::ExtensionSystem::Get(profile_)->ready().Post( | 222 extensions::ExtensionSystem::Get(profile_)->ready().Post( |
231 FROM_HERE, | 223 FROM_HERE, |
232 base::Bind(base::IgnoreResult( | 224 base::Bind(base::IgnoreResult( |
233 &HotwordService::MaybeReinstallHotwordExtension), | 225 &HotwordService::MaybeReinstallHotwordExtension), |
234 weak_factory_.GetWeakPtr())); | 226 weak_factory_.GetWeakPtr())); |
235 | 227 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 | 438 |
447 void HotwordService::DisableHotwordExtension( | 439 void HotwordService::DisableHotwordExtension( |
448 ExtensionService* extension_service) { | 440 ExtensionService* extension_service) { |
449 if (extension_service) { | 441 if (extension_service) { |
450 extension_service->DisableExtension( | 442 extension_service->DisableExtension( |
451 extension_misc::kHotwordExtensionId, | 443 extension_misc::kHotwordExtensionId, |
452 extensions::Extension::DISABLE_USER_ACTION); | 444 extensions::Extension::DISABLE_USER_ACTION); |
453 } | 445 } |
454 } | 446 } |
455 | 447 |
456 void HotwordService::OnHotwordAlwaysOnSearchEnabledChanged( | |
457 const std::string& pref_name) { | |
458 DCHECK_EQ(pref_name, std::string(prefs::kHotwordAlwaysOnSearchEnabled)); | |
459 // TODO(kcarattini): Launch in the appropriate mode given the state of | |
460 // the account-level Audio History setting. | |
461 LaunchHotwordAudioVerificationApp(HOTWORD_AND_AUDIO_HISTORY); | |
462 } | |
463 | |
464 void HotwordService::LaunchHotwordAudioVerificationApp( | 448 void HotwordService::LaunchHotwordAudioVerificationApp( |
465 const LaunchMode& launch_mode) { | 449 const LaunchMode& launch_mode) { |
466 hotword_audio_verification_launch_mode_ = launch_mode; | 450 hotword_audio_verification_launch_mode_ = launch_mode; |
467 | 451 |
468 ExtensionService* extension_service = GetExtensionService(profile_); | 452 ExtensionService* extension_service = GetExtensionService(profile_); |
469 if (!extension_service) | 453 if (!extension_service) |
470 return; | 454 return; |
471 const extensions::Extension* extension = extension_service->GetExtensionById( | 455 const extensions::Extension* extension = extension_service->GetExtensionById( |
472 extension_misc::kHotwordAudioVerificationAppId, true); | 456 extension_misc::kHotwordAudioVerificationAppId, true); |
473 if (!extension) | 457 if (!extension) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 return false; | 514 return false; |
531 | 515 |
532 std::string previous_locale = | 516 std::string previous_locale = |
533 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage); | 517 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage); |
534 std::string locale = GetCurrentLocale(profile_); | 518 std::string locale = GetCurrentLocale(profile_); |
535 | 519 |
536 // If it's a new locale, then the old extension should be uninstalled. | 520 // If it's a new locale, then the old extension should be uninstalled. |
537 return locale != previous_locale && | 521 return locale != previous_locale && |
538 HotwordService::DoesHotwordSupportLanguage(profile_); | 522 HotwordService::DoesHotwordSupportLanguage(profile_); |
539 } | 523 } |
OLD | NEW |