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 84c2b85ab7f84b847c2edbf463bc1984755b26ff..8929f724a27ce73f98e97d7757a189a21bb3413f 100644 |
--- a/chrome/browser/resources/bluetooth_internals/device_collection.js |
+++ b/chrome/browser/resources/bluetooth_internals/device_collection.js |
@@ -32,6 +32,7 @@ cr.define('device_collection', function() { |
} |
return null; |
}, |
+ |
/** |
* Adds or updates a Device with new DeviceInfo. |
* @param {!interfaces.bluetoothDevice.DeviceInfo} deviceInfo |
@@ -53,11 +54,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)); |
} |
}; |
@@ -70,6 +77,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.ConnectErrorCode.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.ConnectErrorCode)[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, |