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

Unified Diff: device/bluetooth/bluetooth_low_energy_discovery_manager_mac.mm

Issue 1165053003: Adding support for Low Energy device discovery to BluetoothAdapterMac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment nit on SetManagerForTesting. Created 5 years, 6 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_discovery_manager_mac.mm
diff --git a/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.mm b/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.mm
index 11d40caa6261d6a8db61b30986e5b5ab3fcfbe9e..5ba19fcac624570274fa7ed3e9a9205f29038d27 100644
--- a/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.mm
+++ b/device/bluetooth/bluetooth_low_energy_discovery_manager_mac.mm
@@ -79,7 +79,13 @@ class BluetoothLowEnergyDiscoveryManagerMacDelegate {
BluetoothLowEnergyDiscoveryManagerMac::
~BluetoothLowEnergyDiscoveryManagerMac() {
- ClearDevices();
+ // Set the manager's delegate to nil since the object it points to
+ // (|bridge_|) will be deallocated while |manager_| is leaked.
+ if (base::mac::IsOSLionOrLater()) {
+ // CoreBluetooth only available in OSX 10.7 and later.
+ SEL selector = NSSelectorFromString(@"setDelegate:");
+ [manager_ performSelector:selector withObject:nil];
+ }
}
bool BluetoothLowEnergyDiscoveryManagerMac::IsDiscovering() const {
@@ -88,7 +94,6 @@ bool BluetoothLowEnergyDiscoveryManagerMac::IsDiscovering() const {
void BluetoothLowEnergyDiscoveryManagerMac::StartDiscovery(
BluetoothDevice::UUIDList services_uuids) {
- ClearDevices();
discovering_ = true;
pending_ = true;
services_uuids_ = services_uuids;
@@ -137,23 +142,16 @@ void BluetoothLowEnergyDiscoveryManagerMac::DiscoveredPeripheral(
CBPeripheral* peripheral,
NSDictionary* advertisementData,
int rssi) {
- // Look for existing device.
- auto iter = devices_.find(
- BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier(peripheral));
- if (iter == devices_.end()) {
- // A device has been added.
- BluetoothLowEnergyDeviceMac* device =
- new BluetoothLowEnergyDeviceMac(peripheral, advertisementData, rssi);
- devices_.insert(devices_.begin(),
- std::make_pair(device->GetIdentifier(), device));
- observer_->DeviceFound(device);
- return;
- }
+ observer_->LowEnergyDeviceUpdated(peripheral, advertisementData, rssi);
+}
- // A device has an update.
- BluetoothLowEnergyDeviceMac* old_device = iter->second;
- old_device->Update(peripheral, advertisementData, rssi);
- observer_->DeviceUpdated(old_device);
+void BluetoothLowEnergyDiscoveryManagerMac::SetManagerForTesting(
+ CBCentralManager* manager) {
+ // setDelegate is only available in OSX 10.7 and later.
+ CHECK(base::mac::IsOSLionOrLater());
+ SEL selector = NSSelectorFromString(@"setDelegate:");
+ [manager performSelector:selector withObject:bridge_];
+ manager_.reset(manager);
}
BluetoothLowEnergyDiscoveryManagerMac*
@@ -173,10 +171,7 @@ BluetoothLowEnergyDiscoveryManagerMac::BluetoothLowEnergyDiscoveryManagerMac(
manager_.reset(
[[aClass alloc] initWithDelegate:bridge_
queue:dispatch_get_main_queue()]);
+ [manager_ retain];
scheib 2015/06/24 23:24:25 Add a comment here referencing the explanation in
krstnmnlsn 2015/06/24 23:42:26 Done.
}
discovering_ = false;
}
-
-void BluetoothLowEnergyDiscoveryManagerMac::ClearDevices() {
- STLDeleteValues(&devices_);
-}

Powered by Google App Engine
This is Rietveld 408576698