Index: device/bluetooth/bluetooth_low_energy_device_mac.mm |
diff --git a/device/bluetooth/bluetooth_low_energy_device_mac.mm b/device/bluetooth/bluetooth_low_energy_device_mac.mm |
index 00712ae82ec1b4ab14a06c81423cad36c31ffc22..d0f3f3dc29d2d5f464cfe057d9d28d44204f4e79 100644 |
--- a/device/bluetooth/bluetooth_low_energy_device_mac.mm |
+++ b/device/bluetooth/bluetooth_low_energy_device_mac.mm |
@@ -43,6 +43,9 @@ BluetoothLowEnergyDeviceMac::BluetoothLowEnergyDeviceMac( |
} |
BluetoothLowEnergyDeviceMac::~BluetoothLowEnergyDeviceMac() { |
+ if (IsGattConnected()) { |
+ GetMacAdapter()->DisconnectGatt(this); |
+ } |
} |
void BluetoothLowEnergyDeviceMac::Update(CBPeripheral* peripheral, |
@@ -134,7 +137,7 @@ bool BluetoothLowEnergyDeviceMac::IsConnectable() const { |
} |
bool BluetoothLowEnergyDeviceMac::IsConnecting() const { |
- return false; |
+ return ([peripheral_ state] == CBPeripheralStateConnecting); |
} |
BluetoothDevice::UUIDList BluetoothLowEnergyDeviceMac::GetUUIDs() const { |
@@ -220,12 +223,6 @@ void BluetoothLowEnergyDeviceMac::ConnectToServiceInsecurely( |
NOTIMPLEMENTED(); |
} |
-void BluetoothLowEnergyDeviceMac::CreateGattConnection( |
- const GattConnectionCallback& callback, |
- const ConnectErrorCallback& error_callback) { |
- NOTIMPLEMENTED(); |
-} |
- |
NSDate* BluetoothLowEnergyDeviceMac::GetLastUpdateTime() const { |
return last_update_time_.get(); |
} |
@@ -235,15 +232,13 @@ std::string BluetoothLowEnergyDeviceMac::GetDeviceName() const { |
} |
void BluetoothLowEnergyDeviceMac::CreateGattConnectionImpl() { |
- // Mac implementation does not yet use the default CreateGattConnection |
- // implementation. http://crbug.com/520774 |
- NOTIMPLEMENTED(); |
+ if (!IsGattConnected()) { |
+ GetMacAdapter()->CreateGattConnection(this); |
+ } |
} |
void BluetoothLowEnergyDeviceMac::DisconnectGatt() { |
- // Mac implementation does not yet use the default CreateGattConnection |
- // implementation. http://crbug.com/520774 |
- NOTIMPLEMENTED(); |
+ GetMacAdapter()->DisconnectGatt(this); |
} |
// static |
@@ -265,3 +260,19 @@ std::string BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress( |
std::string hash = base::HexEncode(raw, sizeof(raw)); |
return BluetoothDevice::CanonicalizeAddress(hash); |
} |
+ |
+device::BluetoothAdapterMac* BluetoothLowEnergyDeviceMac::GetMacAdapter() { |
+ return static_cast<BluetoothAdapterMac*>(this->adapter_); |
+} |
+ |
+CBPeripheral* BluetoothLowEnergyDeviceMac::GetPeripheral() { |
+ return peripheral_; |
+} |
+ |
+void BluetoothLowEnergyDeviceMac::DidDisconnectPeripheral() { |
+ if (create_gatt_connection_error_callbacks_.empty()) { |
+ DidDisconnectGatt(); |
+ } else { |
+ DidFailToConnectGatt(ERROR_FAILED); |
+ } |
+} |