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 cd2823c8a02d030c877d948d7ab7dcc88c747c78..c41ca26aaacbb08499ac69861ccc247cc8231761 100644 |
| --- a/device/bluetooth/bluetooth_low_energy_device_mac.mm |
| +++ b/device/bluetooth/bluetooth_low_energy_device_mac.mm |
| @@ -6,6 +6,7 @@ |
| #import <CoreFoundation/CoreFoundation.h> |
| +#include "base/mac/mac_util.h" |
| #include "base/mac/scoped_cftyperef.h" |
| #include "base/mac/sdk_forward_declarations.h" |
| #include "base/strings/sys_string_conversions.h" |
| @@ -15,48 +16,11 @@ using device::BluetoothLowEnergyDeviceMac; |
| namespace { |
| -// Converts a CBUUID to a Cocoa string. |
| -// |
| -// The string representation can have the following formats: |
| -// - 16 bit: xxxx |
| -// - 128 bit: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| -// CBUUID supports only 16 bits and 128 bits formats. |
| -// |
| -// In OSX < 10.10, -[uuid UUIDString] method is not implemented. It's why we |
| -// need to provide this function. |
| -NSString* stringWithCBUUID(CBUUID* uuid) { |
| - NSData* data = [uuid data]; |
| - |
| - NSUInteger bytesToConvert = [data length]; |
| - const unsigned char* uuidBytes = (const unsigned char*)[data bytes]; |
| - NSMutableString* outputString = [NSMutableString stringWithCapacity:16]; |
| - |
| - for (NSUInteger currentByteIndex = 0; currentByteIndex < bytesToConvert; |
| - currentByteIndex++) { |
| - switch (currentByteIndex) { |
| - case 3: |
| - case 5: |
| - case 7: |
| - case 9: |
| - [outputString appendFormat:@"%02x-", uuidBytes[currentByteIndex]]; |
| - break; |
| - default: |
| - [outputString appendFormat:@"%02x", uuidBytes[currentByteIndex]]; |
| - } |
| - } |
| - return outputString; |
| -} |
| - |
| // Converts a CBUUID to a BluetoothUUID. |
| device::BluetoothUUID BluetoothUUIDWithCBUUID(CBUUID* uuid) { |
| - NSString* uuidString = nil; |
| - // TODO(dvh): Remove this once we moved to OSX SDK >= 10.10. |
| - if ([uuid respondsToSelector:@selector(UUIDString)]) { |
| - uuidString = [uuid UUIDString]; |
| - } else { |
| - uuidString = stringWithCBUUID(uuid); |
| - } |
| - std::string uuid_c_string = base::SysNSStringToUTF8(uuidString); |
| + // UUIDString only available OS X >= 10.8. |
| + CHECK(base::mac::IsOSMountainLionOrLater()); |
| + std::string uuid_c_string = base::SysNSStringToUTF8([uuid UUIDString]); |
| return device::BluetoothUUID(uuid_c_string); |
| } |
| @@ -66,6 +30,9 @@ BluetoothLowEnergyDeviceMac::BluetoothLowEnergyDeviceMac( |
| CBPeripheral* peripheral, |
| NSDictionary* advertisementData, |
| int rssi) { |
| + // For stability we only use CoreBluetooth on OS X >= 10.10. Thus |
| + // BluetoothLowEnergyDeviceMac should only be instantiated if on >= 10.10. |
| + CHECK(base::mac::IsOSYosemiteOrLater()); |
| Update(peripheral, advertisementData, rssi); |
| } |
| @@ -237,15 +204,9 @@ std::string BluetoothLowEnergyDeviceMac::GetDeviceName() const { |
| std::string BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier( |
|
scheib
2015/07/09 19:51:23
Add a "// static" comment line above this method.
krstnmnlsn
2015/07/10 17:17:46
Done.
|
| CBPeripheral* peripheral) { |
| - // TODO(dvh): Remove this once we moved to OSX SDK >= 10.9. |
| - if ([peripheral respondsToSelector:@selector(identifier)]) { |
| - // When -[CBPeripheral identifier] is available. |
| - NSUUID* uuid = [peripheral identifier]; |
| - NSString* uuidString = [uuid UUIDString]; |
| - return base::SysNSStringToUTF8(uuidString); |
| - } |
| - |
| - base::ScopedCFTypeRef<CFStringRef> str( |
| - CFUUIDCreateString(NULL, [peripheral UUID])); |
| - return SysCFStringRefToUTF8(str); |
| + // For stability we only use CoreBluetooth on OS X >= 10.10. |
| + CHECK(base::mac::IsOSYosemiteOrLater()); |
| + NSUUID* uuid = [peripheral identifier]; |
| + NSString* uuidString = [uuid UUIDString]; |
| + return base::SysNSStringToUTF8(uuidString); |
| } |