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

Unified Diff: chrome/browser/resources/settings/bluetooth_page/bluetooth_subpage.js

Issue 2724533006: MD Settings: Bluetooth: Clean up observers and discovery logic (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « chrome/browser/resources/settings/bluetooth_page/bluetooth_subpage.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/settings/bluetooth_page/bluetooth_subpage.js
diff --git a/chrome/browser/resources/settings/bluetooth_page/bluetooth_subpage.js b/chrome/browser/resources/settings/bluetooth_page/bluetooth_subpage.js
index eec93c88966f03604539f1f3f60bfe940e0d67b8..bbff7a444320c4665809a22a8290ce354dec454f 100644
--- a/chrome/browser/resources/settings/bluetooth_page/bluetooth_subpage.js
+++ b/chrome/browser/resources/settings/bluetooth_page/bluetooth_subpage.js
@@ -24,7 +24,6 @@ Polymer({
/** Reflects the bluetooth-page property. */
bluetoothEnabled: {
type: Boolean,
- observer: 'bluetoothEnabledChanged_',
notify: true,
},
@@ -148,21 +147,22 @@ Polymer({
/**
* Listener for chrome.bluetooth.onBluetoothDeviceAdded/Changed events.
- * @type {function(!chrome.bluetooth.Device)|undefined}
+ * @type {?function(!chrome.bluetooth.Device)}
* @private
*/
- bluetoothDeviceUpdatedListener_: undefined,
+ bluetoothDeviceUpdatedListener_: null,
/**
* Listener for chrome.bluetooth.onBluetoothDeviceRemoved events.
- * @type {function(!chrome.bluetooth.Device)|undefined}
+ * @type {?function(!chrome.bluetooth.Device)}
* @private
*/
- bluetoothDeviceRemovedListener_: undefined,
+ bluetoothDeviceRemovedListener_: null,
/** @override */
attached: function() {
this.bluetoothDeviceUpdatedListener_ =
+ this.bluetoothDeviceUpdatedListener_ ||
this.onBluetoothDeviceUpdated_.bind(this);
this.bluetooth.onDeviceAdded.addListener(
this.bluetoothDeviceUpdatedListener_);
@@ -170,6 +170,7 @@ Polymer({
this.bluetoothDeviceUpdatedListener_);
this.bluetoothDeviceRemovedListener_ =
+ this.bluetoothDeviceRemovedListener_ ||
this.onBluetoothDeviceRemoved_.bind(this);
this.bluetooth.onDeviceRemoved.addListener(
this.bluetoothDeviceRemovedListener_);
@@ -177,16 +178,12 @@ Polymer({
/** @override */
detached: function() {
- if (this.bluetoothAdapterStateChangedListener_) {
- this.bluetooth.onAdapterStateChanged.removeListener(
- this.bluetoothAdapterStateChangedListener_);
- }
- if (this.bluetoothDeviceUpdatedListener_) {
- this.bluetooth.onDeviceAdded.removeListener(
- this.bluetoothDeviceUpdatedListener_);
- this.bluetooth.onDeviceChanged.removeListener(
- this.bluetoothDeviceUpdatedListener_);
- }
+ this.bluetooth.onDeviceAdded.removeListener(
+ assert(this.bluetoothDeviceUpdatedListener_));
+ this.bluetooth.onDeviceChanged.removeListener(
+ assert(this.bluetoothDeviceUpdatedListener_));
+ this.bluetooth.onDeviceRemoved.removeListener(
+ assert(this.bluetoothDeviceRemovedListener_));
},
/**
@@ -195,12 +192,7 @@ Polymer({
* @protected
*/
currentRouteChanged: function(route) {
- if (route == settings.Route.BLUETOOTH_DEVICES) {
- if (this.bluetoothEnabled)
- this.startDiscovery_();
- } else {
- this.stopDiscovery_();
- }
+ this.updateDiscovery_();
},
/** @private */
@@ -210,20 +202,11 @@ Polymer({
/** @private */
adapterStateChanged_: function() {
+ this.updateDiscovery_();
this.updateDeviceList_();
},
/** @private */
- bluetoothEnabledChanged_: function() {
- if (settings.getCurrentRoute() == settings.Route.BLUETOOTH_DEVICES &&
- this.bluetoothEnabled) {
- this.startDiscovery_();
- } else {
- this.stopDiscovery_();
- }
- },
-
- /** @private */
deviceListChanged_: function() {
this.saveScroll(this.$.pairedDevices);
this.saveScroll(this.$.unpairedDevices);
@@ -250,6 +233,16 @@ Polymer({
this.connectDevice_(this.selectedUnpairedItem_);
},
+ /** @private */
+ updateDiscovery_: function() {
+ if (!this.adapterState || !this.adapterState.powered)
+ return;
+ if (settings.getCurrentRoute() == settings.Route.BLUETOOTH_DEVICES)
+ this.startDiscovery_();
+ else
+ this.stopDiscovery_();
+ },
+
/**
* If bluetooth is enabled, request the complete list of devices and update
* this.deviceList_.
« no previous file with comments | « chrome/browser/resources/settings/bluetooth_page/bluetooth_subpage.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698