Index: chrome/browser/resources/bluetooth_internals/adapter_broker.js |
diff --git a/chrome/browser/resources/bluetooth_internals/adapter_broker.js b/chrome/browser/resources/bluetooth_internals/adapter_broker.js |
index ae9bfaae28d35ebe689de7cc5ff7634a2ce52976..1cc879d8a507a0c8d5c46ae6d5561c79d1417a29 100644 |
--- a/chrome/browser/resources/bluetooth_internals/adapter_broker.js |
+++ b/chrome/browser/resources/bluetooth_internals/adapter_broker.js |
@@ -27,6 +27,35 @@ cr.define('adapter_broker', function() { |
__proto__: cr.EventTarget.prototype, |
/** |
+ * Creates a GATT connection to the device with |address|. |
+ * @param {string} address |
+ * @return {!Promise<!interfaces.BluetoothDevice.Device.proxyClass>} |
+ */ |
+ connectToDevice: function(address) { |
+ return this.adapter_.connectToDevice(address).then(function(response) { |
+ if (response.result != |
+ interfaces.BluetoothAdapter.ConnectResult.SUCCESS) { |
+ // TODO(crbug.com/663394): Replace with more descriptive error |
+ // messages. |
+ var ConnectResult = interfaces.BluetoothAdapter.ConnectResult; |
+ var errorString = ''; |
ortuno
2016/11/17 03:54:45
var errorString = Object.keys(ConnectResult).find(
mbrunson
2016/11/17 19:33:33
Done.
|
+ for (result in ConnectResult) { |
+ if (response.result === ConnectResult[result]) { |
+ errorString = result; |
+ break; |
+ } |
+ } |
+ |
+ throw new Error(errorString); |
+ } |
+ |
+ return interfaces.Connection.bindHandleToProxy( |
+ response.device, |
+ interfaces.BluetoothDevice.Device); |
+ }); |
+ }, |
+ |
+ /** |
* Sets client of Adapter service. |
* @param {!interfaces.BluetoothAdapter.AdapterClient} adapterClient |
*/ |