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 @@
<!-- (Experimental) hotword triggering extension -->
<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_NACL_MANAGER_JS" file="hotword/nacl_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 @@
// Detect when the shared module containing the NaCL module and language model
// is installed.
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();
}
});
// Detect when a session has requested to be started and stopped.
chrome.hotwordPrivate.onHotwordSessionRequested.addListener(function() {
hotword.debug('hotwordPrivate.onHotwordSessionRequested');
// TODO(amistry): This event should change state depending on whether 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
......@@ -51,6 +54,7 @@
});
chrome.hotwordPrivate.onHotwordSessionStopped.addListener(function() {
hotword.debug('hotwordPrivate.onHotwordSessionStopped');
stateManager.stopSession(hotword.constants.SessionSource.LAUNCHER);
chrome.hotwordPrivate.setHotwordSessionState(false, function() {});
});
......
......@@ -12,6 +12,7 @@
"chrome://resources/js/util.js",
"chrome://resources/js/cr/event_target.js",
"constants.js",
"logging.js",
"nacl_manager.js",
"state_manager.js",
"manager.js"
......
......@@ -86,6 +86,7 @@ cr.define('hotword', function() {
* @private
*/
handleStatus_: function(status) {
hotword.debug('New hotword status', status);
this.hotwordStatus_ = status;
this.updateStateFromStatus_();
},
......@@ -234,6 +235,7 @@ cr.define('hotword', function() {
* @private
*/
onTrigger_: function() {
hotword.debug('Hotword triggered!');
assert(this.pluginManager_);
// Detector implicitly stops when the hotword is detected.
this.state_ = State_.STOPPED;
......@@ -257,6 +259,7 @@ cr.define('hotword', function() {
* been started successfully.
*/
startSession: function(source, startedCb) {
hotword.debug('Starting session for source: ' + source);
this.sessionSource_ = source;
this.sessionStartedCb_ = startedCb;
this.updateStateFromStatus_();
......@@ -268,6 +271,7 @@ cr.define('hotword', function() {
* session request.
*/
stopSession: function(source) {
hotword.debug('Stopping session for source: ' + source);
this.sessionSource_ = null;
this.sessionStartedCb_ = null;
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