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

Side by Side Diff: chrome/browser/resources/hotword/state_manager.js

Issue 685053002: Treat regular and always-on hotwording settings as mutually exclusive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 StateManager.prototype = { 133 StateManager.prototype = {
134 /** 134 /**
135 * Request status details update. Intended to be called from the 135 * Request status details update. Intended to be called from the
136 * hotwordPrivate.onEnabledChanged() event. 136 * hotwordPrivate.onEnabledChanged() event.
137 */ 137 */
138 updateStatus: function() { 138 updateStatus: function() {
139 chrome.hotwordPrivate.getStatus(this.handleStatus_.bind(this)); 139 chrome.hotwordPrivate.getStatus(this.handleStatus_.bind(this));
140 }, 140 },
141 141
142 /** 142 /**
143 * @return {boolean} True if hotwording is enabled. 143 * @return {boolean} True if google.com/NTP/launcher hotwording is enabled.
144 */ 144 */
145 isEnabled: function() { 145 isSometimesOnEnabled: function() {
146 assert(this.hotwordStatus_, 'No hotwording status (isEnabled)'); 146 assert(this.hotwordStatus_,
147 return this.hotwordStatus_.enabled; 147 'No hotwording status (isSometimesOnEnabled)');
148 // Although the two settings are supposed to be mutually exclusive, it's
149 // possible for both to be set. In that case, always-on takes precedence.
150 return this.hotwordStatus_.enabled &&
151 !this.hotwordStatus_.alwaysOnEnabled;
148 }, 152 },
149 153
150 /** 154 /**
151 * @return {boolean} True if always-on hotwording is enabled. 155 * @return {boolean} True if always-on hotwording is enabled.
152 */ 156 */
153 isAlwaysOnEnabled: function() { 157 isAlwaysOnEnabled: function() {
154 assert(this.hotwordStatus_, 'No hotword status (isAlwaysOnEnabled)'); 158 assert(this.hotwordStatus_, 'No hotword status (isAlwaysOnEnabled)');
155 return this.hotwordStatus_.enabled && 159 return this.hotwordStatus_.alwaysOnEnabled;
156 this.hotwordStatus_.alwaysOnEnabled;
157 }, 160 },
158 161
159 /** 162 /**
160 * Callback for hotwordPrivate.getStatus() function. 163 * Callback for hotwordPrivate.getStatus() function.
161 * @param {chrome.hotwordPrivate.StatusDetails} status Current hotword 164 * @param {chrome.hotwordPrivate.StatusDetails} status Current hotword
162 * status. 165 * status.
163 * @private 166 * @private
164 */ 167 */
165 handleStatus_: function(status) { 168 handleStatus_: function(status) {
166 hotword.debug('New hotword status', status); 169 hotword.debug('New hotword status', status);
167 this.hotwordStatus_ = status; 170 this.hotwordStatus_ = status;
168 this.updateStateFromStatus_(); 171 this.updateStateFromStatus_();
169 172
170 this.onStatusChanged.dispatch(); 173 this.onStatusChanged.dispatch();
171 }, 174 },
172 175
173 /** 176 /**
174 * Updates state based on the current status. 177 * Updates state based on the current status.
175 * @private 178 * @private
176 */ 179 */
177 updateStateFromStatus_: function() { 180 updateStateFromStatus_: function() {
178 if (!this.hotwordStatus_) 181 if (!this.hotwordStatus_)
179 return; 182 return;
180 183
181 if (this.hotwordStatus_.enabled) { 184 if (this.hotwordStatus_.enabled || this.hotwordStatus_.alwaysOnEnabled) {
182 // Start the detector if there's a session, and shut it down if there 185 // Start the detector if there's a session, and shut it down if there
183 // isn't. 186 // isn't.
184 // NOTE(amistry): With always-on, we want a different behaviour with 187 // NOTE(amistry): With always-on, we want a different behaviour with
185 // sessions since the detector should always be running. The exception 188 // sessions since the detector should always be running. The exception
186 // being when the user triggers by saying 'Ok Google'. In that case, the 189 // being when the user triggers by saying 'Ok Google'. In that case, the
187 // detector stops, so starting/stopping the launcher session should 190 // detector stops, so starting/stopping the launcher session should
188 // restart the detector. 191 // restart the detector.
189 if (this.sessions_.length) 192 if (this.sessions_.length)
190 this.startDetector_(); 193 this.startDetector_();
191 else 194 else
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 hotword.debug('Stopping session for source: ' + source); 388 hotword.debug('Stopping session for source: ' + source);
386 this.removeSession_(source); 389 this.removeSession_(source);
387 this.updateStateFromStatus_(); 390 this.updateStateFromStatus_();
388 } 391 }
389 }; 392 };
390 393
391 return { 394 return {
392 StateManager: StateManager 395 StateManager: StateManager
393 }; 396 };
394 }); 397 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/hotword/page_audio_manager.js ('k') | chrome/browser/ui/app_list/start_page_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698