Commit 31eb3276 authored by amistry's avatar amistry Committed by Commit bot

Add a trivial logging wrapper around console.log, and add some useful log

messages.

BUG=397019

Review URL: https://codereview.chromium.org/601123002

Cr-Commit-Position: refs/heads/master@{#297366}
parent 142d2bdb
...@@ -85,6 +85,7 @@ ...@@ -85,6 +85,7 @@
<!-- (Experimental) hotword triggering extension --> <!-- (Experimental) hotword triggering extension -->
<include name="IDR_HOTWORD_CONSTANTS_JS" file="hotword/constants.js" type="BINDATA" /> <include name="IDR_HOTWORD_CONSTANTS_JS" file="hotword/constants.js" type="BINDATA" />
<include name="IDR_HOTWORD_LOGGING_JS" file="hotword/logging.js" type="BINDATA" />
<include name="IDR_HOTWORD_MANAGER_JS" file="hotword/manager.js" type="BINDATA" /> <include name="IDR_HOTWORD_MANAGER_JS" file="hotword/manager.js" type="BINDATA" />
<include name="IDR_HOTWORD_NACL_MANAGER_JS" file="hotword/nacl_manager.js" type="BINDATA" /> <include name="IDR_HOTWORD_NACL_MANAGER_JS" file="hotword/nacl_manager.js" type="BINDATA" />
<include name="IDR_HOTWORD_STATE_MANAGER_JS" file="hotword/state_manager.js" type="BINDATA" /> <include name="IDR_HOTWORD_STATE_MANAGER_JS" file="hotword/state_manager.js" type="BINDATA" />
......
// 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.
cr.define('hotword', function() {
'use strict';
/**
* Wrapper around console.log allowing debug log message to be enabled during
* development.
*/
function debug() {
if (hotword.DEBUG || window.localStorage['hotword.DEBUG'])
console.log.apply(console, arguments);
}
return {
DEBUG: false,
debug: debug
};
});
...@@ -33,12 +33,15 @@ ...@@ -33,12 +33,15 @@
// Detect when the shared module containing the NaCL module and language model // Detect when the shared module containing the NaCL module and language model
// is installed. // is installed.
chrome.management.onInstalled.addListener(function(info) { chrome.management.onInstalled.addListener(function(info) {
if (info.id == hotword.constants.SHARED_MODULE_ID) if (info.id == hotword.constants.SHARED_MODULE_ID) {
hotword.debug('Shared module installed, reloading extension.');
chrome.runtime.reload(); chrome.runtime.reload();
}
}); });
// Detect when a session has requested to be started and stopped. // Detect when a session has requested to be started and stopped.
chrome.hotwordPrivate.onHotwordSessionRequested.addListener(function() { chrome.hotwordPrivate.onHotwordSessionRequested.addListener(function() {
hotword.debug('hotwordPrivate.onHotwordSessionRequested');
// TODO(amistry): This event should change state depending on whether the // TODO(amistry): This event should change state depending on whether the
// user has enabled always-on hotwording. But for now, always signal the // user has enabled always-on hotwording. But for now, always signal the
// start of a hotwording session. This allows this extension to work with // start of a hotwording session. This allows this extension to work with
...@@ -51,6 +54,7 @@ ...@@ -51,6 +54,7 @@
}); });
chrome.hotwordPrivate.onHotwordSessionStopped.addListener(function() { chrome.hotwordPrivate.onHotwordSessionStopped.addListener(function() {
hotword.debug('hotwordPrivate.onHotwordSessionStopped');
stateManager.stopSession(hotword.constants.SessionSource.LAUNCHER); stateManager.stopSession(hotword.constants.SessionSource.LAUNCHER);
chrome.hotwordPrivate.setHotwordSessionState(false, function() {}); chrome.hotwordPrivate.setHotwordSessionState(false, function() {});
}); });
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
"chrome://resources/js/util.js", "chrome://resources/js/util.js",
"chrome://resources/js/cr/event_target.js", "chrome://resources/js/cr/event_target.js",
"constants.js", "constants.js",
"logging.js",
"nacl_manager.js", "nacl_manager.js",
"state_manager.js", "state_manager.js",
"manager.js" "manager.js"
......
...@@ -86,6 +86,7 @@ cr.define('hotword', function() { ...@@ -86,6 +86,7 @@ cr.define('hotword', function() {
* @private * @private
*/ */
handleStatus_: function(status) { handleStatus_: function(status) {
hotword.debug('New hotword status', status);
this.hotwordStatus_ = status; this.hotwordStatus_ = status;
this.updateStateFromStatus_(); this.updateStateFromStatus_();
}, },
...@@ -234,6 +235,7 @@ cr.define('hotword', function() { ...@@ -234,6 +235,7 @@ cr.define('hotword', function() {
* @private * @private
*/ */
onTrigger_: function() { onTrigger_: function() {
hotword.debug('Hotword triggered!');
assert(this.pluginManager_); assert(this.pluginManager_);
// Detector implicitly stops when the hotword is detected. // Detector implicitly stops when the hotword is detected.
this.state_ = State_.STOPPED; this.state_ = State_.STOPPED;
...@@ -257,6 +259,7 @@ cr.define('hotword', function() { ...@@ -257,6 +259,7 @@ cr.define('hotword', function() {
* been started successfully. * been started successfully.
*/ */
startSession: function(source, startedCb) { startSession: function(source, startedCb) {
hotword.debug('Starting session for source: ' + source);
this.sessionSource_ = source; this.sessionSource_ = source;
this.sessionStartedCb_ = startedCb; this.sessionStartedCb_ = startedCb;
this.updateStateFromStatus_(); this.updateStateFromStatus_();
...@@ -268,6 +271,7 @@ cr.define('hotword', function() { ...@@ -268,6 +271,7 @@ cr.define('hotword', function() {
* session request. * session request.
*/ */
stopSession: function(source) { stopSession: function(source) {
hotword.debug('Stopping session for source: ' + source);
this.sessionSource_ = null; this.sessionSource_ = null;
this.sessionStartedCb_ = null; this.sessionStartedCb_ = null;
this.updateStateFromStatus_(); this.updateStateFromStatus_();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment