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

Unified Diff: content/browser/bluetooth/frame_connected_bluetooth_devices.cc

Issue 2718583002: Refactor WebBluetoothServiceClient in the web_bluetooth.mojom (Closed)
Patch Set: address comments Created 3 years, 10 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: 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 d469a50f0e21b21d3ad3b963c5ebdad13b2a93bd..d218a9cb8b17e585dc5a17dbcca410badf783ae4 100644
--- a/content/browser/bluetooth/frame_connected_bluetooth_devices.cc
+++ b/content/browser/bluetooth/frame_connected_bluetooth_devices.cc
@@ -29,13 +29,14 @@ bool FrameConnectedBluetoothDevices::IsConnectedToDeviceWithId(
if (connection_iter == device_id_to_connection_map_.end()) {
return false;
}
- DCHECK(connection_iter->second->IsConnected());
+ DCHECK(connection_iter->second.first->IsConnected());
return true;
}
void FrameConnectedBluetoothDevices::Insert(
const WebBluetoothDeviceId& device_id,
- std::unique_ptr<device::BluetoothGattConnection> connection) {
+ std::unique_ptr<device::BluetoothGattConnection> connection,
+ blink::mojom::WebBluetoothServerClientAssociatedPtr client) {
if (device_id_to_connection_map_.find(device_id) !=
device_id_to_connection_map_.end()) {
// It's possible for WebBluetoothServiceImpl to issue two successive
@@ -50,7 +51,8 @@ void FrameConnectedBluetoothDevices::Insert(
return;
}
device_address_to_id_map_[connection->GetDeviceAddress()] = device_id;
- device_id_to_connection_map_[device_id] = std::move(connection);
+ device_id_to_connection_map_[device_id] =
+ std::make_pair(std::move(connection), std::move(client));
IncrementDevicesConnectedCount();
}
@@ -61,7 +63,7 @@ void FrameConnectedBluetoothDevices::CloseConnectionToDeviceWithId(
return;
}
CHECK(device_address_to_id_map_.erase(
- connection_iter->second->GetDeviceAddress()));
+ connection_iter->second.first->GetDeviceAddress()));
device_id_to_connection_map_.erase(connection_iter);
DecrementDevicesConnectedCount();
}
@@ -74,8 +76,13 @@ FrameConnectedBluetoothDevices::CloseConnectionToDeviceWithAddress(
return base::nullopt;
}
WebBluetoothDeviceId device_id = device_address_iter->second;
+ auto device_id_iter = device_id_to_connection_map_.find(device_id);
+ CHECK(device_id_iter != device_id_to_connection_map_.end());
+ if (device_id_iter->second.second) {
ortuno 2017/03/01 04:52:05 When would a device have a connection but no clien
juncai 2017/03/02 03:23:38 In the test code at: frame_connected_bluetooth_dev
ortuno 2017/03/06 11:31:20 hmm we should try to avoid polluting prod code bec
juncai 2017/03/09 07:30:56 Done.
+ device_id_iter->second.second->GattServerDisconnected();
+ }
CHECK(device_address_to_id_map_.erase(device_address));
- CHECK(device_id_to_connection_map_.erase(device_id));
+ device_id_to_connection_map_.erase(device_id);
DecrementDevicesConnectedCount();
return base::make_optional(device_id);
}

Powered by Google App Engine
This is Rietveld 408576698