Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: chrome/browser/resources/hotword/state_manager.js

Issue 667873002: Add UMA to hotword trigger extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add to histograms.xml Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 * @private 95 * @private
96 */ 96 */
97 StateManager.State_ = { 97 StateManager.State_ = {
98 STOPPED: 0, 98 STOPPED: 0,
99 STARTING: 1, 99 STARTING: 1,
100 RUNNING: 2, 100 RUNNING: 2,
101 ERROR: 3, 101 ERROR: 3,
102 }; 102 };
103 var State_ = StateManager.State_; 103 var State_ = StateManager.State_;
104 104
105 var UmaMediaStreamErrors_ = {
106 // These first error are defined by the MediaStream spec:
107 // http://w3c.github.io/mediacapture-main/getusermedia.html#idl-def-MediaStr eamError
108 'NotSupportedError': hotword.constants.UmaMediaStreamError.NOT_SUPPORTED,
109 'PermissionDeniedError':
110 hotword.constants.UmaMediaStreamError.PERMISSION_DENIED,
111 'ConstraintNotSatisfiedError':
112 hotword.constants.UmaMediaStreamError.CONSTRAINT_NOT_SATISFIED,
113 'OverconstrainedError':
114 hotword.constants.UmaMediaStreamError.OVERCONSTRAINED,
115 'NotFoundError': hotword.constants.UmaMediaStreamError.NOT_FOUND,
116 'AbortError': hotword.constants.UmaMediaStreamError.ABORT,
117 'SourceUnavailableError':
118 hotword.constants.UmaMediaStreamError.SOURCE_UNAVAILABLE,
119 // The next few errors are chrome-specific. See:
120 // content/renderer/media/user_media_client_impl.cc
121 // (UserMediaClientImpl::GetUserMediaRequestFailed)
122 'PermissionDismissedError':
123 hotword.constants.UmaMediaStreamError.PERMISSION_DISMISSED,
124 'InvalidStateError':
125 hotword.constants.UmaMediaStreamError.INVALID_STATE,
126 'DevicesNotFoundError':
127 hotword.constants.UmaMediaStreamError.DEVICES_NOT_FOUND,
128 'InvalidSecurityOriginError':
129 hotword.constants.UmaMediaStreamError.INVALID_SECURITY_ORIGIN
130 };
131
105 StateManager.prototype = { 132 StateManager.prototype = {
106 /** 133 /**
107 * Request status details update. Intended to be called from the 134 * Request status details update. Intended to be called from the
108 * hotwordPrivate.onEnabledChanged() event. 135 * hotwordPrivate.onEnabledChanged() event.
109 */ 136 */
110 updateStatus: function() { 137 updateStatus: function() {
111 chrome.hotwordPrivate.getStatus(this.handleStatus_.bind(this)); 138 chrome.hotwordPrivate.getStatus(this.handleStatus_.bind(this));
112 }, 139 },
113 140
114 /** 141 /**
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 ({audio: {optional: [{googDucking: false}]}}); 225 ({audio: {optional: [{googDucking: false}]}});
199 navigator.webkitGetUserMedia( 226 navigator.webkitGetUserMedia(
200 /** @type {MediaStreamConstraints} */ (constraints), 227 /** @type {MediaStreamConstraints} */ (constraints),
201 function(stream) { 228 function(stream) {
202 if (!this.pluginManager_.initialize(naclArch, stream)) { 229 if (!this.pluginManager_.initialize(naclArch, stream)) {
203 this.state_ = State_.ERROR; 230 this.state_ = State_.ERROR;
204 this.shutdownPluginManager_(); 231 this.shutdownPluginManager_();
205 } 232 }
206 }.bind(this), 233 }.bind(this),
207 function(error) { 234 function(error) {
235 if (error.name in UmaMediaStreamErrors_) {
236 var metricValue = UmaMediaStreamErrors_[error.name];
237 } else {
238 var metricValue =
239 hotword.constants.UmaMediaStreamError.UNKNOWN;
240 }
241 hotword.metrics.recordEnum(
242 hotword.constants.UmaMetrics.MEDIA_STREAM_ERROR,
243 metricValue,
244 hotword.constants.UmaMediaStreamError.MAX);
208 this.state_ = State_.ERROR; 245 this.state_ = State_.ERROR;
209 this.pluginManager_ = null; 246 this.pluginManager_ = null;
210 }.bind(this)); 247 }.bind(this));
211 }.bind(this)); 248 }.bind(this));
212 } else if (this.state_ != State_.STARTING) { 249 } else if (this.state_ != State_.STARTING) {
213 // Don't try to start a starting detector. 250 // Don't try to start a starting detector.
214 this.startRecognizer_(); 251 this.startRecognizer_();
215 } 252 }
216 }, 253 },
217 254
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 this.state_ = State_.ERROR; 315 this.state_ = State_.ERROR;
279 this.shutdownPluginManager_(); 316 this.shutdownPluginManager_();
280 }, 317 },
281 318
282 /** 319 /**
283 * Handle hotword triggering. 320 * Handle hotword triggering.
284 * @private 321 * @private
285 */ 322 */
286 onTrigger_: function() { 323 onTrigger_: function() {
287 hotword.debug('Hotword triggered!'); 324 hotword.debug('Hotword triggered!');
325 chrome.metricsPrivate.recordUserAction(
326 hotword.constants.UmaMetrics.TRIGGER);
288 assert(this.pluginManager_, 'No NaCl plugin loaded on trigger'); 327 assert(this.pluginManager_, 'No NaCl plugin loaded on trigger');
289 // Detector implicitly stops when the hotword is detected. 328 // Detector implicitly stops when the hotword is detected.
290 this.state_ = State_.STOPPED; 329 this.state_ = State_.STOPPED;
291 330
292 // Play the chime. 331 // Play the chime.
293 this.chime_.play(); 332 this.chime_.play();
294 333
295 // Implicitly clear the top session. A session needs to be started in 334 // Implicitly clear the top session. A session needs to be started in
296 // order to restart the detector. 335 // order to restart the detector.
297 if (this.sessions_.length) { 336 if (this.sessions_.length) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 hotword.debug('Stopping session for source: ' + source); 380 hotword.debug('Stopping session for source: ' + source);
342 this.removeSession_(source); 381 this.removeSession_(source);
343 this.updateStateFromStatus_(); 382 this.updateStateFromStatus_();
344 } 383 }
345 }; 384 };
346 385
347 return { 386 return {
348 StateManager: StateManager 387 StateManager: StateManager
349 }; 388 };
350 }); 389 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698