Chromium Code Reviews| Index: device/bluetooth/bluetooth_gatt_connection.cc |
| diff --git a/device/bluetooth/bluetooth_gatt_connection.cc b/device/bluetooth/bluetooth_gatt_connection.cc |
| index 721391e8d1a803db0aa87aa76d5d89b583a5b950..b0670372479903021e7eafd558aa24277f5489ed 100644 |
| --- a/device/bluetooth/bluetooth_gatt_connection.cc |
| +++ b/device/bluetooth/bluetooth_gatt_connection.cc |
| @@ -4,12 +4,43 @@ |
| #include "device/bluetooth/bluetooth_gatt_connection.h" |
| +#include "device/bluetooth/bluetooth_adapter.h" |
| + |
| namespace device { |
| -BluetoothGattConnection::BluetoothGattConnection() { |
| +BluetoothGattConnection::BluetoothGattConnection( |
| + BluetoothAdapter* adapter, |
| + const std::string& device_address) |
| + : adapter_(adapter), device_address_(device_address) { |
| + DCHECK(adapter_.get()); |
| + DCHECK(!device_address_.empty()); |
| + |
| + BluetoothDevice* device = adapter_->GetDevice(device_address_); |
| + if (device) |
|
Jeffrey Yasskin
2015/08/19 22:49:45
If !device, IsConnected() should probably return f
scheib
2015/09/13 02:40:28
Done.
|
| + device->IncrementGattConnectionReferenceCount(); |
| } |
| BluetoothGattConnection::~BluetoothGattConnection() { |
| + Disconnect(); |
| +} |
| + |
| +std::string BluetoothGattConnection::GetDeviceAddress() const { |
|
Jeffrey Yasskin
2015/08/19 22:49:46
Return a const std::string&?
scheib
2015/09/13 02:40:28
Done.
|
| + return device_address_; |
| +} |
| + |
| +bool BluetoothGattConnection::IsConnected() { |
| + return !already_decremented_connection_reference_on_device_ && |
| + adapter_->GetDevice(device_address_)->IsGattConnected(); |
|
Jeffrey Yasskin
2015/08/19 22:49:46
This leads to an interesting situation where:
1) w
Jeffrey Yasskin
2015/08/19 22:49:46
Do you need to check for adapter_->GetDevice() ret
scheib
2015/09/13 02:40:28
Done - refactored reference counting to have point
scheib
2015/09/13 02:40:28
Done.
|
| +} |
| + |
| +void BluetoothGattConnection::Disconnect() { |
| + if (already_decremented_connection_reference_on_device_) |
| + return; |
| + |
| + already_decremented_connection_reference_on_device_ = true; |
| + BluetoothDevice* device = adapter_->GetDevice(device_address_); |
| + if (device) |
| + device->DecrementGattConnectionReferenceCount(); |
| } |
| } // namespace device |