Chromium Code Reviews| 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..7c8e30a2c4e1d0bda7e1920058aa038e003cce20 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,11 @@ 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. |
| + chrome.runtime.onStartup.addListener(this.startupListener_); |
|
Matt Giuca
2015/05/15 06:54:42
Why not just not remove it if it hasn't been added
Anand Mistry (off Chromium)
2015/05/15 07:08:36
Ah, undocumented and poorly understood behaviour o
Matt Giuca
2015/05/15 08:32:43
Gross :(
Could you explain that a bit in the comm
Anand Mistry (off Chromium)
2015/05/18 01:24:22
Done.
|
| } |
| /** |
| @@ -279,12 +285,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 +614,14 @@ cr.define('hotword', function() { |
| if (oldLocked != this.isLocked_) |
| this.updateStateFromStatus_(); |
| + }, |
| + |
| + /** |
| + * Handles a chrome.runtime.onStartup event. |
| + * @private |
| + */ |
| + handleStartup_: function() { |
| + updateStatus(); |
| } |
| }; |