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

Unified Diff: chrome/browser/resources/settings/bluetooth_page/bluetooth_page.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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/settings/bluetooth_page/bluetooth_page.js
diff --git a/chrome/browser/resources/settings/bluetooth_page/bluetooth_page.js b/chrome/browser/resources/settings/bluetooth_page/bluetooth_page.js
index e23ed90c9e17b244d0fc70244be821926f643269..6510e5472d53c2d93618dc6d7fdb38bf8588a472 100644
--- a/chrome/browser/resources/settings/bluetooth_page/bluetooth_page.js
+++ b/chrome/browser/resources/settings/bluetooth_page/bluetooth_page.js
@@ -32,11 +32,27 @@ Polymer({
notify: true,
},
- /** @private */
- bluetoothEnabled_: {
+ /**
+ * Reflects the current state of the toggle buttons (in this page and the
+ * subpage). This will be set when the adapter state change or when the user
+ * changes the toggle.
+ * @private
+ */
+ bluetoothToggleState_: {
type: Boolean,
- observer: 'bluetoothEnabledChanged_',
- notify: true,
+ observer: 'bluetoothToggleStateChanged_',
+ },
+
+ /**
+ * Set to true before the adapter state is received, when the adapter is
+ * unavailable, and while an adapter state change is requested. This
+ * prevents user changes while a change is in progress or when the adapter
+ * is not available.
+ * @private
+ */
+ bluetoothToggleDisabled_: {
+ type: Boolean,
+ value: true,
},
/**
@@ -111,7 +127,7 @@ Polymer({
* @private
*/
getIcon_: function() {
- if (!this.bluetoothEnabled_)
+ if (!this.bluetoothToggleState_)
return 'settings:bluetooth-disabled';
return 'settings:bluetooth';
},
@@ -134,15 +150,16 @@ Polymer({
*/
onBluetoothAdapterStateChanged_: function(state) {
this.adapterState_ = state;
- this.bluetoothEnabled_ = state.powered;
+ this.bluetoothToggleState_ = state.powered;
+ this.bluetoothToggleDisabled_ = !state.available;
},
/** @private */
onTap_: function() {
if (this.adapterState_.available === false)
return;
- if (!this.bluetoothEnabled_)
- this.bluetoothEnabled_ = true;
+ if (!this.bluetoothToggleState_)
+ this.bluetoothToggleState_ = true;
else
this.openSubpage_();
},
@@ -165,9 +182,14 @@ Polymer({
},
/** @private */
- bluetoothEnabledChanged_: function() {
+ bluetoothToggleStateChanged_: function() {
+ if (!this.adapterState_ || this.bluetoothToggleDisabled_ ||
+ this.bluetoothToggleState_ == this.adapterState_.powered) {
+ return;
+ }
+ this.bluetoothToggleDisabled_ = true;
this.bluetoothPrivate.setAdapterState(
- {powered: this.bluetoothEnabled_}, function() {
+ {powered: this.bluetoothToggleState_}, function() {
if (chrome.runtime.lastError) {
console.error(
'Error enabling bluetooth: ' +

Powered by Google App Engine
This is Rietveld 408576698