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>} | |
|
dpapad
2016/11/10 19:05:02
!Promise<!...>
mbrunson
2016/11/10 22:02:22
Done.
| |
| 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 errorString = Object.keys( | |
|
dpapad
2016/11/10 19:05:02
Isn't this equivalent to
interfaces.BluetoothAdap
mbrunson
2016/11/10 22:02:22
response.result is a number. ConnectResult is an o
| |
| 41 interfaces.BluetoothAdapter.ConnectResult)[response.result]; | |
| 42 | |
| 43 throw new Error(errorString); | |
| 44 } | |
| 45 | |
| 46 return interfaces.Connection.bindHandleToProxy( | |
| 47 response.device, | |
| 48 interfaces.BluetoothDevice.Device); | |
| 49 }); | |
| 50 }, | |
| 51 | |
| 52 /** | |
| 30 * Sets client of Adapter service. | 53 * Sets client of Adapter service. |
| 31 * @param {!interfaces.BluetoothAdapter.AdapterClient} adapterClient | 54 * @param {!interfaces.BluetoothAdapter.AdapterClient} adapterClient |
| 32 */ | 55 */ |
| 33 setClient: function(adapterClient) { | 56 setClient: function(adapterClient) { |
| 34 this.adapter_.setClient(interfaces.Connection.bindStubDerivedImpl( | 57 this.adapter_.setClient(interfaces.Connection.bindStubDerivedImpl( |
| 35 adapterClient)); | 58 adapterClient)); |
| 36 }, | 59 }, |
| 37 | 60 |
| 38 /** | 61 /** |
| 39 * Gets an array of currently detectable devices from the Adapter service. | 62 * 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 | 161 |
| 139 adapterBroker = new AdapterBroker(adapter); | 162 adapterBroker = new AdapterBroker(adapter); |
| 140 return adapterBroker; | 163 return adapterBroker; |
| 141 }); | 164 }); |
| 142 } | 165 } |
| 143 | 166 |
| 144 return { | 167 return { |
| 145 getAdapterBroker: getAdapterBroker, | 168 getAdapterBroker: getAdapterBroker, |
| 146 }; | 169 }; |
| 147 }); | 170 }); |
| OLD | NEW |