Commit b8d26cff authored by amistry's avatar amistry Committed by Commit bot

Don't start the hotword extension on Chrome startup if the user doesn't have hotwording enabled.

BUG=488357

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

Cr-Commit-Position: refs/heads/master@{#330322}
parent 84b7d340
......@@ -24,11 +24,6 @@
var launcherManager = new hotword.LauncherManager(stateManager);
var trainingManager = new hotword.TrainingManager(stateManager);
// Detect Chrome startup and make sure we get a chance to run.
chrome.runtime.onStartup.addListener(function() {
stateManager.updateStatus();
});
// Detect when hotword settings have changed.
chrome.hotwordPrivate.onEnabledChanged.addListener(function() {
stateManager.updateStatus();
......
......@@ -101,6 +101,7 @@ cr.define('hotword', function() {
* @private
*/
this.idleStateChangedListener_ = this.handleIdleStateChanged_.bind(this);
this.startupListener_ = this.handleStartup_.bind(this);
/**
* Whether this user is locked.
......@@ -141,6 +142,18 @@ cr.define('hotword', function() {
this.chime_.src = chrome.extension.getURL(
hotword.constants.SHARED_MODULE_ROOT + '/audio/chime.wav');
document.body.appendChild(this.chime_);
// In order to remove this listener, it must first be added. This handles
// the case on first Chrome startup where this event is never registered,
// so can't be removed when it's determined that hotwording is disabled.
// Why not only remove the listener if it exists? Extension API events have
// two parts to them, the Javascript listeners, and a browser-side component
// that wakes up the extension if it's an event page. The browser-side
// wake-up event is only removed when the number of javascript listeners
// becomes 0. To clear the browser wake-up event, a listener first needs to
// be added, then removed in order to drop the count to 0 and remove the
// event.
chrome.runtime.onStartup.addListener(this.startupListener_);
}
/**
......@@ -279,12 +292,18 @@ cr.define('hotword', function() {
chrome.idle.onStateChanged.addListener(
this.idleStateChangedListener_);
}
if (!chrome.runtime.onStartup.hasListener(this.startupListener_))
chrome.runtime.onStartup.addListener(this.startupListener_);
} else {
// Not enabled. Shut down if running.
this.shutdownDetector_();
chrome.idle.onStateChanged.removeListener(
this.idleStateChangedListener_);
// If hotwording isn't enabled, don't start this component extension on
// Chrome startup. If a user enables hotwording, the status change
// event will be fired and the onStartup event will be registered.
chrome.runtime.onStartup.removeListener(this.startupListener_);
}
},
......@@ -602,6 +621,14 @@ cr.define('hotword', function() {
if (oldLocked != this.isLocked_)
this.updateStateFromStatus_();
},
/**
* Handles a chrome.runtime.onStartup event.
* @private
*/
handleStartup_: function() {
updateStatus();
}
};
......
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