| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 cr.define('hotword', function() { | 5 cr.define('hotword', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Trivial container class for session information. | 9 * Trivial container class for session information. |
| 10 * @param {!hotword.constants.SessionSource} source Source of the hotword | 10 * @param {!hotword.constants.SessionSource} source Source of the hotword |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 StateManager.prototype = { | 133 StateManager.prototype = { |
| 134 /** | 134 /** |
| 135 * Request status details update. Intended to be called from the | 135 * Request status details update. Intended to be called from the |
| 136 * hotwordPrivate.onEnabledChanged() event. | 136 * hotwordPrivate.onEnabledChanged() event. |
| 137 */ | 137 */ |
| 138 updateStatus: function() { | 138 updateStatus: function() { |
| 139 chrome.hotwordPrivate.getStatus(this.handleStatus_.bind(this)); | 139 chrome.hotwordPrivate.getStatus(this.handleStatus_.bind(this)); |
| 140 }, | 140 }, |
| 141 | 141 |
| 142 /** | 142 /** |
| 143 * @return {boolean} True if hotwording is enabled. | 143 * @return {boolean} True if google.com/NTP/launcher hotwording is enabled. |
| 144 */ | 144 */ |
| 145 isEnabled: function() { | 145 isSometimesOnEnabled: function() { |
| 146 assert(this.hotwordStatus_, 'No hotwording status (isEnabled)'); | 146 assert(this.hotwordStatus_, |
| 147 return this.hotwordStatus_.enabled; | 147 'No hotwording status (isSometimesOnEnabled)'); |
| 148 // Although the two settings are supposed to be mutually exclusive, it's |
| 149 // possible for both to be set. In that case, always-on takes precedence. |
| 150 return this.hotwordStatus_.enabled && |
| 151 !this.hotwordStatus_.alwaysOnEnabled; |
| 148 }, | 152 }, |
| 149 | 153 |
| 150 /** | 154 /** |
| 151 * @return {boolean} True if always-on hotwording is enabled. | 155 * @return {boolean} True if always-on hotwording is enabled. |
| 152 */ | 156 */ |
| 153 isAlwaysOnEnabled: function() { | 157 isAlwaysOnEnabled: function() { |
| 154 assert(this.hotwordStatus_, 'No hotword status (isAlwaysOnEnabled)'); | 158 assert(this.hotwordStatus_, 'No hotword status (isAlwaysOnEnabled)'); |
| 155 return this.hotwordStatus_.enabled && | 159 return this.hotwordStatus_.alwaysOnEnabled; |
| 156 this.hotwordStatus_.alwaysOnEnabled; | |
| 157 }, | 160 }, |
| 158 | 161 |
| 159 /** | 162 /** |
| 160 * Callback for hotwordPrivate.getStatus() function. | 163 * Callback for hotwordPrivate.getStatus() function. |
| 161 * @param {chrome.hotwordPrivate.StatusDetails} status Current hotword | 164 * @param {chrome.hotwordPrivate.StatusDetails} status Current hotword |
| 162 * status. | 165 * status. |
| 163 * @private | 166 * @private |
| 164 */ | 167 */ |
| 165 handleStatus_: function(status) { | 168 handleStatus_: function(status) { |
| 166 hotword.debug('New hotword status', status); | 169 hotword.debug('New hotword status', status); |
| 167 this.hotwordStatus_ = status; | 170 this.hotwordStatus_ = status; |
| 168 this.updateStateFromStatus_(); | 171 this.updateStateFromStatus_(); |
| 169 | 172 |
| 170 this.onStatusChanged.dispatch(); | 173 this.onStatusChanged.dispatch(); |
| 171 }, | 174 }, |
| 172 | 175 |
| 173 /** | 176 /** |
| 174 * Updates state based on the current status. | 177 * Updates state based on the current status. |
| 175 * @private | 178 * @private |
| 176 */ | 179 */ |
| 177 updateStateFromStatus_: function() { | 180 updateStateFromStatus_: function() { |
| 178 if (!this.hotwordStatus_) | 181 if (!this.hotwordStatus_) |
| 179 return; | 182 return; |
| 180 | 183 |
| 181 if (this.hotwordStatus_.enabled) { | 184 if (this.hotwordStatus_.enabled || this.hotwordStatus_.alwaysOnEnabled) { |
| 182 // Start the detector if there's a session, and shut it down if there | 185 // Start the detector if there's a session, and shut it down if there |
| 183 // isn't. | 186 // isn't. |
| 184 // NOTE(amistry): With always-on, we want a different behaviour with | 187 // NOTE(amistry): With always-on, we want a different behaviour with |
| 185 // sessions since the detector should always be running. The exception | 188 // sessions since the detector should always be running. The exception |
| 186 // being when the user triggers by saying 'Ok Google'. In that case, the | 189 // being when the user triggers by saying 'Ok Google'. In that case, the |
| 187 // detector stops, so starting/stopping the launcher session should | 190 // detector stops, so starting/stopping the launcher session should |
| 188 // restart the detector. | 191 // restart the detector. |
| 189 if (this.sessions_.length) | 192 if (this.sessions_.length) |
| 190 this.startDetector_(); | 193 this.startDetector_(); |
| 191 else | 194 else |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 hotword.debug('Stopping session for source: ' + source); | 388 hotword.debug('Stopping session for source: ' + source); |
| 386 this.removeSession_(source); | 389 this.removeSession_(source); |
| 387 this.updateStateFromStatus_(); | 390 this.updateStateFromStatus_(); |
| 388 } | 391 } |
| 389 }; | 392 }; |
| 390 | 393 |
| 391 return { | 394 return { |
| 392 StateManager: StateManager | 395 StateManager: StateManager |
| 393 }; | 396 }; |
| 394 }); | 397 }); |
| OLD | NEW |