From ad0d07421f17d5d822994cf906412f0d9788d500 Mon Sep 17 00:00:00 2001 From: jlebel Date: Tue, 23 Feb 2016 19:38:59 -0800 Subject: Chrome doesn't need to compile on 10.6, cleaning up the code BUG= Review URL: https://codereview.chromium.org/1712183002 Cr-Commit-Position: refs/heads/master@{#377208} --- device/bluetooth/bluetooth_adapter_mac.mm | 6 +-- device/bluetooth/bluetooth_low_energy_device_mac.h | 3 -- .../bluetooth/bluetooth_low_energy_device_mac.mm | 16 +------- .../bluetooth_low_energy_discovery_manager_mac.mm | 3 +- device/bluetooth/bluetooth_socket_mac.mm | 48 ++++++++++------------ device/bluetooth/test/bluetooth_test_mac.mm | 8 ++-- 6 files changed, 30 insertions(+), 54 deletions(-) (limited to 'device') diff --git a/device/bluetooth/bluetooth_adapter_mac.mm b/device/bluetooth/bluetooth_adapter_mac.mm index 72554ed..76dad60 100644 --- a/device/bluetooth/bluetooth_adapter_mac.mm +++ b/device/bluetooth/bluetooth_adapter_mac.mm @@ -82,8 +82,7 @@ BluetoothAdapterMac::BluetoothAdapterMac() [[BluetoothLowEnergyCentralManagerDelegate alloc] initWithDiscoveryManager:low_energy_discovery_manager_.get() andAdapter:this]); - Class aClass = NSClassFromString(@"CBCentralManager"); - low_energy_central_manager_.reset([[aClass alloc] + low_energy_central_manager_.reset([[CBCentralManager alloc] initWithDelegate:low_energy_central_manager_delegate_.get() queue:dispatch_get_main_queue()]); low_energy_discovery_manager_->SetCentralManager( @@ -225,8 +224,7 @@ bool BluetoothAdapterMac::IsLowEnergyAvailable() { void BluetoothAdapterMac::SetCentralManagerForTesting( CBCentralManager* central_manager) { CHECK(BluetoothAdapterMac::IsLowEnergyAvailable()); - [central_manager performSelector:@selector(setDelegate:) - withObject:low_energy_central_manager_delegate_]; + central_manager.delegate = low_energy_central_manager_delegate_; low_energy_central_manager_.reset(central_manager); low_energy_discovery_manager_->SetCentralManager( low_energy_central_manager_.get()); diff --git a/device/bluetooth/bluetooth_low_energy_device_mac.h b/device/bluetooth/bluetooth_low_energy_device_mac.h index 19cbb01..f2517dd 100644 --- a/device/bluetooth/bluetooth_low_energy_device_mac.h +++ b/device/bluetooth/bluetooth_low_energy_device_mac.h @@ -108,9 +108,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothLowEnergyDeviceMac friend class BluetoothAdapterMac; friend class BluetoothAdapterMacTest; - // Equivalent to [peripheral_ state]. Allows compilation on OS X 10.6. - CBPeripheralState GetPeripheralState() const; - // CoreBluetooth data structure. base::scoped_nsobject peripheral_; diff --git a/device/bluetooth/bluetooth_low_energy_device_mac.mm b/device/bluetooth/bluetooth_low_energy_device_mac.mm index 677c595..ac0357e 100644 --- a/device/bluetooth/bluetooth_low_energy_device_mac.mm +++ b/device/bluetooth/bluetooth_low_energy_device_mac.mm @@ -119,7 +119,7 @@ bool BluetoothLowEnergyDeviceMac::IsConnected() const { } bool BluetoothLowEnergyDeviceMac::IsGattConnected() const { - return (GetPeripheralState() == CBPeripheralStateConnected); + return ([peripheral_ state] == CBPeripheralStateConnected); } bool BluetoothLowEnergyDeviceMac::IsConnectable() const { @@ -258,17 +258,3 @@ std::string BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress( std::string hash = base::HexEncode(raw, sizeof(raw)); return BluetoothDevice::CanonicalizeAddress(hash); } - -CBPeripheralState BluetoothLowEnergyDeviceMac::GetPeripheralState() const { - Class peripheral_class = NSClassFromString(@"CBPeripheral"); - base::scoped_nsobject signature([[peripheral_class - instanceMethodSignatureForSelector:@selector(state)] retain]); - base::scoped_nsobject invocation( - [[NSInvocation invocationWithMethodSignature:signature] retain]); - [invocation setTarget:peripheral_]; - [invocation setSelector:@selector(state)]; - [invocation invoke]; - CBPeripheralState state = CBPeripheralStateDisconnected; - [invocation getReturnValue:&state]; - return state; -} diff --git a/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.mm b/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.mm index d14b578..5a0dbe9 100644 --- a/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.mm +++ b/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.mm @@ -57,8 +57,7 @@ void BluetoothLowEnergyDiscoveryManagerMac::TryStartDiscovery() { for (auto& service_uuid : services_uuids_) { NSString* uuidString = base::SysUTF8ToNSString(service_uuid.canonical_value().c_str()); - Class aClass = NSClassFromString(@"CBUUID"); - CBUUID* uuid = [aClass UUIDWithString:uuidString]; + CBUUID* uuid = [CBUUID UUIDWithString:uuidString]; [services addObject:uuid]; } }; diff --git a/device/bluetooth/bluetooth_socket_mac.mm b/device/bluetooth/bluetooth_socket_mac.mm index c82e5d2..235168a 100644 --- a/device/bluetooth/bluetooth_socket_mac.mm +++ b/device/bluetooth/bluetooth_socket_mac.mm @@ -264,7 +264,7 @@ IOBluetoothSDPUUID* GetIOBluetoothSDPUUID(const BluetoothUUID& uuid) { // Converts the given |integer| to a string. NSString* IntToNSString(int integer) { - return [[NSNumber numberWithInt:integer] stringValue]; + return [@(integer) stringValue]; } // Returns a dictionary containing the Bluetooth service definition @@ -305,20 +305,17 @@ NSDictionary* BuildRfcommServiceDefinition( const BluetoothUUID& uuid, const BluetoothAdapter::ServiceOptions& options) { int channel_id = options.channel ? *options.channel : kInvalidRfcommChannelId; - NSArray* rfcomm_protocol_definition = - @[ - @[ - [IOBluetoothSDPUUID uuid16:kBluetoothSDPUUID16L2CAP] - ], - @[ - [IOBluetoothSDPUUID uuid16:kBluetoothSDPUUID16RFCOMM], - @{ - @"DataElementType": @1, // Unsigned integer. - @"DataElementSize": @1, // 1 byte. - @"DataElementValue": [NSNumber numberWithInt:channel_id] - } - ] - ]; + NSArray* rfcomm_protocol_definition = @[ + @[ [IOBluetoothSDPUUID uuid16:kBluetoothSDPUUID16L2CAP] ], + @[ + [IOBluetoothSDPUUID uuid16:kBluetoothSDPUUID16RFCOMM], + @{ + @"DataElementType" : @1, // Unsigned integer. + @"DataElementSize" : @1, // 1 byte. + @"DataElementValue" : @(channel_id), + }, + ], + ]; return BuildServiceDefinition( uuid, options.name.get(), rfcomm_protocol_definition); } @@ -329,17 +326,16 @@ NSDictionary* BuildL2capServiceDefinition( const BluetoothUUID& uuid, const BluetoothAdapter::ServiceOptions& options) { int psm = options.psm ? *options.psm : kInvalidL2capPsm; - NSArray* l2cap_protocol_definition = - @[ - @[ - [IOBluetoothSDPUUID uuid16:kBluetoothSDPUUID16L2CAP], - @{ - @"DataElementType": @1, // Unsigned integer. - @"DataElementSize": @2, // 2 bytes. - @"DataElementValue": [NSNumber numberWithInt:psm] - } - ] - ]; + NSArray* l2cap_protocol_definition = @[ + @[ + [IOBluetoothSDPUUID uuid16:kBluetoothSDPUUID16L2CAP], + @{ + @"DataElementType" : @1, // Unsigned integer. + @"DataElementSize" : @2, // 2 bytes. + @"DataElementValue" : @(psm), + }, + ], + ]; return BuildServiceDefinition( uuid, options.name.get(), l2cap_protocol_definition); } diff --git a/device/bluetooth/test/bluetooth_test_mac.mm b/device/bluetooth/test/bluetooth_test_mac.mm index 110e9f9..d64b5f7 100644 --- a/device/bluetooth/test/bluetooth_test_mac.mm +++ b/device/bluetooth/test/bluetooth_test_mac.mm @@ -127,7 +127,7 @@ BluetoothDevice* BluetoothTestMac::DiscoverLowEnergyDevice(int device_ordinal) { [central_manager_delegate centralManager:central_manager didDiscoverPeripheral:peripheral advertisementData:advertisement_data - RSSI:[NSNumber numberWithInt:0]]; + RSSI:@(0)]; break; } case 2: { @@ -147,7 +147,7 @@ BluetoothDevice* BluetoothTestMac::DiscoverLowEnergyDevice(int device_ordinal) { [central_manager_delegate centralManager:central_manager didDiscoverPeripheral:peripheral advertisementData:advertisement_data - RSSI:[NSNumber numberWithInt:0]]; + RSSI:@(0)]; break; } case 3: { @@ -160,7 +160,7 @@ BluetoothDevice* BluetoothTestMac::DiscoverLowEnergyDevice(int device_ordinal) { [central_manager_delegate centralManager:central_manager didDiscoverPeripheral:peripheral advertisementData:advertisement_data - RSSI:[NSNumber numberWithInt:0]]; + RSSI:@(0)]; break; } case 4: { @@ -173,7 +173,7 @@ BluetoothDevice* BluetoothTestMac::DiscoverLowEnergyDevice(int device_ordinal) { [central_manager_delegate centralManager:central_manager didDiscoverPeripheral:peripheral advertisementData:advertisement_data - RSSI:[NSNumber numberWithInt:0]]; + RSSI:@(0)]; break; } } -- cgit v1.1