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

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

Issue 2939273002: DO NOT SUBMIT: what chrome/browser/resources/ could eventually look like with clang-format (Closed)
Patch Set: Created 3 years, 6 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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 device_broker, served from chrome://bluetooth-internals/. 6 * Javascript for device_broker, served from chrome://bluetooth-internals/.
7 * Provides a single source to access DevicePtrs. DevicePtrs are cached for 7 * Provides a single source to access DevicePtrs. DevicePtrs are cached for
8 * for repeated use. Multiple connection requests will result in the same 8 * for repeated use. Multiple connection requests will result in the same
9 * DevicePtr being shared among all requesters. 9 * DevicePtr being shared among all requesters.
10 */ 10 */
(...skipping 11 matching lines...) Expand all
22 * DevicePtr. If a connection is in progress, the promise resolves when 22 * DevicePtr. If a connection is in progress, the promise resolves when
23 * the existing connection request promise is fulfilled. 23 * the existing connection request promise is fulfilled.
24 * @param {string} address 24 * @param {string} address
25 * @return {!Promise<!interfaces.BluetoothDevice.DevicePtr>} 25 * @return {!Promise<!interfaces.BluetoothDevice.DevicePtr>}
26 */ 26 */
27 function connectToDevice(address) { 27 function connectToDevice(address) {
28 var deviceOrPromise = connectedDevices.get(address) || null; 28 var deviceOrPromise = connectedDevices.get(address) || null;
29 if (deviceOrPromise !== null) 29 if (deviceOrPromise !== null)
30 return Promise.resolve(deviceOrPromise); 30 return Promise.resolve(deviceOrPromise);
31 31
32 var promise = adapter_broker.getAdapterBroker().then( 32 var promise = adapter_broker.getAdapterBroker()
33 function(adapterBroker) { 33 .then(function(adapterBroker) {
34 return adapterBroker.connectToDevice(address); 34 return adapterBroker.connectToDevice(address);
35 }).then(function(device) { 35 })
36 connectedDevices.set(address, device); 36 .then(function(device) {
37 connectedDevices.set(address, device);
37 38
38 device.ptr.setConnectionErrorHandler(function() { 39 device.ptr.setConnectionErrorHandler(function() {
39 connectedDevices.delete(address); 40 connectedDevices.delete(address);
40 }); 41 });
41 42
42 return device; 43 return device;
43 }).catch(function(error) { 44 })
44 connectedDevices.delete(address); 45 .catch(function(error) {
45 throw error; 46 connectedDevices.delete(address);
46 }); 47 throw error;
48 });
47 49
48 connectedDevices.set(address, promise); 50 connectedDevices.set(address, promise);
49 return promise; 51 return promise;
50 } 52 }
51 53
52 return { 54 return {connectToDevice: connectToDevice};
53 connectToDevice: connectToDevice
54 };
55 }); 55 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698