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

Unified Diff: chrome/browser/resources/bluetooth_internals/bluetooth_internals.js

Issue 2418343002: bluetooth: Add device list UI for chrome://bluetooth-internals. (Closed)
Patch Set: Update comments Created 4 years, 2 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/bluetooth_internals/bluetooth_internals.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/bluetooth_internals/bluetooth_internals.js
diff --git a/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js b/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js
index 4582adef574a89ced2976da1a1960d16bd1dac24..e32988f1f747927759335f64fca83140a9e058bd 100644
--- a/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js
+++ b/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js
@@ -10,6 +10,8 @@
(function() {
var adapter, adapterClient, bluetoothAdapter, bluetoothDevice, connection;
+ var REMOVED_CSS = 'removed';
+
/*
* Data model for a cached device.
* @constructor
@@ -26,32 +28,56 @@
var AdapterClient = function() { this.devices_ = new Map(); };
AdapterClient.prototype = {
/**
- * Logs added device to console and caches the device info.
- * @param {!bluetoothDevice.DeviceInfo} device
+ * Caches the device info and updates the device list.
+ * @param {!bluetoothDevice.DeviceInfo} deviceInfo
*/
deviceAdded: function(deviceInfo) {
- console.log('Device added', deviceInfo);
- this.devices_.set(deviceInfo.address, new Device(deviceInfo));
+ if (this.devices_.has(deviceInfo.address)) {
+ var deviceElement = $(deviceInfo.address);
+ deviceElement.classList.remove(REMOVED_CSS);
+ } else {
+ this.devices_.set(deviceInfo.address, new Device(deviceInfo));
+
+ var deviceRowTemplate = $('device-row-template');
+ var deviceRow = document.importNode(
+ deviceRowTemplate.content.children[0], true /* deep */);
+ deviceRow.id = deviceInfo.address;
+
+ var deviceList = $('device-list');
+ deviceList.appendChild(deviceRow);
+ }
+
+ this.deviceChanged(deviceInfo);
},
/**
- * Logs removed device to console and removes the cached device.
- * @param {!bluetoothDevice.DeviceInfo} device
+ * Marks device as removed.
+ * @param {!bluetoothDevice.DeviceInfo} deviceInfo
*/
deviceRemoved: function(deviceInfo) {
- console.log('Device removed', deviceInfo);
- this.devices_.delete(deviceInfo.address);
+ $(deviceInfo.address).classList.add(REMOVED_CSS);
},
/**
- * Logs changed device info to console and updates the cached device.
+ * Updates cached device and updates the device list.
* @param {!bluetoothDevice.DeviceInfo} deviceInfo
*/
deviceChanged: function(deviceInfo) {
console.log(new Date(), deviceInfo);
- if (this.devices_.has(deviceInfo.address)) {
- this.devices_.get(deviceInfo.address).info = deviceInfo;
- }
+
+ assert(this.devices_.has(deviceInfo.address), 'Device does not exist.');
+
+ this.devices_.get(deviceInfo.address).info = deviceInfo;
+
+ var deviceRow = $(deviceInfo.address);
+ deviceRow.querySelector('.device-name').textContent =
+ deviceInfo.name_for_display;
+ deviceRow.querySelector('.device-address').textContent =
+ deviceInfo.address;
+
+ var rssi = (deviceInfo.rssi && deviceInfo.rssi.value) ||
+ deviceRow.querySelector('.device-rssi').textContent;
+ deviceRow.querySelector('.device-rssi').textContent = rssi;
}
};
@@ -81,8 +107,6 @@
'device/bluetooth/public/interfaces/device.mojom',
'mojo/public/js/connection',
]).then(function([frameInterfaces, ...modules]) {
- console.log('Loaded modules');
-
// Destructure here to assign global variables.
[bluetoothAdapter, bluetoothDevice, connection] = modules;
@@ -117,11 +141,7 @@
.then(function(response) { console.log('adapter', response.info); })
.then(function() { return adapter.getDevices(); })
.then(function(response) {
- console.log('devices', response.devices.length);
-
- response.devices.forEach(function(deviceInfo) {
- adapterClient.deviceAdded(deviceInfo);
- });
+ response.devices.forEach(adapterClient.deviceAdded, adapterClient);
})
.catch(function(error) { console.error(error); });
});
« no previous file with comments | « chrome/browser/resources/bluetooth_internals/bluetooth_internals.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698