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