Chromium Code Reviews| Index: chrome/browser/resources/bluetooth_internals/bluetooth_internals.js |
| diff --git a/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js b/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js |
| index 23f02c3329b4a650c37ba5233bcaae368860b965..0e48aa25c64ef9b23d5efb3c9c96394d11db3d51 100644 |
| --- a/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js |
| +++ b/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js |
| @@ -33,9 +33,7 @@ AdapterClient.prototype = { |
| }; |
| (function() { |
| - var adapter = null; |
| - var adapterClient = null; |
| - var adapterClientHandle = null; |
| + var adapter, adapterClient; |
| /** |
| * TODO: Move to shared location. See crbug.com/652361. |
| @@ -53,7 +51,8 @@ AdapterClient.prototype = { |
| /** |
| * Initializes Mojo proxies for page and Bluetooth services. |
| - * @return {!Promise} |
| + * @return {!Promise} resolves if adapter is acquired, rejects if Bluetooth |
| + * is not supported. |
| */ |
| function initializeProxies() { |
| return importModules([ |
| @@ -67,22 +66,31 @@ AdapterClient.prototype = { |
| AdapterClient.prototype.__proto__ = |
| bluetoothAdapter.AdapterClient.stubClass.prototype; |
| - // Create a message pipe and bind one end to client |
| - // implementation. |
| - adapterClient = new AdapterClient(); |
| - adapterClientHandle = connection.bindStubDerivedImpl(adapterClient); |
| + var adapterFactory = connection.bindHandleToProxy( |
| + frameInterfaces.getInterface(bluetoothAdapter.AdapterFactory.name), |
| + bluetoothAdapter.AdapterFactory); |
| + |
| + // Get an Adapter service. |
| + return adapterFactory.getAdapter().then(function(response) { |
|
dpapad
2016/10/06 17:13:32
Nit (optional): You could avoid nesting Promise ca
mbrunson
2016/10/06 20:25:57
This will be used in a future patch.
|
| + if (!response.adapter) { |
| + throw new Error('Bluetooth Not Supported on this platform.'); |
| + } |
| - adapter = connection.bindHandleToProxy( |
| - frameInterfaces.getInterface(bluetoothAdapter.Adapter.name), |
| - bluetoothAdapter.Adapter); |
| + adapter = connection.bindHandleToProxy(response.adapter, |
| + bluetoothAdapter.Adapter); |
| - adapter.setClient(adapterClientHandle); |
| + // Create a message pipe and bind one end to client |
| + // implementation and the other to the Adapter service. |
| + adapterClient = new AdapterClient(); |
| + adapter.setClient(connection.bindStubDerivedImpl(adapterClient)); |
| + }); |
| }); |
| } |
| document.addEventListener('DOMContentLoaded', function() { |
| initializeProxies() |
| .then(function() { return adapter.getDevices(); }) |
| - .then(function(response) { console.log(response.devices); }); |
| + .then(function(response) { console.log(response.devices); }) |
| + .catch(function(error) { console.error(error); }); |
| }); |
| })(); |