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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 : profile_(profile), | 187 : profile_(profile), |
188 extension_registry_observer_(this), | 188 extension_registry_observer_(this), |
189 client_(NULL), | 189 client_(NULL), |
190 error_message_(0), | 190 error_message_(0), |
191 reinstall_pending_(false), | 191 reinstall_pending_(false), |
192 weak_factory_(this) { | 192 weak_factory_(this) { |
193 extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile)); | 193 extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile)); |
194 // This will be called during profile initialization which is a good time | 194 // This will be called during profile initialization which is a good time |
195 // to check the user's hotword state. | 195 // to check the user's hotword state. |
196 HotwordEnabled enabled_state = UNSET; | 196 HotwordEnabled enabled_state = UNSET; |
197 if (profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled)) { | 197 if (IsExperimentalHotwordingEnabled()) { |
198 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled)) | 198 // Disable the old extension so it doesn't interfere with the new stuff. |
199 enabled_state = ENABLED; | 199 DisableHotwordExtension(GetExtensionService(profile_)); |
200 else | |
201 enabled_state = DISABLED; | |
202 } else { | 200 } else { |
203 // If the preference has not been set the hotword extension should | 201 if (profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled)) { |
204 // not be running. However, this should only be done if auto-install | 202 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled)) |
205 // is enabled which is gated through the IsHotwordAllowed check. | 203 enabled_state = ENABLED; |
206 if (IsHotwordAllowed()) | 204 else |
207 DisableHotwordExtension(GetExtensionService(profile_)); | 205 enabled_state = DISABLED; |
| 206 } else { |
| 207 // If the preference has not been set the hotword extension should |
| 208 // not be running. However, this should only be done if auto-install |
| 209 // is enabled which is gated through the IsHotwordAllowed check. |
| 210 if (IsHotwordAllowed()) |
| 211 DisableHotwordExtension(GetExtensionService(profile_)); |
| 212 } |
208 } | 213 } |
209 UMA_HISTOGRAM_ENUMERATION("Hotword.Enabled", enabled_state, | 214 UMA_HISTOGRAM_ENUMERATION("Hotword.Enabled", enabled_state, |
210 NUM_HOTWORD_ENABLED_METRICS); | 215 NUM_HOTWORD_ENABLED_METRICS); |
211 | 216 |
212 pref_registrar_.Init(profile_->GetPrefs()); | 217 pref_registrar_.Init(profile_->GetPrefs()); |
213 pref_registrar_.Add( | 218 pref_registrar_.Add( |
214 prefs::kHotwordSearchEnabled, | 219 prefs::kHotwordSearchEnabled, |
215 base::Bind(&HotwordService::OnHotwordSearchEnabledChanged, | 220 base::Bind(&HotwordService::OnHotwordSearchEnabledChanged, |
216 base::Unretained(this))); | 221 base::Unretained(this))); |
217 | 222 |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 } | 446 } |
442 | 447 |
443 bool HotwordService::IsAlwaysOnEnabled() { | 448 bool HotwordService::IsAlwaysOnEnabled() { |
444 return | 449 return |
445 profile_->GetPrefs()->HasPrefPath(prefs::kHotwordAlwaysOnSearchEnabled) && | 450 profile_->GetPrefs()->HasPrefPath(prefs::kHotwordAlwaysOnSearchEnabled) && |
446 profile_->GetPrefs()->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled); | 451 profile_->GetPrefs()->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled); |
447 } | 452 } |
448 | 453 |
449 void HotwordService::EnableHotwordExtension( | 454 void HotwordService::EnableHotwordExtension( |
450 ExtensionService* extension_service) { | 455 ExtensionService* extension_service) { |
451 if (extension_service) | 456 if (extension_service && !IsExperimentalHotwordingEnabled()) |
452 extension_service->EnableExtension(extension_misc::kHotwordExtensionId); | 457 extension_service->EnableExtension(extension_misc::kHotwordExtensionId); |
453 } | 458 } |
454 | 459 |
455 void HotwordService::DisableHotwordExtension( | 460 void HotwordService::DisableHotwordExtension( |
456 ExtensionService* extension_service) { | 461 ExtensionService* extension_service) { |
457 if (extension_service) { | 462 if (extension_service) { |
458 extension_service->DisableExtension( | 463 extension_service->DisableExtension( |
459 extension_misc::kHotwordExtensionId, | 464 extension_misc::kHotwordExtensionId, |
460 extensions::Extension::DISABLE_USER_ACTION); | 465 extensions::Extension::DISABLE_USER_ACTION); |
461 } | 466 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 return false; | 538 return false; |
534 | 539 |
535 std::string previous_locale = | 540 std::string previous_locale = |
536 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage); | 541 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage); |
537 std::string locale = GetCurrentLocale(profile_); | 542 std::string locale = GetCurrentLocale(profile_); |
538 | 543 |
539 // 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. |
540 return locale != previous_locale && | 545 return locale != previous_locale && |
541 HotwordService::DoesHotwordSupportLanguage(profile_); | 546 HotwordService::DoesHotwordSupportLanguage(profile_); |
542 } | 547 } |
OLD | NEW |