OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 * Class to manage hotwording state. Starts/stops the hotword detector based | 9 * Class to manage hotwording state. Starts/stops the hotword detector based |
10 * on user settings, session requests, and any other factors that play into | 10 * on user settings, session requests, and any other factors that play into |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 chrome.hotwordPrivate.getStatus(this.handleStatus_.bind(this)); | 79 chrome.hotwordPrivate.getStatus(this.handleStatus_.bind(this)); |
80 }, | 80 }, |
81 | 81 |
82 /** | 82 /** |
83 * Callback for hotwordPrivate.getStatus() function. | 83 * Callback for hotwordPrivate.getStatus() function. |
84 * @param {chrome.hotwordPrivate.StatusDetails} status Current hotword | 84 * @param {chrome.hotwordPrivate.StatusDetails} status Current hotword |
85 * status. | 85 * status. |
86 * @private | 86 * @private |
87 */ | 87 */ |
88 handleStatus_: function(status) { | 88 handleStatus_: function(status) { |
| 89 hotword.debug('New hotword status', status); |
89 this.hotwordStatus_ = status; | 90 this.hotwordStatus_ = status; |
90 this.updateStateFromStatus_(); | 91 this.updateStateFromStatus_(); |
91 }, | 92 }, |
92 | 93 |
93 /** | 94 /** |
94 * Updates state based on the current status. | 95 * Updates state based on the current status. |
95 * @private | 96 * @private |
96 */ | 97 */ |
97 updateStateFromStatus_: function() { | 98 updateStateFromStatus_: function() { |
98 if (!this.hotwordStatus_) | 99 if (!this.hotwordStatus_) |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 onError_: function() { | 228 onError_: function() { |
228 this.state_ = State_.ERROR; | 229 this.state_ = State_.ERROR; |
229 this.shutdownPluginManager_(); | 230 this.shutdownPluginManager_(); |
230 }, | 231 }, |
231 | 232 |
232 /** | 233 /** |
233 * Handle hotword triggering. | 234 * Handle hotword triggering. |
234 * @private | 235 * @private |
235 */ | 236 */ |
236 onTrigger_: function() { | 237 onTrigger_: function() { |
| 238 hotword.debug('Hotword triggered!'); |
237 assert(this.pluginManager_); | 239 assert(this.pluginManager_); |
238 // Detector implicitly stops when the hotword is detected. | 240 // Detector implicitly stops when the hotword is detected. |
239 this.state_ = State_.STOPPED; | 241 this.state_ = State_.STOPPED; |
240 | 242 |
241 // Play the chime. | 243 // Play the chime. |
242 this.chime_.play(); | 244 this.chime_.play(); |
243 | 245 |
244 chrome.hotwordPrivate.notifyHotwordRecognition('search', function() {}); | 246 chrome.hotwordPrivate.notifyHotwordRecognition('search', function() {}); |
245 | 247 |
246 // Implicitly clear the session. A session needs to be started in order to | 248 // Implicitly clear the session. A session needs to be started in order to |
247 // restart the detector. | 249 // restart the detector. |
248 this.sessionSource_ = null; | 250 this.sessionSource_ = null; |
249 this.sessionStartedCb_ = null; | 251 this.sessionStartedCb_ = null; |
250 }, | 252 }, |
251 | 253 |
252 /** | 254 /** |
253 * Start a hotwording session. | 255 * Start a hotwording session. |
254 * @param {!hotword.constants.SessionSource} source Source of the hotword | 256 * @param {!hotword.constants.SessionSource} source Source of the hotword |
255 * session request. | 257 * session request. |
256 * @param {!function()} startedCb Callback invoked when the session has | 258 * @param {!function()} startedCb Callback invoked when the session has |
257 * been started successfully. | 259 * been started successfully. |
258 */ | 260 */ |
259 startSession: function(source, startedCb) { | 261 startSession: function(source, startedCb) { |
| 262 hotword.debug('Starting session for source: ' + source); |
260 this.sessionSource_ = source; | 263 this.sessionSource_ = source; |
261 this.sessionStartedCb_ = startedCb; | 264 this.sessionStartedCb_ = startedCb; |
262 this.updateStateFromStatus_(); | 265 this.updateStateFromStatus_(); |
263 }, | 266 }, |
264 | 267 |
265 /** | 268 /** |
266 * Stops a hotwording session. | 269 * Stops a hotwording session. |
267 * @param {!hotword.constants.SessionSource} source Source of the hotword | 270 * @param {!hotword.constants.SessionSource} source Source of the hotword |
268 * session request. | 271 * session request. |
269 */ | 272 */ |
270 stopSession: function(source) { | 273 stopSession: function(source) { |
| 274 hotword.debug('Stopping session for source: ' + source); |
271 this.sessionSource_ = null; | 275 this.sessionSource_ = null; |
272 this.sessionStartedCb_ = null; | 276 this.sessionStartedCb_ = null; |
273 this.updateStateFromStatus_(); | 277 this.updateStateFromStatus_(); |
274 } | 278 } |
275 }; | 279 }; |
276 | 280 |
277 return { | 281 return { |
278 StateManager: StateManager | 282 StateManager: StateManager |
279 }; | 283 }; |
280 }); | 284 }); |
OLD | NEW |