Commit fcca36a5 authored by ejcaruso's avatar ejcaruso Committed by Commit bot

arc/bluetooth: Save BluetoothGattConnection objects

When we make outbound GATT connections, we were immediately
letting them expire in OnGattConnected, which meant we would
disconnect remote devices as soon as they were connected to us.

BUG=644792
TEST=make GATT connections from inside the container and
  verify that they stay connected, disconnect and verify that
  the device is disconnected

Review-Url: https://codereview.chromium.org/2321693002
Cr-Commit-Position: refs/heads/master@{#417097}
parent 6a10e693
......@@ -943,7 +943,9 @@ void ArcBluetoothBridge::OnGattConnectStateChanged(
void ArcBluetoothBridge::OnGattConnected(
mojom::BluetoothAddressPtr addr,
std::unique_ptr<BluetoothGattConnection> connection) const {
std::unique_ptr<BluetoothGattConnection> connection) {
DCHECK(CalledOnValidThread());
gatt_connections_[addr->To<std::string>()] = std::move(connection);
OnGattConnectStateChanged(std::move(addr), true);
}
......@@ -954,7 +956,16 @@ void ArcBluetoothBridge::OnGattConnectError(
}
void ArcBluetoothBridge::OnGattDisconnected(
mojom::BluetoothAddressPtr addr) const {
mojom::BluetoothAddressPtr addr) {
DCHECK(CalledOnValidThread());
auto it = gatt_connections_.find(addr->To<std::string>());
if (it == gatt_connections_.end()) {
LOG(WARNING) << "OnGattDisconnected called, "
<< "but no gatt connection was found";
} else {
gatt_connections_.erase(it);
}
OnGattConnectStateChanged(std::move(addr), false);
}
......
......@@ -291,11 +291,11 @@ class ArcBluetoothBridge
bool connected) const;
void OnGattConnected(
mojom::BluetoothAddressPtr addr,
std::unique_ptr<device::BluetoothGattConnection> connection) const;
std::unique_ptr<device::BluetoothGattConnection> connection);
void OnGattConnectError(
mojom::BluetoothAddressPtr addr,
device::BluetoothDevice::ConnectErrorCode error_code) const;
void OnGattDisconnected(mojom::BluetoothAddressPtr addr) const;
void OnGattDisconnected(mojom::BluetoothAddressPtr addr);
void OnStartLEListenDone(const StartLEListenCallback& callback,
scoped_refptr<device::BluetoothAdvertisement> adv);
......@@ -385,6 +385,12 @@ class ArcBluetoothBridge
int32_t gatt_server_attribute_next_handle_ = 0;
// Keeps track of all devices which initiated a GATT connection to us.
std::unordered_set<std::string> gatt_connection_cache_;
// Map of device address to GATT connection objects for connections we
// have made. We need to hang on to these as long as the connection is
// active since their destructors will drop the connections otherwise.
std::unordered_map<std::string,
std::unique_ptr<device::BluetoothGattConnection>>
gatt_connections_;
// Timer to turn adapter discoverable off.
base::OneShotTimer discoverable_off_timer_;
......
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