Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: chrome/browser/resources/bluetooth_internals/adapter_broker.js

Issue 2448713002: bluetooth: Add Device connection logic and accompanying user interface. (Closed)
Patch Set: Remove binding variable in Device.Create Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 = Object.keys(ConnectResult).find(function(key) {
42 return ConnectResult[key] === response.result;
43 });
44
45 throw new Error(errorString);
46 }
47
48 return interfaces.Connection.bindHandleToProxy(
49 response.device,
50 interfaces.BluetoothDevice.Device);
51 });
52 },
53
54 /**
30 * Sets client of Adapter service. 55 * Sets client of Adapter service.
31 * @param {!interfaces.BluetoothAdapter.AdapterClient} adapterClient 56 * @param {!interfaces.BluetoothAdapter.AdapterClient} adapterClient
32 */ 57 */
33 setClient: function(adapterClient) { 58 setClient: function(adapterClient) {
34 this.adapter_.setClient(interfaces.Connection.bindStubDerivedImpl( 59 this.adapter_.setClient(interfaces.Connection.bindStubDerivedImpl(
35 adapterClient)); 60 adapterClient));
36 }, 61 },
37 62
38 /** 63 /**
39 * Gets an array of currently detectable devices from the Adapter service. 64 * Gets an array of currently detectable devices from the Adapter service.
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 163
139 adapterBroker = new AdapterBroker(adapter); 164 adapterBroker = new AdapterBroker(adapter);
140 return adapterBroker; 165 return adapterBroker;
141 }); 166 });
142 } 167 }
143 168
144 return { 169 return {
145 getAdapterBroker: getAdapterBroker, 170 getAdapterBroker: getAdapterBroker,
146 }; 171 };
147 }); 172 });
OLDNEW
« no previous file with comments | « chrome/browser/browser_resources.grd ('k') | chrome/browser/resources/bluetooth_internals/bluetooth_internals.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698