Commit fb5a643e authored by kcarattini's avatar kcarattini Committed by Commit bot

Adds a Training Manager to the hotword extension.

BUG=397019

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

Cr-Commit-Position: refs/heads/master@{#302530}
parent 68fedbf9
...@@ -99,6 +99,7 @@ ...@@ -99,6 +99,7 @@
<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_PAGE_AUDIO_MANAGER_JS" file="hotword/page_audio_manager.js" type="BINDATA" /> <include name="IDR_HOTWORD_PAGE_AUDIO_MANAGER_JS" file="hotword/page_audio_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" />
<include name="IDR_HOTWORD_TRAINING_MANAGER_JS" file="hotword/training_manager.js" type="BINDATA" />
</if> </if>
<if expr="not is_android"> <if expr="not is_android">
<include name="IDR_FEEDBACK_DEFAULT_HTML" file="feedback/html/default.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" /> <include name="IDR_FEEDBACK_DEFAULT_HTML" file="feedback/html/default.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" />
......
...@@ -69,7 +69,7 @@ cr.define('hotword', function() { ...@@ -69,7 +69,7 @@ cr.define('hotword', function() {
function() { function() {
chrome.hotwordPrivate.setHotwordSessionState(true, function() {}); chrome.hotwordPrivate.setHotwordSessionState(true, function() {});
}, },
this.handleHotwordTrigger_.bind(this)); this.handleHotwordTrigger.bind(this));
}, },
/** /**
...@@ -83,9 +83,9 @@ cr.define('hotword', function() { ...@@ -83,9 +83,9 @@ cr.define('hotword', function() {
/** /**
* Handles a hotword triggered event. * Handles a hotword triggered event.
* @private * @protected
*/ */
handleHotwordTrigger_: function() { handleHotwordTrigger: function() {
hotword.debug('Hotword triggered: ' + this.sessionSource_); hotword.debug('Hotword triggered: ' + this.sessionSource_);
chrome.hotwordPrivate.notifyHotwordRecognition('search', function() {}); chrome.hotwordPrivate.notifyHotwordRecognition('search', function() {});
}, },
......
...@@ -121,7 +121,8 @@ var CommandFromPage = { ...@@ -121,7 +121,8 @@ var CommandFromPage = {
var SessionSource = { var SessionSource = {
LAUNCHER: 'launcher', LAUNCHER: 'launcher',
NTP: 'ntp', NTP: 'ntp',
ALWAYS: 'always' ALWAYS: 'always',
TRAINING: 'training'
}; };
/** /**
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
var pageAudioManager = new hotword.PageAudioManager(stateManager); var pageAudioManager = new hotword.PageAudioManager(stateManager);
var alwaysOnManager = new hotword.AlwaysOnManager(stateManager); var alwaysOnManager = new hotword.AlwaysOnManager(stateManager);
var launcherManager = new hotword.LauncherManager(stateManager); var launcherManager = new hotword.LauncherManager(stateManager);
var trainingManager = new hotword.TrainingManager(stateManager);
// Detect Chrome startup and make sure we get a chance to run. // Detect Chrome startup and make sure we get a chance to run.
chrome.runtime.onStartup.addListener(function() { chrome.runtime.onStartup.addListener(function() {
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
"always_on_manager.js", "always_on_manager.js",
"launcher_manager.js", "launcher_manager.js",
"page_audio_manager.js", "page_audio_manager.js",
"training_manager.js",
"manager.js" "manager.js"
], ],
"persistent": false "persistent": false
......
...@@ -159,6 +159,14 @@ cr.define('hotword', function() { ...@@ -159,6 +159,14 @@ cr.define('hotword', function() {
return this.hotwordStatus_.alwaysOnEnabled; return this.hotwordStatus_.alwaysOnEnabled;
}, },
/**
* @return {boolean} True if training is enabled.
*/
isTrainingEnabled: function() {
assert(this.hotwordStatus_, 'No hotword status (isTrainingEnabled)');
return this.hotwordStatus_.trainingEnabled;
},
/** /**
* Callback for hotwordPrivate.getStatus() function. * Callback for hotwordPrivate.getStatus() function.
* @param {chrome.hotwordPrivate.StatusDetails} status Current hotword * @param {chrome.hotwordPrivate.StatusDetails} status Current hotword
...@@ -181,7 +189,9 @@ cr.define('hotword', function() { ...@@ -181,7 +189,9 @@ cr.define('hotword', function() {
if (!this.hotwordStatus_) if (!this.hotwordStatus_)
return; return;
if (this.hotwordStatus_.enabled || this.hotwordStatus_.alwaysOnEnabled) { if (this.hotwordStatus_.enabled ||
this.hotwordStatus_.alwaysOnEnabled ||
this.hotwordStatus_.trainingEnabled) {
// Start the detector if there's a session, and shut it down if there // Start the detector if there's a session, and shut it down if there
// isn't. // isn't.
// NOTE(amistry): With always-on, we want a different behaviour with // NOTE(amistry): With always-on, we want a different behaviour with
......
// 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';
/**
* Class used to manage speaker training. Starts a hotwording session
* if training is on, and automatically restarts the detector when a
* a hotword is triggered.
* @param {!hotword.StateManager} stateManager
* @constructor
* @extends {hotword.BaseSessionManager}
*/
function TrainingManager(stateManager) {
hotword.BaseSessionManager.call(this,
stateManager,
hotword.constants.SessionSource.TRAINING);
}
TrainingManager.prototype = {
__proto__: hotword.BaseSessionManager.prototype,
/** @override */
enabled: function() {
return this.stateManager.isTrainingEnabled();
},
/** @override */
updateListeners: function() {
hotword.BaseSessionManager.prototype.updateListeners.call(this);
if (this.enabled())
this.startSession_();
},
/** @override */
handleHotwordTrigger: function() {
if (this.enabled()) {
hotword.BaseSessionManager.prototype.handleHotwordTrigger.call(this);
this.startSession_();
}
}
};
return {
TrainingManager: TrainingManager
};
});
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