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 4d86d99c79d47e972aa809d210f54b8a59528384..ba352790cf138d80b4441c509527482bc3b16376 100644 |
--- a/chrome/browser/resources/bluetooth_internals/device_collection.js |
+++ b/chrome/browser/resources/bluetooth_internals/device_collection.js |
@@ -76,6 +76,44 @@ cr.define('device_collection', function() { |
var Device = function(info) { |
this.info = info; |
this.removed = false; |
+ this.connectionPending = false; |
+ }; |
+ Device.prototype = { |
+ /** |
+ * Creates a connection to the device and updates the service listing. |
+ * @return {Promise} rejects if connection failed, resolves otherwise. |
+ */ |
+ connect: function() { |
+ this.connectionPending = true; |
+ return adapter_broker.getAdapterBroker().then(function(broker) { |
+ return broker.connectToDevice(this.info.address); |
+ }.bind(this)).then(function(response) { |
+ this.connectionPending = false; |
+ if (response.error == |
ortuno
2016/11/08 04:38:02
I would move this (if (response.error)... throw ne
mbrunson
2016/11/08 22:45:12
Done.
|
+ interfaces.BluetoothAdapter.ConnectResult.SUCCESS) { |
+ this.proxy = response.device; |
+ return this.proxy.getServices(); |
+ } |
+ |
+ // TODO(mbrunson): Replace with more descriptive error messages. |
ortuno
2016/11/08 04:38:02
TODOs are usually used when there are other depend
mbrunson
2016/11/08 22:45:12
Ok. I'll make an issue. Done.
|
+ 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 { |