Chromium Code Reviews| 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 /** | 150 /** |
| 151 * @return {boolean} True if always-on hotwording is enabled. | 151 * @return {boolean} True if always-on hotwording is enabled. |
| 152 */ | 152 */ |
| 153 isAlwaysOnEnabled: function() { | 153 isAlwaysOnEnabled: function() { |
| 154 assert(this.hotwordStatus_, 'No hotword status (isAlwaysOnEnabled)'); | 154 assert(this.hotwordStatus_, 'No hotword status (isAlwaysOnEnabled)'); |
| 155 return this.hotwordStatus_.enabled && | 155 return this.hotwordStatus_.enabled && |
| 156 this.hotwordStatus_.alwaysOnEnabled; | 156 this.hotwordStatus_.alwaysOnEnabled; |
| 157 }, | 157 }, |
| 158 | 158 |
| 159 /** | 159 /** |
| 160 * @return {boolean} True if training is enabled. | |
| 161 */ | |
| 162 isTrainingEnabled: function() { | |
| 163 assert(this.hotwordStatus_, 'No hotword status (isAlwaysOnEnabled)'); | |
|
Anand Mistry (off Chromium)
2014/10/30 03:53:12
isAlwaysOnEnabled?
kcarattini
2014/10/30 05:27:06
Done.
| |
| 164 return this.hotwordStatus_.trainingEnabled; | |
| 165 }, | |
| 166 | |
| 167 /** | |
| 160 * Callback for hotwordPrivate.getStatus() function. | 168 * Callback for hotwordPrivate.getStatus() function. |
| 161 * @param {chrome.hotwordPrivate.StatusDetails} status Current hotword | 169 * @param {chrome.hotwordPrivate.StatusDetails} status Current hotword |
| 162 * status. | 170 * status. |
| 163 * @private | 171 * @private |
| 164 */ | 172 */ |
| 165 handleStatus_: function(status) { | 173 handleStatus_: function(status) { |
| 166 hotword.debug('New hotword status', status); | 174 hotword.debug('New hotword status', status); |
| 167 this.hotwordStatus_ = status; | 175 this.hotwordStatus_ = status; |
| 168 this.updateStateFromStatus_(); | 176 this.updateStateFromStatus_(); |
| 169 | 177 |
| 170 this.onStatusChanged.dispatch(); | 178 this.onStatusChanged.dispatch(); |
| 171 }, | 179 }, |
| 172 | 180 |
| 173 /** | 181 /** |
| 174 * Updates state based on the current status. | 182 * Updates state based on the current status. |
| 175 * @private | 183 * @private |
| 176 */ | 184 */ |
| 177 updateStateFromStatus_: function() { | 185 updateStateFromStatus_: function() { |
| 178 if (!this.hotwordStatus_) | 186 if (!this.hotwordStatus_) |
| 179 return; | 187 return; |
| 180 | 188 |
| 181 if (this.hotwordStatus_.enabled) { | 189 if (this.hotwordStatus_.enabled || this.hotwordStatus_.trainingEnabled) { |
| 182 // Start the detector if there's a session, and shut it down if there | 190 // Start the detector if there's a session, and shut it down if there |
| 183 // isn't. | 191 // isn't. |
| 184 // NOTE(amistry): With always-on, we want a different behaviour with | 192 // NOTE(amistry): With always-on, we want a different behaviour with |
| 185 // sessions since the detector should always be running. The exception | 193 // sessions since the detector should always be running. The exception |
| 186 // being when the user triggers by saying 'Ok Google'. In that case, the | 194 // being when the user triggers by saying 'Ok Google'. In that case, the |
| 187 // detector stops, so starting/stopping the launcher session should | 195 // detector stops, so starting/stopping the launcher session should |
| 188 // restart the detector. | 196 // restart the detector. |
| 189 if (this.sessions_.length) | 197 if (this.sessions_.length) |
| 190 this.startDetector_(); | 198 this.startDetector_(); |
| 191 else | 199 else |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 hotword.debug('Stopping session for source: ' + source); | 393 hotword.debug('Stopping session for source: ' + source); |
| 386 this.removeSession_(source); | 394 this.removeSession_(source); |
| 387 this.updateStateFromStatus_(); | 395 this.updateStateFromStatus_(); |
| 388 } | 396 } |
| 389 }; | 397 }; |
| 390 | 398 |
| 391 return { | 399 return { |
| 392 StateManager: StateManager | 400 StateManager: StateManager |
| 393 }; | 401 }; |
| 394 }); | 402 }); |
| OLD | NEW |