Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1796)

Unified Diff: chrome/browser/resources/hotword/state_manager.js

Issue 1130763005: Don't start the hotword extension on Chrome startup if the user doesn't have hotwording enabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update comment. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/hotword/manager.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/hotword/state_manager.js
diff --git a/chrome/browser/resources/hotword/state_manager.js b/chrome/browser/resources/hotword/state_manager.js
index ebe68355d80815250acd0df74ba2eaa7c479bb31..782939a6ea8e5048e97ab110c4e06dac9869f985 100644
--- a/chrome/browser/resources/hotword/state_manager.js
+++ b/chrome/browser/resources/hotword/state_manager.js
@@ -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();
}
};
« no previous file with comments | « chrome/browser/resources/hotword/manager.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698