Chromium Code Reviews| Index: chrome/browser/resources/bluetooth_internals/device_collection.js |
| diff --git a/chrome/browser/resources/bluetooth_internals/device_collection.js b/chrome/browser/resources/bluetooth_internals/device_collection.js |
| index 4d86d99c79d47e972aa809d210f54b8a59528384..db483b0e5d8b46d3a711ac2cfb3a63018c0b7041 100644 |
| --- a/chrome/browser/resources/bluetooth_internals/device_collection.js |
| +++ b/chrome/browser/resources/bluetooth_internals/device_collection.js |
| @@ -12,8 +12,8 @@ cr.define('device_collection', function() { |
| * Collection of devices. Extends ArrayDataModel which provides a set of |
| * functions and events that notifies observers when the collection changes. |
| * @constructor |
| - * @param {!Array<device_collection.Device>} array The starting collection of |
| - * devices. |
| + * @param {!Array<device_collection.DeviceInfo>} array The starting collection |
|
dpapad
2016/11/10 19:05:02
I am guessing that the array should not hold null
mbrunson
2016/11/10 22:02:22
Done.
|
| + * of devices. |
| * @extends {cr.ui.ArrayDataModel} |
| */ |
| var DeviceCollection = function(array) { |
| @@ -29,7 +29,7 @@ cr.define('device_collection', function() { |
| getByAddress: function(address) { |
| for (var i = 0; i < this.length; i++) { |
| var device = this.item(i); |
| - if (address == device.info.address) |
| + if (address == device.address) |
| return device; |
| } |
| return null; |
| @@ -40,19 +40,20 @@ cr.define('device_collection', function() { |
| * @param {!interfaces.BluetoothDevice.DeviceInfo} deviceInfo |
| */ |
| addOrUpdate: function(deviceInfo) { |
| - var oldDevice = this.getByAddress(deviceInfo.address); |
| - if (oldDevice) { |
| + deviceInfo.removed = false; |
| + var oldDeviceInfo = this.getByAddress(deviceInfo.address); |
| + |
| + if (oldDeviceInfo) { |
| // Update rssi if it's valid |
| var rssi = (deviceInfo.rssi && deviceInfo.rssi.value) || |
| - (oldDevice.info.rssi && oldDevice.info.rssi.value); |
| - |
| - oldDevice.info = deviceInfo; |
| - oldDevice.info.rssi = { value: rssi }; |
| - oldDevice.removed = false; |
| + (oldDeviceInfo.rssi && oldDeviceInfo.rssi.value); |
| - this.updateIndex(this.indexOf(oldDevice)); |
| + Object.assign(oldDeviceInfo, deviceInfo); |
|
dpapad
2016/11/10 19:05:02
Are all properties of oldDeviceInfo overwritten by
mbrunson
2016/11/10 22:02:22
Yes. deviceInfo.rssi may be null while oldDeviceIn
|
| + oldDeviceInfo.rssi = { value: rssi }; |
| + this.updateIndex(this.indexOf(oldDeviceInfo)); |
| } else { |
| - this.push(new Device(deviceInfo)); |
| + deviceInfo.connectionStatus = 'disconnected'; |
| + this.push(deviceInfo); |
| } |
| }, |
| @@ -65,21 +66,29 @@ cr.define('device_collection', function() { |
| assert(device, 'Device does not exist.'); |
| device.removed = true; |
| this.updateIndex(this.indexOf(device)); |
| - } |
| - }; |
| + }, |
| - /* |
| - * Data model for a cached device. |
| - * @constructor |
| - * @param {!interfaces.BluetoothDevice.DeviceInfo} info |
| - */ |
| - var Device = function(info) { |
| - this.info = info; |
| - this.removed = false; |
| + /** |
| + * Updates the device connection status. |
| + * @param {string} address The address of the device. |
| + * @param {string} status Disconnected, connecting, or connected string. |
| + * @param {Error} optional_error Optional Error object. |
|
dpapad
2016/11/10 19:05:02
Please follow styleguide for naming optional param
mbrunson
2016/11/10 22:02:22
Done.
|
| + */ |
| + updateConnectionStatus: function(address, status, optional_error) { |
| + var message = (optional_error && optional_error.message) || ''; |
| + |
| + var device = this.getByAddress(address); |
|
dpapad
2016/11/10 19:05:02
Nit (optional): You can also
var device = assert(t
mbrunson
2016/11/10 22:02:22
Oh. That's cool! Done.
|
| + assert(device, 'Device does not exist'); |
| + device.connectionStatus = status; |
| + |
| + // TODO(crbug.com/663830): Replace connection error column with better |
| + // notification system. |
| + device.connectionMessage = message; |
| + this.updateIndex(this.indexOf(device)); |
| + }, |
| }; |
| return { |
| - Device: Device, |
| DeviceCollection: DeviceCollection, |
| }; |
| }); |