Chromium Code Reviews| Index: content/browser/bluetooth/frame_connected_bluetooth_devices.cc |
| diff --git a/content/browser/bluetooth/frame_connected_bluetooth_devices.cc b/content/browser/bluetooth/frame_connected_bluetooth_devices.cc |
| index 7187609453ccdabce09be39b060ad456eceadbfe..722c4f04cc6b56bb8ffb0e64e0aa6ecf3d04598a 100644 |
| --- a/content/browser/bluetooth/frame_connected_bluetooth_devices.cc |
| +++ b/content/browser/bluetooth/frame_connected_bluetooth_devices.cc |
| @@ -25,49 +25,28 @@ FrameConnectedBluetoothDevices::~FrameConnectedBluetoothDevices() { |
| bool FrameConnectedBluetoothDevices::IsConnectedToDeviceWithId( |
| const WebBluetoothDeviceId& device_id) { |
| - auto connection_iter = device_id_to_connection_map_.find(device_id); |
| - if (connection_iter == device_id_to_connection_map_.end()) { |
| + if (device_id_to_connection_map_.find(device_id) == |
| + device_id_to_connection_map_.end()) { |
| return false; |
| } |
| - // Owners of FrameConnectedBluetoothDevices should notify it when a device |
| - // disconnects but currently Android and Mac don't notify of disconnection, |
| - // so the map could get into a state where it's holding a stale connection. |
| - // For this reason we return the value of IsConnected for the connection. |
| - // TODO(ortuno): Always return true once Android and Mac notify of |
| - // disconnection. |
| - // http://crbug.com/607273 |
| - return connection_iter->second->IsConnected(); |
| + return true; |
|
ortuno
2017/02/23 02:27:03
nit: could we add a DCHECK?
DCHECK(connection_iter
juncai
2017/02/23 04:53:41
Done.
|
| } |
| void FrameConnectedBluetoothDevices::Insert( |
| const WebBluetoothDeviceId& device_id, |
| std::unique_ptr<device::BluetoothGattConnection> connection) { |
| - auto connection_iter = device_id_to_connection_map_.find(device_id); |
| - if (connection_iter != device_id_to_connection_map_.end()) { |
| - // Owners of FrameConnectedBluetoothDevices should notify it when a device |
| - // disconnects but currently Android and Mac don't notify of disconnection, |
| - // so the map could get into a state where it's holding a stale connection. |
| - // For this reason we check if the current connection is active and if |
| - // not we remove it. |
| - // TODO(ortuno): Remove once Android and Mac notify of disconnection. |
| - // http://crbug.com/607273 |
| - if (!connection_iter->second->IsConnected()) { |
| - device_address_to_id_map_.erase( |
| - connection_iter->second->GetDeviceAddress()); |
| - device_id_to_connection_map_.erase(connection_iter); |
| - DecrementDevicesConnectedCount(); |
| - } else { |
| - // It's possible for WebBluetoothServiceImpl to issue two successive |
| - // connection requests for which it would get two successive responses |
| - // and consequently try to insert two BluetoothGattConnections for the |
| - // same device. WebBluetoothServiceImpl should reject or queue connection |
| - // requests if there is a pending connection already, but the platform |
| - // abstraction doesn't currently support checking for pending connections. |
| - // TODO(ortuno): CHECK that this never happens once the platform |
| - // abstraction allows to check for pending connections. |
| - // http://crbug.com/583544 |
| - return; |
| - } |
| + if (device_id_to_connection_map_.find(device_id) != |
| + device_id_to_connection_map_.end()) { |
| + // It's possible for WebBluetoothServiceImpl to issue two successive |
| + // connection requests for which it would get two successive responses |
| + // and consequently try to insert two BluetoothGattConnections for the |
| + // same device. WebBluetoothServiceImpl should reject or queue connection |
| + // requests if there is a pending connection already, but the platform |
| + // abstraction doesn't currently support checking for pending connections. |
| + // TODO(ortuno): CHECK that this never happens once the platform |
| + // abstraction allows to check for pending connections. |
| + // http://crbug.com/583544 |
| + return; |
| } |
| device_address_to_id_map_[connection->GetDeviceAddress()] = device_id; |
| device_id_to_connection_map_[device_id] = std::move(connection); |