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 ab62448c12433f64117e8a262ef5bf030596ab47..0a6f9d8d1bd991385149ddc43118f631b7b5bda5 100644 |
--- a/chrome/browser/resources/bluetooth_internals/device_collection.js |
+++ b/chrome/browser/resources/bluetooth_internals/device_collection.js |
@@ -31,6 +31,7 @@ cr.define('device_collection', function() { |
} |
return null; |
}, |
+ |
/** |
* Adds or updates a Device with new DeviceInfo. |
* @param {!interfaces.BluetoothDevice.DeviceInfo} deviceInfo |
@@ -52,11 +53,17 @@ cr.define('device_collection', function() { |
this.push(device); |
} |
}, |
+ |
+ /** |
+ * Marks the Device as removed. |
+ * @param {!interfaces.bluetoothDevice.DeviceInfo} deviceInfo |
+ */ |
remove: function(deviceInfo) { |
var device = this.getByAddress(deviceInfo.address); |
assert(device, |
'Device does not exist.'); |
device.removed = true; |
+ this.updateIndex(this.indexOf(device)); |
} |
}; |
@@ -69,6 +76,43 @@ cr.define('device_collection', function() { |
this.info = info; |
this.removed = false; |
}; |
+ Device.prototype = { |
+ /** |
+ * Creates a connection to the device and updates the service listing. |
+ * @return {Promise} rejects if connection failed, resolves otherwise. |
+ */ |
+ connect: function() { |
+ return interfaces.DefaultAdapter.connectToDevice( |
+ this.info.address).then( |
+ function(response) { |
+ if (response.error == |
+ interfaces.BluetoothAdapter.ConnectResult.SUCCESS) { |
+ this.proxy = interfaces.Connection.bindHandleToProxy( |
+ response.device, |
+ interfaces.BluetoothDevice.Device); |
+ return this.proxy.getServices(); |
+ } |
+ |
+ // TODO(mbrunson): Replace with more descriptive error messages. |
+ var errorString = Object.keys( |
+ interfaces.BluetoothAdapter.ConnectResult)[response.error]; |
+ |
+ throw new Error(errorString); |
+ }.bind(this)).then(function(response) { |
+ this.info.services = response.services; |
+ }.bind(this)); |
+ }, |
+ |
+ /** |
+ * Disconnects a device and removes the Device interface proxy. |
+ */ |
+ disconnect: function() { |
+ if (this.proxy) { |
+ this.proxy.disconnect(); |
+ this.proxy = null; |
+ } |
+ } |
+ }; |
return { |
DeviceCollection, DeviceCollection, |