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

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

Issue 2401193002: bluetooth: Add Device service for chrome://bluetooth-internals. (Closed)
Patch Set: Fully qualify mojom import 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
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 961b15d5a7ce860ba34b4c4ea103d7b054ed5725..b9af7fb9c83e1c876d8d6555e259545d87b986da 100644
--- a/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js
+++ b/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js
@@ -15,28 +15,22 @@ var AdapterClient = function() {};
AdapterClient.prototype = {
/**
* Prints added device to console.
- * @param {!Object} device the device that was added
+ * @param {!bluetoothDevice.DeviceInfo} device
*/
- deviceAdded: function(device) {
- console.log('Device added');
- console.log(device);
- },
+ deviceAdded: function(device) { console.log('Device added', device); },
/**
* Prints removed device to console.
- * @param {!Object} device the device that was removed
+ * @param {!bluetoothDevice.DeviceInfo} device
*/
- deviceRemoved: function(device) {
- console.log('Device removed');
- console.log(device);
- }
+ deviceRemoved: function(device) { console.log('Device removed', device); }
};
(function() {
- var adapter, adapterClient;
+ var adapter, adapterClient, bluetoothAdapter, bluetoothDevice, connection;
/**
- * TODO: Move to shared location. See http://crbug.com/652361.
+ * TODO(crbug.com/652361): Move to shared location.
* Helper to convert callback-based define() API to a promise-based API.
* @param {!Array<string>} moduleNames
* @return {!Promise}
@@ -58,10 +52,14 @@ AdapterClient.prototype = {
return importModules([
'content/public/renderer/frame_interfaces',
'device/bluetooth/public/interfaces/adapter.mojom',
+ 'device/bluetooth/public/interfaces/device.mojom',
'mojo/public/js/connection',
- ]).then(function([frameInterfaces, bluetoothAdapter, connection]) {
+ ]).then(function([frameInterfaces, ...modules]) {
console.log('Loaded modules');
+ // Destructure here to assign global variables.
+ [bluetoothAdapter, bluetoothDevice, connection] = modules;
+
// Hook up the instance properties.
AdapterClient.prototype.__proto__ =
bluetoothAdapter.AdapterClient.stubClass.prototype;
@@ -71,28 +69,55 @@ AdapterClient.prototype = {
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(response.adapter,
- bluetoothAdapter.Adapter);
-
- // 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));
- });
+ return adapterFactory.getAdapter();
+ }).then(function(response) {
+ if (!response.adapter) {
+ throw new Error('Bluetooth Not Supported on this platform.');
+ }
+
+ adapter = connection.bindHandleToProxy(response.adapter,
+ bluetoothAdapter.Adapter);
+
+ // 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));
});
}
+ /**
+ * Prints device info from the device service.
+ * @param {!bluetoothDevice.DeviceInfo} deviceInfo the device for which to
+ * get the information.
+ * @return {!Promise} resolves if device service is retrieved, rejects
+ * otherwise.
+ */
+ function logDevice(deviceInfo) {
+ return adapter.getDevice(deviceInfo.address).then(function(response) {
+ var deviceHandle = response.device;
+ if (!deviceHandle) {
+ throw new Error(deviceInfo.name_for_display + ' cannot be found.');
+ }
+
+ var device = connection.bindHandleToProxy(
+ deviceHandle, bluetoothDevice.Device);
+ return device.getInfo();
+ }).then(function(response) {
+ console.log(deviceInfo.name_for_display, response.info);
+ });
+ }
+
document.addEventListener('DOMContentLoaded', function() {
initializeProxies()
- .then(function() {return adapter.getInfo(); })
- .then(function(response) { console.log('info', response.info); })
+ .then(function() { return adapter.getInfo(); })
+ .then(function(response) { console.log('adapter', response.info); })
.then(function() { return adapter.getDevices(); })
- .then(function(response) { console.log('devices', response.devices); })
+ .then(function(response) {
+ var devices = response.devices;
+ console.log('devices', devices.length);
+
+ return Promise.all(devices.map(logDevice));
+ })
.catch(function(error) { console.error(error); });
});
})();
« no previous file with comments | « chrome/browser/browser_resources.grd ('k') | chrome/browser/ui/webui/bluetooth_internals/bluetooth_internals_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698