Commit 530f364a authored by Ryan Hansberry's avatar Ryan Hansberry Committed by Commit Bot

[Bluetooth] Fix Closure errors in bluetooth-internals.

Address closure issues caused by moving to more restrictive rules:
  * Tweaked how BluetoothAdapter 'info' was bubbled up to be non-null.
  * The code was previously shoving undeclared 'removed' and
    'connectionStatus' properties into the bluetooth.mojom.DeviceInfo
    struct. I moved this 'removed' property to a separate map (it's a
    hacky property only used for the bluetooth-internals page, so it
    makes no sense to actually add to the struct) and completely tore
    out the notion of a 'connectionStatus' from being attached to a
    DeviceInfo since it was actually not used (!).

Tested by building webui_closure_compile with this CL based on top of
crrev.com/c/2006413, and by manually testing
chrome://bluetooth-internals to verify no regressions were introduced.

Fixed: 1047809
Change-Id: Id5abfec261602e67e9f9783a5621bec7bd97cc65
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2038078
Commit-Queue: Ryan Hansberry <hansberry@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738658}
parent 6ac0d578
......@@ -110,11 +110,6 @@ cr.define('bluetooth_internals', function() {
$('page-container').appendChild(pageSection);
deviceDetailsPage = new DeviceDetailsPage(deviceDetailsPageId, deviceInfo);
deviceDetailsPage.pageDiv.addEventListener(
'connectionchanged', function(event) {
devices.updateConnectionStatus(
event.detail.address, event.detail.status);
});
deviceDetailsPage.pageDiv.addEventListener('infochanged', function(event) {
devices.addOrUpdate(event.detail.info);
......@@ -176,7 +171,11 @@ cr.define('bluetooth_internals', function() {
adapterPage.pageDiv.addEventListener('refreshpressed', function() {
adapterBroker.getInfo().then(function(response) {
adapterPage.setAdapterInfo(response.info);
if (response && response.info) {
adapterPage.setAdapterInfo(response.info);
} else {
console.error('Failed to fetch adapter info.');
}
});
});
}
......
......@@ -9,10 +9,7 @@
cr.define('device_collection', function() {
/**
* Enum of connection status for a device. Used for
* DeviceCollection.updateConnectionStatus which sets the connectionStatus
* on the DeviceInfo object. New DeviceInfo objects have a DISCONNECTED status
* by default.
* Enum of connection status for a device.
* @enum {number}
*/
const ConnectionStatus = {
......@@ -32,6 +29,11 @@ cr.define('device_collection', function() {
*/
constructor(array) {
super(array);
// Keep track of MAC addresses which were previously found via scan, but
// are no longer being advertised or nearby. Used to inform isRemoved().
/** @private {!Object<string, boolean>} */
this.removedDevices_ = {};
}
/**
......@@ -53,7 +55,7 @@ cr.define('device_collection', function() {
* @param {!bluetooth.mojom.DeviceInfo} deviceInfo
*/
addOrUpdate(deviceInfo) {
deviceInfo.removed = false;
this.removedDevices_[deviceInfo.address] = false;
const oldDeviceInfo = this.getByAddress(deviceInfo.address);
if (oldDeviceInfo) {
......@@ -61,14 +63,11 @@ cr.define('device_collection', function() {
const rssi = (deviceInfo.rssi && deviceInfo.rssi.value) ||
(oldDeviceInfo.rssi && oldDeviceInfo.rssi.value);
// The connectionStatus and connectionMessage properties may not exist
// on |deviceInfo|. The rssi property may be null, so it must be
// re-assigned.
// The rssi property may be null, so it must be re-assigned.
Object.assign(oldDeviceInfo, deviceInfo);
oldDeviceInfo.rssi = {value: rssi};
this.updateIndex(this.indexOf(oldDeviceInfo));
} else {
deviceInfo.connectionStatus = ConnectionStatus.DISCONNECTED;
this.push(deviceInfo);
}
}
......@@ -80,20 +79,17 @@ cr.define('device_collection', function() {
remove(deviceInfo) {
const device = this.getByAddress(deviceInfo.address);
assert(device, 'Device does not exist.');
device.removed = true;
this.removedDevices_[deviceInfo.address] = true;
this.updateIndex(this.indexOf(device));
}
/**
* Updates the device connection status.
* @param {string} address The address of the device.
* @param {number} status The new connection status.
* Return true if device was "removed" -- previously found via scan but
* either no longer advertising or no longer nearby.
* @param {!bluetooth.mojom.DeviceInfo} deviceInfo
*/
updateConnectionStatus(address, status) {
const device =
assert(this.getByAddress(address), 'Device does not exist');
device.connectionStatus = status;
this.updateIndex(this.indexOf(device));
isRemoved(deviceInfo) {
return !!this.removedDevices_[deviceInfo.address];
}
}
......
......@@ -191,7 +191,7 @@ cr.define('device_table', function() {
const row = this.body_.rows[index];
assert(row, 'Row ' + index + ' is not in the table.');
row.classList.toggle('removed', device.removed);
row.classList.toggle('removed', this.devices_.isRemoved(device));
const forgetLink = row.cells[COLUMNS.LINKS].children[1];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment