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

Unified Diff: chrome/browser/resources/bluetooth_internals/bluetooth_internals.js

Issue 2379573006: bluetooth: Standardize Bluetooth adapter access in Adapter service. (Closed)
Patch Set: dcheng fixes Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | device/bluetooth/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
+ 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); });
});
})();
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | device/bluetooth/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698