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..2c8753ad1b5bf7816247a809b76196e7ddad9ef3 100644 |
--- a/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js |
+++ b/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js |
@@ -33,9 +33,9 @@ AdapterClient.prototype = { |
}; |
(function() { |
+ var adapterFactory = null; |
var adapter = null; |
var adapterClient = null; |
- var adapterClientHandle = null; |
/** |
* TODO: Move to shared location. See crbug.com/652361. |
@@ -53,7 +53,7 @@ AdapterClient.prototype = { |
/** |
* Initializes Mojo proxies for page and Bluetooth services. |
- * @return {!Promise} |
+ * @return {!Promise} resolves if adapter is acquired |
dpapad
2016/10/06 00:52:45
Nit: Use proper punctuation (per styleguide). Also
mbrunson
2016/10/06 01:13:58
Done.
|
*/ |
function initializeProxies() { |
return importModules([ |
@@ -67,22 +67,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); |
+ adapterFactory = connection.bindHandleToProxy( |
dpapad
2016/10/06 00:52:45
Does this need to be global? It is only used withi
mbrunson
2016/10/06 01:13:58
Done.
|
+ frameInterfaces.getInterface(bluetoothAdapter.AdapterFactory.name), |
+ bluetoothAdapter.AdapterFactory); |
+ |
+ // Get an Adapter service. |
+ return adapterFactory.getAdapter().then(function(response) { |
+ 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); }); |
}); |
})(); |