Index: content/renderer/bluetooth/web_bluetooth_impl.cc |
diff --git a/content/renderer/bluetooth/web_bluetooth_impl.cc b/content/renderer/bluetooth/web_bluetooth_impl.cc |
index 49358d0bdb28e33e6ce5bb5a008e0586f355f699..d1efd830ad03cbcb4b4eca4b3a1c6503c3b48f28 100644 |
--- a/content/renderer/bluetooth/web_bluetooth_impl.cc |
+++ b/content/renderer/bluetooth/web_bluetooth_impl.cc |
@@ -183,8 +183,12 @@ void WebBluetoothImpl::OnRequestDeviceComplete( |
void WebBluetoothImpl::GattServerDisconnected(const mojo::String& device_id) { |
auto device_iter = connected_devices_.find(device_id); |
if (device_iter != connected_devices_.end()) { |
- device_iter->second->dispatchGattServerDisconnected(); |
+ // Remove device from the map before calling dispatchGattServerDisconnected |
+ // to avoid removing a device the gattserverdisconnected event handler might |
+ // have re-connected. |
+ blink::WebBluetoothDevice* device = device_iter->second; |
connected_devices_.erase(device_iter); |
+ device->dispatchGattServerDisconnected(); |
} |
} |