Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(872)

Unified Diff: device/bluetooth/bluetooth_low_energy_device_mac.mm

Issue 1228863002: Runtime checks so that CoreBluetooth only used on >= 10.10 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@timeinfo
Patch Set: CHECK->DCHECK Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..d86e9f7794911a25bf09fa9d1fad7b1e10fc8dc9 100644
--- a/device/bluetooth/bluetooth_low_energy_device_mac.mm
+++ b/device/bluetooth/bluetooth_low_energy_device_mac.mm
@@ -6,57 +6,22 @@
#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"
+#include "device/bluetooth/bluetooth_adapter_mac.h"
using device::BluetoothDevice;
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.
+ DCHECK(base::mac::IsOSMountainLionOrLater());
+ std::string uuid_c_string = base::SysNSStringToUTF8([uuid UUIDString]);
return device::BluetoothUUID(uuid_c_string);
}
@@ -66,6 +31,7 @@ BluetoothLowEnergyDeviceMac::BluetoothLowEnergyDeviceMac(
CBPeripheral* peripheral,
NSDictionary* advertisementData,
int rssi) {
+ DCHECK(BluetoothAdapterMac::IsLowEnergyAvailable());
Update(peripheral, advertisementData, rssi);
}
@@ -235,17 +201,11 @@ std::string BluetoothLowEnergyDeviceMac::GetDeviceName() const {
return base::SysNSStringToUTF8([peripheral_ name]);
}
+// static
std::string BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier(
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);
+ DCHECK(BluetoothAdapterMac::IsLowEnergyAvailable());
+ NSUUID* uuid = [peripheral identifier];
+ NSString* uuidString = [uuid UUIDString];
+ return base::SysNSStringToUTF8(uuidString);
}
« no previous file with comments | « device/bluetooth/bluetooth_adapter_mac_unittest.mm ('k') | device/bluetooth/bluetooth_low_energy_discovery_manager_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698