Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Javascript for AdapterBroker, served from | 6 * Javascript for AdapterBroker, served from |
| 7 * chrome://bluetooth-internals/. | 7 * chrome://bluetooth-internals/. |
| 8 */ | 8 */ |
| 9 cr.define('adapter_broker', function() { | 9 cr.define('adapter_broker', function() { |
| 10 /** | 10 /** |
| 11 * The proxy class of an adapter and router of adapter events. | 11 * The proxy class of an adapter and router of adapter events. |
| 12 * Exposes an EventTarget interface that allows other object to subscribe to | 12 * Exposes an EventTarget interface that allows other object to subscribe to |
| 13 * to specific AdapterClient events. | 13 * to specific AdapterClient events. |
| 14 * Provides proxy access to Adapter functions. Converts parameters to Mojo | 14 * Provides proxy access to Adapter functions. Converts parameters to Mojo |
| 15 * handles and back when necessary. | 15 * handles and back when necessary. |
| 16 * @constructor | 16 * @constructor |
| 17 * @extends {cr.EventTarget} | 17 * @extends {cr.EventTarget} |
| 18 * @param {!interfaces.BluetoothAdapter.Adapter.proxyClass} adapter | 18 * @param {!interfaces.BluetoothAdapter.Adapter.proxyClass} adapter |
| 19 */ | 19 */ |
| 20 var AdapterBroker = function(adapter) { | 20 var AdapterBroker = function(adapter) { |
| 21 this.adapter_ = adapter; | 21 this.adapter_ = adapter; |
| 22 this.adapterClient_ = new AdapterClient(this); | 22 this.adapterClient_ = new AdapterClient(this); |
| 23 this.setClient(this.adapterClient_); | 23 this.setClient(this.adapterClient_); |
| 24 }; | 24 }; |
| 25 | 25 |
| 26 AdapterBroker.prototype = { | 26 AdapterBroker.prototype = { |
| 27 __proto__: cr.EventTarget.prototype, | 27 __proto__: cr.EventTarget.prototype, |
| 28 | 28 |
| 29 /** | 29 /** |
| 30 * Creates a GATT connection to the device with |address|. | |
| 31 * @param {string} address | |
| 32 * @return {!Promise<!interfaces.BluetoothDevice.Device.proxyClass>} | |
| 33 */ | |
| 34 connectToDevice: function(address) { | |
| 35 return this.adapter_.connectToDevice(address).then(function(response) { | |
| 36 if (response.result != | |
| 37 interfaces.BluetoothAdapter.ConnectResult.SUCCESS) { | |
| 38 // TODO(crbug.com/663394): Replace with more descriptive error | |
| 39 // messages. | |
| 40 var ConnectResult = interfaces.BluetoothAdapter.ConnectResult; | |
| 41 var errorString = ''; | |
|
ortuno
2016/11/17 03:54:45
var errorString = Object.keys(ConnectResult).find(
mbrunson
2016/11/17 19:33:33
Done.
| |
| 42 for (result in ConnectResult) { | |
| 43 if (response.result === ConnectResult[result]) { | |
| 44 errorString = result; | |
| 45 break; | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 throw new Error(errorString); | |
| 50 } | |
| 51 | |
| 52 return interfaces.Connection.bindHandleToProxy( | |
| 53 response.device, | |
| 54 interfaces.BluetoothDevice.Device); | |
| 55 }); | |
| 56 }, | |
| 57 | |
| 58 /** | |
| 30 * Sets client of Adapter service. | 59 * Sets client of Adapter service. |
| 31 * @param {!interfaces.BluetoothAdapter.AdapterClient} adapterClient | 60 * @param {!interfaces.BluetoothAdapter.AdapterClient} adapterClient |
| 32 */ | 61 */ |
| 33 setClient: function(adapterClient) { | 62 setClient: function(adapterClient) { |
| 34 this.adapter_.setClient(interfaces.Connection.bindStubDerivedImpl( | 63 this.adapter_.setClient(interfaces.Connection.bindStubDerivedImpl( |
| 35 adapterClient)); | 64 adapterClient)); |
| 36 }, | 65 }, |
| 37 | 66 |
| 38 /** | 67 /** |
| 39 * Gets an array of currently detectable devices from the Adapter service. | 68 * Gets an array of currently detectable devices from the Adapter service. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 | 167 |
| 139 adapterBroker = new AdapterBroker(adapter); | 168 adapterBroker = new AdapterBroker(adapter); |
| 140 return adapterBroker; | 169 return adapterBroker; |
| 141 }); | 170 }); |
| 142 } | 171 } |
| 143 | 172 |
| 144 return { | 173 return { |
| 145 getAdapterBroker: getAdapterBroker, | 174 getAdapterBroker: getAdapterBroker, |
| 146 }; | 175 }; |
| 147 }); | 176 }); |
| OLD | NEW |