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

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

Issue 2448713002: bluetooth: Add Device connection logic and accompanying user interface. (Closed)
Patch Set: Remove binding variable in Device.Create Created 4 years, 1 month 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/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 4057293273bc1ddaa7726553896bef63b21fd86d..5059c3ece81068daacbf4feaf00a18ca5a0af98a 100644
--- a/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js
+++ b/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js
@@ -8,6 +8,10 @@
*/
cr.define('bluetooth_internals', function() {
+
+ /** @type {!Map<string, !interfaces.BluetoothDevice.Device.proxyClass>} */
+ var deviceAddressToProxy = new Map();
+
function initializeViews() {
var adapterBroker = null;
adapter_broker.getAdapterBroker()
@@ -32,6 +36,49 @@ cr.define('bluetooth_internals', function() {
devices /* this */);
var deviceTable = new device_table.DeviceTable();
+
+ deviceTable.addEventListener('inspectpressed', function(event) {
+ // TODO(crbug.com/663470): Move connection logic to DeviceDetailsView
+ // when it's added in chrome://bluetooth-internals.
+ var address = event.detail.address;
+ var proxy = deviceAddressToProxy.get(address);
+
+ if (proxy) {
+ // Device is already connected, so disconnect.
+ proxy.disconnect();
+ deviceAddressToProxy.delete(address);
+ devices.updateConnectionStatus(
+ address, device_collection.ConnectionStatus.DISCONNECTED);
+ return;
+ }
+
+ devices.updateConnectionStatus(
+ address, device_collection.ConnectionStatus.CONNECTING);
+ adapterBroker.connectToDevice(address).then(function(deviceProxy) {
+ if (!devices.getByAddress(address)) {
+ // Device no longer in list, so drop the connection.
+ deviceProxy.disconnect();
+ return;
+ }
+
+ deviceAddressToProxy.set(address, deviceProxy);
+ devices.updateConnectionStatus(
+ address, device_collection.ConnectionStatus.CONNECTED);
+
+ // Fetch services asynchronously.
+ return deviceProxy.getServices();
+ }).then(function(response) {
+ var deviceInfo = devices.getByAddress(address);
+ deviceInfo.services = response.services;
+ devices.addOrUpdate(deviceInfo);
+ }).catch(function(error) {
+ devices.updateConnectionStatus(
+ address,
+ device_collection.ConnectionStatus.DISCONNECTED,
+ error);
+ });
+ });
+
deviceTable.setDevices(devices);
document.body.appendChild(deviceTable);
})

Powered by Google App Engine
This is Rietveld 408576698