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

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

Issue 2622393002: bluetooth: Add characteristic list to DeviceDetailsPage in internals page. (Closed)
Patch Set: Remove unneeded tests Created 3 years, 11 months 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * Javascript for device_broker, served from chrome://bluetooth-internals/.
7 * Provides a single source to access DevicePtrs. DevicePtrs are cached for
8 * for repeated use. Multiple connections may occur if subsequent requests are
9 * made before the first request is resolved. In this case, the connection is
10 * dropped.
11 */
12
13 // Expose for testing.
14 /** @type {!Map<string, !interfaces.BluetoothDevice.DevicePtr>} */
15 var connectedDevices = null;
16
17 cr.define('device_broker', function() {
18 connectedDevices = new Map();
19
20 /**
21 * Creates a GATT connection to the device with |address|. If a connection to
22 * the device already exists, the promise is resolved with the existing
23 * DeviceBroker.
24 * @param {string} address
25 * @return {!Promise<!DeviceBroker>}
26 */
27 function connectToDevice(address) {
28 if (connectedDevices.has(address))
dpapad 2017/01/19 02:01:47 Is this function meant to call adapterBroker.conne
mbrunson 2017/01/19 03:22:20 I was less concerned about connection requests in
29 return Promise.resolve(connectedDevices.get(address));
30
31 return adapter_broker.getAdapterBroker().then(function(adapterBroker) {
dpapad 2017/01/19 02:01:47 Chain instead of nesting, as follows ... retu
mbrunson 2017/01/19 03:22:20 What function is "return adapter_broker.getAdapter
dpapad 2017/01/19 17:41:45 Ack. I misread the diff.
32 return adapterBroker.connectToDevice(address);
33 }).then(function(device) {
34 // If multiple connections occur, only use the first active connection.
35 if (connectedDevices.has(address)) {
36 device.disconnect();
37 return connectedDevices.get(address);
38 }
39
40 device.ptr.setConnectionErrorHandler(function() {
41 connectedDevices.delete(address);
42 });
43
44 connectedDevices.set(address, device);
45 return device;
46 });
47 }
48
49 return {
50 connectToDevice: connectToDevice
51 };
52 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698