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

Side by Side 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: 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/resources/hotword/manager.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('hotword', function() { 5 cr.define('hotword', function() {
6 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * Trivial container class for session information. 9 * Trivial container class for session information.
10 * @param {!hotword.constants.SessionSource} source Source of the hotword 10 * @param {!hotword.constants.SessionSource} source Source of the hotword
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 */ 94 */
95 this.chime_ = 95 this.chime_ =
96 /** @type {!HTMLAudioElement} */(document.createElement('audio')); 96 /** @type {!HTMLAudioElement} */(document.createElement('audio'));
97 97
98 /** 98 /**
99 * Chrome event listeners. Saved so that they can be de-registered when 99 * Chrome event listeners. Saved so that they can be de-registered when
100 * hotwording is disabled. 100 * hotwording is disabled.
101 * @private 101 * @private
102 */ 102 */
103 this.idleStateChangedListener_ = this.handleIdleStateChanged_.bind(this); 103 this.idleStateChangedListener_ = this.handleIdleStateChanged_.bind(this);
104 this.startupListener_ = this.handleStartup_.bind(this);
104 105
105 /** 106 /**
106 * Whether this user is locked. 107 * Whether this user is locked.
107 * @private {boolean} 108 * @private {boolean}
108 */ 109 */
109 this.isLocked_ = false; 110 this.isLocked_ = false;
110 111
111 /** 112 /**
112 * Current state of audio logging. 113 * Current state of audio logging.
113 * This is tracked separately from hotwordStatus_ because we need to restart 114 * This is tracked separately from hotwordStatus_ because we need to restart
(...skipping 20 matching lines...) Expand all
134 // Get the initial status. 135 // Get the initial status.
135 chrome.hotwordPrivate.getStatus(this.handleStatus_.bind(this)); 136 chrome.hotwordPrivate.getStatus(this.handleStatus_.bind(this));
136 137
137 // Setup the chime and insert into the page. 138 // Setup the chime and insert into the page.
138 // Set preload=none to prevent an audio output stream from being created 139 // Set preload=none to prevent an audio output stream from being created
139 // when the extension loads. 140 // when the extension loads.
140 this.chime_.preload = 'none'; 141 this.chime_.preload = 'none';
141 this.chime_.src = chrome.extension.getURL( 142 this.chime_.src = chrome.extension.getURL(
142 hotword.constants.SHARED_MODULE_ROOT + '/audio/chime.wav'); 143 hotword.constants.SHARED_MODULE_ROOT + '/audio/chime.wav');
143 document.body.appendChild(this.chime_); 144 document.body.appendChild(this.chime_);
145
146 // In order to remove this listener, it must first be added. This handles
147 // the case on first Chrome startup where this event is never registered,
148 // so can't be removed when it's determined that hotwording is disabled.
149 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.
144 } 150 }
145 151
146 /** 152 /**
147 * @enum {number} 153 * @enum {number}
148 * @private 154 * @private
149 */ 155 */
150 StateManager.State_ = { 156 StateManager.State_ = {
151 STOPPED: 0, 157 STOPPED: 0,
152 STARTING: 1, 158 STARTING: 1,
153 RUNNING: 2, 159 RUNNING: 2,
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 this.startDetector_(); 278 this.startDetector_();
273 } else { 279 } else {
274 this.shutdownDetector_(); 280 this.shutdownDetector_();
275 } 281 }
276 282
277 if (!chrome.idle.onStateChanged.hasListener( 283 if (!chrome.idle.onStateChanged.hasListener(
278 this.idleStateChangedListener_)) { 284 this.idleStateChangedListener_)) {
279 chrome.idle.onStateChanged.addListener( 285 chrome.idle.onStateChanged.addListener(
280 this.idleStateChangedListener_); 286 this.idleStateChangedListener_);
281 } 287 }
288 if (!chrome.runtime.onStartup.hasListener(this.startupListener_))
289 chrome.runtime.onStartup.addListener(this.startupListener_);
282 } else { 290 } else {
283 // Not enabled. Shut down if running. 291 // Not enabled. Shut down if running.
284 this.shutdownDetector_(); 292 this.shutdownDetector_();
285 293
286 chrome.idle.onStateChanged.removeListener( 294 chrome.idle.onStateChanged.removeListener(
287 this.idleStateChangedListener_); 295 this.idleStateChangedListener_);
296 // If hotwording isn't enabled, don't start this component extension on
297 // Chrome startup. If a user enables hotwording, the status change
298 // event will be fired and the onStartup event will be registered.
299 chrome.runtime.onStartup.removeListener(this.startupListener_);
288 } 300 }
289 }, 301 },
290 302
291 /** 303 /**
292 * Starts the hotword detector. 304 * Starts the hotword detector.
293 * @private 305 * @private
294 */ 306 */
295 startDetector_: function() { 307 startDetector_: function() {
296 // Last attempt to start detector resulted in an error. 308 // Last attempt to start detector resulted in an error.
297 if (this.state_ == State_.ERROR) { 309 if (this.state_ == State_.ERROR) {
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 handleIdleStateChanged_: function(state) { 607 handleIdleStateChanged_: function(state) {
596 hotword.debug('Idle state changed: ' + state); 608 hotword.debug('Idle state changed: ' + state);
597 var oldLocked = this.isLocked_; 609 var oldLocked = this.isLocked_;
598 if (state == 'locked') 610 if (state == 'locked')
599 this.isLocked_ = true; 611 this.isLocked_ = true;
600 else 612 else
601 this.isLocked_ = false; 613 this.isLocked_ = false;
602 614
603 if (oldLocked != this.isLocked_) 615 if (oldLocked != this.isLocked_)
604 this.updateStateFromStatus_(); 616 this.updateStateFromStatus_();
617 },
618
619 /**
620 * Handles a chrome.runtime.onStartup event.
621 * @private
622 */
623 handleStartup_: function() {
624 updateStatus();
605 } 625 }
606 }; 626 };
607 627
608 return { 628 return {
609 StateManager: StateManager 629 StateManager: StateManager
610 }; 630 };
611 }); 631 });
OLDNEW
« 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