Index: chrome/browser/resources/bluetooth_internals/adapter_broker.js |
diff --git a/chrome/browser/resources/bluetooth_internals/adapter_broker.js b/chrome/browser/resources/bluetooth_internals/adapter_broker.js |
index 13a8eee88c2dda0526287ea5c59a44f8453138a7..fe65eeb74c6452798d6d1a2b228d88d8cd6f705c 100644 |
--- a/chrome/browser/resources/bluetooth_internals/adapter_broker.js |
+++ b/chrome/browser/resources/bluetooth_internals/adapter_broker.js |
@@ -7,6 +7,13 @@ |
* chrome://bluetooth-internals/. |
*/ |
cr.define('adapter_broker', function() { |
+ /** @typedef {interfaces.BluetoothAdapter.Adapter.ptrClass} */ |
+ var AdapterPtr; |
+ /** @typedef {interfaces.BluetoothDevice.Device.ptrClass} */ |
+ var DevicePtr; |
+ /** @typedef {interfaces.BluetoothAdapter.DiscoverySession.ptrClass} */ |
+ var DiscoverySessionPtr; |
+ |
/** |
* The proxy class of an adapter and router of adapter events. |
* Exposes an EventTarget interface that allows other object to subscribe to |
@@ -15,7 +22,7 @@ cr.define('adapter_broker', function() { |
* handles and back when necessary. |
* @constructor |
* @extends {cr.EventTarget} |
- * @param {!interfaces.BluetoothAdapter.AdapterPtr} adapter |
+ * @param {!AdapterPtr} adapter |
*/ |
var AdapterBroker = function(adapter) { |
this.adapter_ = adapter; |
@@ -29,7 +36,7 @@ cr.define('adapter_broker', function() { |
/** |
* Creates a GATT connection to the device with |address|. |
* @param {string} address |
- * @return {!Promise<!interfaces.BluetoothDevice.DevicePtr>} |
+ * @return {!Promise<!DevicePtr>} |
*/ |
connectToDevice: function(address) { |
return this.adapter_.connectToDevice(address).then(function(response) { |
@@ -50,6 +57,22 @@ cr.define('adapter_broker', function() { |
}, |
/** |
+ * Gets an array of currently detectable devices from the Adapter service. |
+ * @return {!Array<!interfaces.BluetoothDevice.DeviceInfo>} |
+ */ |
+ getDevices: function() { |
+ return this.adapter_.getDevices(); |
+ }, |
+ |
+ /** |
+ * Gets the current state of the Adapter. |
+ * @return {!interfaces.BluetoothAdapter.AdapterInfo} |
+ */ |
+ getInfo: function() { |
+ return this.adapter_.getInfo(); |
+ }, |
+ |
+ /** |
* Sets client of Adapter service. |
* @param {!interfaces.BluetoothAdapter.AdapterClient} adapterClient |
*/ |
@@ -63,20 +86,18 @@ cr.define('adapter_broker', function() { |
}, |
/** |
- * Gets an array of currently detectable devices from the Adapter service. |
- * @return {!Array<!interfaces.BluetoothDevice.DeviceInfo>} |
+ * Requests the adapter to start a new discovery session. |
+ * @return {!Promise<!DiscoverySessionPtr>} |
*/ |
- getDevices: function() { |
- return this.adapter_.getDevices(); |
- }, |
+ startDiscoverySession: function() { |
+ return this.adapter_.startDiscoverySession().then(function(response) { |
+ if (!response.session.ptr.isBound()) { |
+ throw new Error('Discovery session failed to start'); |
+ } |
- /** |
- * Gets the current state of the Adapter. |
- * @return {!interfaces.BluetoothAdapter.AdapterInfo} |
- */ |
- getInfo: function() { |
- return this.adapter_.getInfo(); |
- } |
+ return response.session; |
+ }); |
+ }, |
}; |
/** |
@@ -93,6 +114,20 @@ cr.define('adapter_broker', function() { |
AdapterClient.prototype = { |
/** |
+ * Fires adapterchanged event. |
+ * @param {boolean} discovering |
+ */ |
+ discoveringChanged: function(discovering) { |
+ var event = new CustomEvent('adapterchanged', { |
dpapad
2017/01/05 23:30:33
Is this the only case where an 'adapterchanged' ev
mbrunson
2017/01/06 01:18:56
There are a batch of these change events concernin
|
+ detail: { |
+ property: 'discovering', |
+ value: discovering, |
+ } |
+ }); |
+ this.adapterBroker_.dispatchEvent(event); |
+ }, |
+ |
+ /** |
* Fires deviceadded event. |
* @param {!interfaces.BluetoothDevice.DeviceInfo} deviceInfo |
*/ |
@@ -106,11 +141,11 @@ cr.define('adapter_broker', function() { |
}, |
/** |
- * Fires deviceremoved event. |
+ * Fires devicechanged event. |
* @param {!interfaces.BluetoothDevice.DeviceInfo} deviceInfo |
*/ |
- deviceRemoved: function(deviceInfo) { |
- var event = new CustomEvent('deviceremoved', { |
+ deviceChanged: function(deviceInfo) { |
+ var event = new CustomEvent('devicechanged', { |
dpapad
2017/01/05 23:30:33
Nit (optional): I think is more readable if you se
mbrunson
2017/01/06 01:18:56
If I do this I'd want to do this for all the custo
|
detail: { |
deviceInfo: deviceInfo |
} |
@@ -119,17 +154,17 @@ cr.define('adapter_broker', function() { |
}, |
/** |
- * Fires devicechanged event. |
+ * Fires deviceremoved event. |
* @param {!interfaces.BluetoothDevice.DeviceInfo} deviceInfo |
*/ |
- deviceChanged: function(deviceInfo) { |
- var event = new CustomEvent('devicechanged', { |
+ deviceRemoved: function(deviceInfo) { |
+ var event = new CustomEvent('deviceremoved', { |
detail: { |
deviceInfo: deviceInfo |
} |
}); |
this.adapterBroker_.dispatchEvent(event); |
- } |
+ }, |
}; |
var adapterBroker = null; |