Chromium Code Reviews| 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 c425fdae82eba9c115b0b085341583ecaf25bb40..950bbdf2a357035e00a08b5f28246aa92f87b7f3 100644 |
| --- a/device/bluetooth/bluetooth_low_energy_device_mac.mm |
| +++ b/device/bluetooth/bluetooth_low_energy_device_mac.mm |
| @@ -8,7 +8,9 @@ |
| #include "base/mac/scoped_cftyperef.h" |
| #include "base/mac/sdk_forward_declarations.h" |
| +#include "base/strings/string_number_conversions.h" |
| #include "base/strings/sys_string_conversions.h" |
| +#include "device/bluetooth/bluetooth_device.h" |
| using device::BluetoothDevice; |
| using device::BluetoothLowEnergyDeviceMac; |
| @@ -66,6 +68,8 @@ BluetoothLowEnergyDeviceMac::BluetoothLowEnergyDeviceMac( |
| CBPeripheral* peripheral, |
| NSDictionary* advertisementData, |
| int rssi) { |
| + identifier_ = GetPeripheralIdentifier(peripheral); |
| + hash_address_ = GetPeripheralHashAddress(peripheral); |
| Update(peripheral, advertisementData, rssi); |
| } |
| @@ -92,7 +96,7 @@ void BluetoothLowEnergyDeviceMac::Update(CBPeripheral* peripheral, |
| } |
| std::string BluetoothLowEnergyDeviceMac::GetIdentifier() const { |
| - return GetPeripheralIdentifier(peripheral_); |
| + return identifier_; |
| } |
| uint32 BluetoothLowEnergyDeviceMac::GetBluetoothClass() const { |
| @@ -100,7 +104,7 @@ uint32 BluetoothLowEnergyDeviceMac::GetBluetoothClass() const { |
| } |
| std::string BluetoothLowEnergyDeviceMac::GetAddress() const { |
| - return std::string(); |
| + return hash_address_; |
| } |
| BluetoothDevice::VendorIDSource BluetoothLowEnergyDeviceMac::GetVendorIDSource() |
| @@ -129,6 +133,10 @@ bool BluetoothLowEnergyDeviceMac::IsPaired() const { |
| } |
| bool BluetoothLowEnergyDeviceMac::IsConnected() const { |
| + // TODO(krstnmnlsn): Remove check once we move to OSX SDK >= 10.9. |
|
scheib
2015/07/01 17:29:44
Rephrase as explaining that isConnected was deprec
krstnmnlsn
2015/07/02 00:25:30
Done.
|
| + if ([peripheral_ respondsToSelector:@selector(state)]) { |
| + return ([peripheral_ state] == CBPeripheralStateConnected); |
| + } |
| return [peripheral_ isConnected]; |
| } |
| @@ -249,3 +257,13 @@ std::string BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier( |
| CFUUIDCreateString(NULL, [peripheral UUID])); |
| return SysCFStringRefToUTF8(str); |
| } |
| + |
| +std::string BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress( |
| + CBPeripheral* peripheral) { |
| + const size_t kCanonicalAddressNumberOfBytes = 6; |
| + char raw[kCanonicalAddressNumberOfBytes] = {0}; |
| + crypto::SHA256HashString(GetPeripheralIdentifier(peripheral), raw, |
| + sizeof(raw)); |
| + std::string hash = base::HexEncode(raw, sizeof(raw)); |
| + return BluetoothDevice::CanonicalizeAddress(hash); |
| +} |