-// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* NaCl plugin element on extension background page.
- * @private {?Nacl}
+ * @private {?HTMLEmbedElement}
*/
this.plugin_ = null;
};
var ManagerState_ = NaClManager.ManagerState_;
var Error_ = hotword.constants.Error;
+var UmaNaClMessageTimeout_ = hotword.constants.UmaNaClMessageTimeout;
+var UmaNaClPluginLoadResult_ = hotword.constants.UmaNaClPluginLoadResult;
NaClManager.prototype.__proto__ = cr.EventTarget.prototype;
* @private
*/
NaClManager.prototype.handleError_ = function(error) {
- event = new Event(hotword.constants.Event.ERROR);
+ var event = new Event(hotword.constants.Event.ERROR);
event.data = error;
this.dispatchEvent(event);
};
/**
+ * Record the result of loading the NaCl plugin to UMA.
+ * @param {!hotword.constants.UmaNaClPluginLoadResult} error
+ * @private
+ */
+NaClManager.prototype.logPluginLoadResult_ = function(error) {
+ hotword.metrics.recordEnum(
+ hotword.constants.UmaMetrics.NACL_PLUGIN_LOAD_RESULT,
+ error,
+ UmaNaClPluginLoadResult_.MAX);
+};
+
+/**
* @return {boolean} True if the recognizer is in a running state.
*/
NaClManager.prototype.isRunning = function() {
* @private
*/
NaClManager.prototype.setTimeout_ = function(func, timeout) {
- assert(!this.naclTimeoutId_);
+ assert(!this.naclTimeoutId_, 'Timeout already exists');
this.naclTimeoutId_ = window.setTimeout(
function() {
this.naclTimeoutId_ = null;
/**
* Creates a NaCl plugin object and attaches it to the page.
* @param {!string} src Location of the plugin.
- * @return {!Nacl} NaCl plugin DOM object.
+ * @return {!HTMLEmbedElement} NaCl plugin DOM object.
* @private
*/
NaClManager.prototype.createPlugin_ = function(src) {
- var plugin = document.createElement('embed');
+ var plugin = /** @type {HTMLEmbedElement} */(document.createElement('embed'));
plugin.src = src;
plugin.type = 'application/x-nacl';
document.body.appendChild(plugin);
* @return {boolean} True if the successful.
*/
NaClManager.prototype.initialize = function(naclArch, stream) {
- assert(this.recognizerState_ == ManagerState_.UNINITIALIZED);
+ assert(this.recognizerState_ == ManagerState_.UNINITIALIZED,
+ 'Recognizer not in uninitialized state. State: ' +
+ this.recognizerState_);
var langs = this.getPossibleLanguages_();
var i, j;
// For country-lang variations. For example, when combined with path it will
}
var plugin = this.createPlugin_(pluginSrc);
- this.plugin_ = /** @type {Nacl} */ (plugin);
+ this.plugin_ = plugin;
if (!this.plugin_ || !this.plugin_.postMessage) {
document.body.removeChild(this.plugin_);
this.recognizerState_ = ManagerState_.ERROR;
false);
plugin.addEventListener('crash',
- this.handleError_.bind(this, Error_.NACL_CRASH),
+ function() {
+ this.handleError_(Error_.NACL_CRASH);
+ this.logPluginLoadResult_(
+ UmaNaClPluginLoadResult_.CRASH);
+ }.bind(this),
false);
return true;
}
this.recognizerState_ = ManagerState_.ERROR;
+ this.logPluginLoadResult_(UmaNaClPluginLoadResult_.NO_MODULE_FOUND);
return false;
};
/**
* Sends data to the NaCl plugin.
- * @param {!string} data Command to be sent to NaCl plugin.
+ * @param {!string|!MediaStreamTrack} data Command to be sent to NaCl plugin.
* @private
*/
NaClManager.prototype.sendDataToPlugin_ = function(data) {
- assert(this.recognizerState_ != ManagerState_.UNINITIALIZED);
+ assert(this.recognizerState_ != ManagerState_.UNINITIALIZED,
+ 'Recognizer in uninitialized state');
this.plugin_.postMessage(data);
};
function() {
this.recognizerState_ = ManagerState_.ERROR;
this.handleError_(Error_.TIMEOUT);
+ switch (this.expectingMessage_) {
+ case hotword.constants.NaClPlugin.REQUEST_MODEL:
+ var metricValue = UmaNaClMessageTimeout_.REQUEST_MODEL;
+ break;
+ case hotword.constants.NaClPlugin.MODEL_LOADED:
+ var metricValue = UmaNaClMessageTimeout_.MODEL_LOADED;
+ break;
+ case hotword.constants.NaClPlugin.READY_FOR_AUDIO:
+ var metricValue = UmaNaClMessageTimeout_.READY_FOR_AUDIO;
+ break;
+ case hotword.constants.NaClPlugin.STOPPED:
+ var metricValue = UmaNaClMessageTimeout_.STOPPED;
+ break;
+ case hotword.constants.NaClPlugin.HOTWORD_DETECTED:
+ var metricValue = UmaNaClMessageTimeout_.HOTWORD_DETECTED;
+ break;
+ case hotword.constants.NaClPlugin.MS_CONFIGURED:
+ var metricValue = UmaNaClMessageTimeout_.MS_CONFIGURED;
+ break;
+ }
+ hotword.metrics.recordEnum(
+ hotword.constants.UmaMetrics.NACL_MESSAGE_TIMEOUT,
+ metricValue,
+ UmaNaClMessageTimeout_.MAX);
}.bind(this), timeout);
this.expectingMessage_ = message;
};
if (this.recognizerState_ != ManagerState_.LOADING) {
return;
}
+ this.logPluginLoadResult_(UmaNaClPluginLoadResult_.SUCCESS);
this.sendDataToPlugin_(
hotword.constants.NaClPlugin.MODEL_PREFIX + this.modelUrl_);
this.waitForMessage_(hotword.constants.TimeoutMs.LONG,