Commit 24139de9 authored by Kazuhiro Inaba's avatar Kazuhiro Inaba Committed by Commit Bot

bluetooth: Make the pairing dialog aware of BT address change.

This CL plumbs the address change event to the Web UI dialog,
so that it can listen all the necessary events even after the
address has changed, and take appropriate response (like
automatically closing the dialog after the pairing is established.).

BUG=1045310
TEST=ARC++ CTSVerifer BLE Secure Client test (see the bug for the detail)

Change-Id: I023404adf561d6da2ac1148470a15b9e57b8ea1a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2016775Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Commit-Queue: Kazuhiro Inaba <kinaba@chromium.org>
Auto-Submit: Kazuhiro Inaba <kinaba@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738753}
parent 71d38f8f
......@@ -101,6 +101,9 @@ cr.define('settings', function() {
/** @type {!FakeChromeEvent} */
onPairing: new FakeChromeEvent(),
/** @type {!FakeChromeEvent} */
onDeviceAddressChanged: new FakeChromeEvent(),
};
return {FakeBluetoothPrivate: FakeBluetoothPrivate};
......
......@@ -383,6 +383,29 @@ void BluetoothEventRouter::DeviceRemoved(device::BluetoothAdapter* adapter,
bluetooth::OnDeviceRemoved::kEventName, device);
}
void BluetoothEventRouter::DeviceAddressChanged(
device::BluetoothAdapter* adapter,
device::BluetoothDevice* device,
const std::string& old_address) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (adapter != adapter_.get()) {
BLUETOOTH_LOG(DEBUG) << "Ignoring event for adapter "
<< adapter->GetAddress();
return;
}
DCHECK(device);
bluetooth::Device extension_device;
bluetooth::BluetoothDeviceToApiDevice(*device, &extension_device);
std::unique_ptr<base::ListValue> args =
bt_private::OnDeviceAddressChanged::Create(extension_device, old_address);
auto event = std::make_unique<Event>(
events::BLUETOOTH_PRIVATE_ON_DEVICE_ADDRESS_CHANGED,
bt_private::OnDeviceAddressChanged::kEventName, std::move(args));
EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event));
}
void BluetoothEventRouter::OnListenerAdded(const EventListenerInfo& details) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
std::string id = GetListenerId(details);
......
......@@ -115,6 +115,9 @@ class BluetoothEventRouter : public device::BluetoothAdapter::Observer,
device::BluetoothDevice* device) override;
void DeviceRemoved(device::BluetoothAdapter* adapter,
device::BluetoothDevice* device) override;
void DeviceAddressChanged(device::BluetoothAdapter* adapter,
device::BluetoothDevice* device,
const std::string& old_address) override;
// Overridden from content::NotificationObserver.
void Observe(int type,
......
......@@ -469,6 +469,7 @@ enum HistogramValue {
TERMINAL_PRIVATE_ON_SETTINGS_CHANGED = 447,
AUTOFILL_ASSISTANT_PRIVATE_ON_ACTIONS_CHANGED = 448,
AUTOFILL_ASSISTANT_PRIVATE_ON_STATUS_MESSAGE_CHANGED = 449,
BLUETOOTH_PRIVATE_ON_DEVICE_ADDRESS_CHANGED = 450,
// Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY
......
......@@ -170,5 +170,9 @@ namespace bluetoothPrivate {
// Fired when a pairing event occurs.
// |pairingEvent|: A pairing event.
[maxListeners=1] static void onPairing(PairingEvent pairingEvent);
// Fired when a Bluetooth device changed its address.
static void onDeviceAddressChanged(bluetooth.Device device,
DOMString oldAddress);
};
};
......@@ -185,3 +185,9 @@ chrome.bluetoothPrivate.recordDeviceSelection = function(selectionDurationMs, wa
* @type {!ChromeEvent}
*/
chrome.bluetoothPrivate.onPairing;
/**
* Fired when a Bluetooth device changed its address.
* @type {!ChromeEvent}
*/
chrome.bluetoothPrivate.onDeviceAddressChanged;
......@@ -78,3 +78,10 @@ BluetoothPrivate.prototype = {
* @see https://developer.chrome.com/extensions/bluetoothPrivate#event-onPairing
*/
BluetoothPrivate.prototype.onPairing;
/**
* Fired when a Bluetooth device changed its address.
* @type {!ChromeEvent}
* @see https://developer.chrome.com/extensions/bluetoothPrivate#event-onDeviceAddressChanged
*/
BluetoothPrivate.prototype.onDeviceAddressChanged;
......@@ -20683,6 +20683,7 @@ to ensure that the crash string is shown properly on the user-facing crash UI.
<int value="448" label="AUTOFILL_ASSISTANT_PRIVATE_ON_ACTIONS_CHANGED"/>
<int value="449"
label="AUTOFILL_ASSISTANT_PRIVATE_ON_STATUS_MESSAGE_CHANGED"/>
<int value="450" label="BLUETOOTH_PRIVATE_ON_DEVICE_ADDRESS_CHANGED"/>
</enum>
<enum name="ExtensionFileWriteResult">
......@@ -120,6 +120,12 @@ Polymer({
*/
bluetoothPrivateOnPairingListener_: null,
/**
* Listener for chrome.bluetoothPrivate.deviceAddressChanged events.
* @private {?function(!chrome.bluetooth.Device, !string)}
*/
bluetoothPrivateDeviceAddressChangedListener_: null,
/**
* Listener for chrome.bluetooth.onBluetoothDeviceChanged events.
* @private {?function(!chrome.bluetooth.Device)}
......@@ -233,6 +239,12 @@ Polymer({
this.connectionAttemptStartTimestampMs_ = Date.now();
}
if (!this.bluetoothPrivateDeviceAddressChangedListener_) {
this.bluetoothPrivateDeviceAddressChangedListener_ =
this.onBluetoothPrivateDeviceAddressChanged_.bind(this);
this.bluetoothPrivate.onDeviceAddressChanged.addListener(
this.bluetoothPrivateDeviceAddressChangedListener_);
}
if (!this.bluetoothDeviceChangedListener_) {
this.bluetoothDeviceChangedListener_ =
this.onBluetoothDeviceChanged_.bind(this);
......@@ -248,6 +260,11 @@ Polymer({
this.bluetoothPrivateOnPairingListener_);
this.bluetoothPrivateOnPairingListener_ = null;
}
if (this.bluetoothPrivateDeviceAddressChangedListener_) {
this.bluetoothPrivate.onDeviceAddressChanged.removeListener(
this.bluetoothPrivateDeviceAddressChangedListener_);
this.bluetoothPrivateDeviceAddressChangedListener_ = null;
}
if (this.bluetoothDeviceChangedListener_) {
this.bluetooth.onDeviceChanged.removeListener(
this.bluetoothDeviceChangedListener_);
......@@ -275,6 +292,19 @@ Polymer({
this.pairingEvent_ = event;
},
/**
* Process bluetoothPrivate.onDeviceAddressChanged events.
* @param {!chrome.bluetooth.Device} device
* @param {!string} oldAddress
* @private
*/
onBluetoothPrivateDeviceAddressChanged_(device, oldAddress) {
if (!this.pairingDevice || oldAddress !== this.pairingDevice.address) {
return;
}
this.pairingDevice = device;
},
/**
* Process bluetooth.onDeviceChanged events. This ensures that the dialog
* updates when the connection state changes.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment