Commit c82af941 authored by amistry's avatar amistry Committed by Commit bot

Treat regular and always-on hotwording settings as mutually exclusive.

Only one should be set, so update functions to reflect this. In the rare
case both are set, always-on takes precedence.

BUG=397019

Review URL: https://codereview.chromium.org/685053002

Cr-Commit-Position: refs/heads/master@{#302382}
parent 5fb6274c
...@@ -23,8 +23,7 @@ cr.define('hotword', function() { ...@@ -23,8 +23,7 @@ cr.define('hotword', function() {
/** @override */ /** @override */
enabled: function() { enabled: function() {
return this.stateManager.isEnabled() && return this.stateManager.isSometimesOnEnabled();
!this.stateManager.isAlwaysOnEnabled();
}, },
/** @override */ /** @override */
......
...@@ -431,9 +431,7 @@ cr.define('hotword', function() { ...@@ -431,9 +431,7 @@ cr.define('hotword', function() {
* @private * @private
*/ */
updateListeners_: function() { updateListeners_: function() {
var enabled = this.stateManager_.isEnabled() && if (this.stateManager_.isSometimesOnEnabled()) {
!this.stateManager_.isAlwaysOnEnabled();
if (enabled) {
this.setupListeners_(); this.setupListeners_();
} else { } else {
this.removeListeners_(); this.removeListeners_();
......
...@@ -140,11 +140,15 @@ cr.define('hotword', function() { ...@@ -140,11 +140,15 @@ cr.define('hotword', function() {
}, },
/** /**
* @return {boolean} True if hotwording is enabled. * @return {boolean} True if google.com/NTP/launcher hotwording is enabled.
*/ */
isEnabled: function() { isSometimesOnEnabled: function() {
assert(this.hotwordStatus_, 'No hotwording status (isEnabled)'); assert(this.hotwordStatus_,
return this.hotwordStatus_.enabled; 'No hotwording status (isSometimesOnEnabled)');
// Although the two settings are supposed to be mutually exclusive, it's
// possible for both to be set. In that case, always-on takes precedence.
return this.hotwordStatus_.enabled &&
!this.hotwordStatus_.alwaysOnEnabled;
}, },
/** /**
...@@ -152,8 +156,7 @@ cr.define('hotword', function() { ...@@ -152,8 +156,7 @@ cr.define('hotword', function() {
*/ */
isAlwaysOnEnabled: function() { isAlwaysOnEnabled: function() {
assert(this.hotwordStatus_, 'No hotword status (isAlwaysOnEnabled)'); assert(this.hotwordStatus_, 'No hotword status (isAlwaysOnEnabled)');
return this.hotwordStatus_.enabled && return this.hotwordStatus_.alwaysOnEnabled;
this.hotwordStatus_.alwaysOnEnabled;
}, },
/** /**
...@@ -178,7 +181,7 @@ cr.define('hotword', function() { ...@@ -178,7 +181,7 @@ cr.define('hotword', function() {
if (!this.hotwordStatus_) if (!this.hotwordStatus_)
return; return;
if (this.hotwordStatus_.enabled) { if (this.hotwordStatus_.enabled || this.hotwordStatus_.alwaysOnEnabled) {
// Start the detector if there's a session, and shut it down if there // Start the detector if there's a session, and shut it down if there
// isn't. // isn't.
// NOTE(amistry): With always-on, we want a different behaviour with // NOTE(amistry): With always-on, we want a different behaviour with
......
...@@ -174,8 +174,10 @@ void StartPageService::ToggleSpeechRecognition() { ...@@ -174,8 +174,10 @@ void StartPageService::ToggleSpeechRecognition() {
bool StartPageService::HotwordEnabled() { bool StartPageService::HotwordEnabled() {
if (HotwordService::IsExperimentalHotwordingEnabled()) { if (HotwordService::IsExperimentalHotwordingEnabled()) {
auto prefs = profile_->GetPrefs();
return HotwordServiceFactory::IsServiceAvailable(profile_) && return HotwordServiceFactory::IsServiceAvailable(profile_) &&
profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled); (prefs->GetBoolean(prefs::kHotwordSearchEnabled) ||
prefs->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled));
} }
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
return HotwordServiceFactory::IsServiceAvailable(profile_) && return HotwordServiceFactory::IsServiceAvailable(profile_) &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment