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

Side by Side Diff: chrome/browser/resources/settings/bluetooth_page/bluetooth_subpage.js

Issue 2801403002: MD Settings: Bluetooth: Fix adapter state and discovery (Closed)
Patch Set: Use CHECK instead of early exit Created 3 years, 8 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * 'settings-bluetooth-subpage' is the settings subpage for managing bluetooth 7 * 'settings-bluetooth-subpage' is the settings subpage for managing bluetooth
8 * properties and devices. 8 * properties and devices.
9 */ 9 */
10 10
11 // NOTE(dbeam): even though this behavior is only used privately, it must 11 // NOTE(dbeam): even though this behavior is only used privately, it must
12 // be globally accessible for Closure's --polymer_pass to compile happily. 12 // be globally accessible for Closure's --polymer_pass to compile happily.
13 13
14 Polymer({ 14 Polymer({
15 is: 'settings-bluetooth-subpage', 15 is: 'settings-bluetooth-subpage',
16 16
17 behaviors: [ 17 behaviors: [
18 I18nBehavior, 18 I18nBehavior,
19 CrScrollableBehavior, 19 CrScrollableBehavior,
20 settings.RouteObserverBehavior, 20 settings.RouteObserverBehavior,
21 ], 21 ],
22 22
23 properties: { 23 properties: {
24 /** Reflects the bluetooth-page property. */ 24 /** Reflects the bluetooth-page property. */
25 bluetoothEnabled: { 25 bluetoothToggleState: {
26 type: Boolean, 26 type: Boolean,
27 notify: true, 27 notify: true,
28 }, 28 },
29 29
30 /** Reflects the bluetooth-page property. */
31 bluetoothToggleDisabled: Boolean,
32
30 /** 33 /**
31 * The bluetooth adapter state, cached by bluetooth-page. 34 * The bluetooth adapter state, cached by bluetooth-page.
32 * @type {!chrome.bluetooth.AdapterState|undefined} 35 * @type {!chrome.bluetooth.AdapterState|undefined}
33 */ 36 */
34 adapterState: Object, 37 adapterState: Object,
35 38
36 /** Informs bluetooth-page whether to show the spinner in the header. */ 39 /** Informs bluetooth-page whether to show the spinner in the header. */
37 showSpinner_: { 40 showSpinner_: {
38 type: Boolean, 41 type: Boolean,
39 notify: true, 42 notify: true,
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 else 245 else
243 this.stopDiscovery_(); 246 this.stopDiscovery_();
244 }, 247 },
245 248
246 /** 249 /**
247 * If bluetooth is enabled, request the complete list of devices and update 250 * If bluetooth is enabled, request the complete list of devices and update
248 * this.deviceList_. 251 * this.deviceList_.
249 * @private 252 * @private
250 */ 253 */
251 updateDeviceList_: function() { 254 updateDeviceList_: function() {
252 if (!this.bluetoothEnabled) { 255 if (!this.bluetoothToggleState) {
253 this.deviceList_ = []; 256 this.deviceList_ = [];
254 return; 257 return;
255 } 258 }
256 this.bluetooth.getDevices(function(devices) { 259 this.bluetooth.getDevices(function(devices) {
257 this.deviceList_ = devices; 260 this.deviceList_ = devices;
258 }.bind(this)); 261 }.bind(this));
259 }, 262 },
260 263
261 /** 264 /**
262 * Process bluetooth.onDeviceAdded and onDeviceChanged events. 265 * Process bluetooth.onDeviceAdded and onDeviceChanged events.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 * @param {string} onstr 348 * @param {string} onstr
346 * @param {string} offstr 349 * @param {string} offstr
347 * @return {string} 350 * @return {string}
348 * @private 351 * @private
349 */ 352 */
350 getOnOffString_: function(enabled, onstr, offstr) { 353 getOnOffString_: function(enabled, onstr, offstr) {
351 return enabled ? onstr : offstr; 354 return enabled ? onstr : offstr;
352 }, 355 },
353 356
354 /** 357 /**
355 * @param {boolean} bluetoothEnabled 358 * @param {boolean} bluetoothToggleState
356 * @param {!Array<!chrome.bluetooth.Device>} deviceList 359 * @param {!Array<!chrome.bluetooth.Device>} deviceList
357 * @return {boolean} 360 * @return {boolean}
358 * @private 361 * @private
359 */ 362 */
360 showDevices_: function(bluetoothEnabled, deviceList) { 363 showDevices_: function(bluetoothToggleState, deviceList) {
361 return bluetoothEnabled && deviceList.length > 0; 364 return bluetoothToggleState && deviceList.length > 0;
362 }, 365 },
363 366
364 /** 367 /**
365 * @param {boolean} bluetoothEnabled 368 * @param {boolean} bluetoothToggleState
366 * @param {!Array<!chrome.bluetooth.Device>} deviceList 369 * @param {!Array<!chrome.bluetooth.Device>} deviceList
367 * @return {boolean} 370 * @return {boolean}
368 * @private 371 * @private
369 */ 372 */
370 showNoDevices_: function(bluetoothEnabled, deviceList) { 373 showNoDevices_: function(bluetoothToggleState, deviceList) {
371 return bluetoothEnabled && deviceList.length == 0; 374 return bluetoothToggleState && deviceList.length == 0;
372 }, 375 },
373 376
374 /** 377 /**
375 * @param {!chrome.bluetooth.Device} device 378 * @param {!chrome.bluetooth.Device} device
376 * @private 379 * @private
377 */ 380 */
378 connectDevice_: function(device) { 381 connectDevice_: function(device) {
379 // If the device is not paired, show the pairing dialog before connecting. 382 // If the device is not paired, show the pairing dialog before connecting.
380 if (!device.paired) { 383 if (!device.paired) {
381 this.pairingDevice_ = device; 384 this.pairingDevice_ = device;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 Polymer.dom.flush(); 463 Polymer.dom.flush();
461 this.$.deviceDialog.open(); 464 this.$.deviceDialog.open();
462 }, 465 },
463 466
464 /** @private */ 467 /** @private */
465 onDialogClosed_: function() { 468 onDialogClosed_: function() {
466 this.dialogId_ = ''; 469 this.dialogId_ = '';
467 this.pairingDevice_ = undefined; 470 this.pairingDevice_ = undefined;
468 }, 471 },
469 }); 472 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698