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 ba9eedab577539b073adee51cef7bd48698397c6..ca34b67f210640bdccf1a29a20899109039e44c4 100644 |
--- a/device/bluetooth/bluetooth_low_energy_device_mac.mm |
+++ b/device/bluetooth/bluetooth_low_energy_device_mac.mm |
@@ -206,17 +206,18 @@ void BluetoothLowEnergyDeviceMac::DidDiscoverPrimaryServices(NSError* error) { |
if (!gatt_service) { |
gatt_service = new BluetoothRemoteGattServiceMac(this, cb_service, |
true /* is_primary */); |
- auto result_iter = gatt_services_.add(gatt_service->GetIdentifier(), |
- base::WrapUnique(gatt_service)); |
- DCHECK(result_iter.second); |
- adapter_->NotifyGattServiceAdded(gatt_service); |
+ auto insertion = gatt_services_.insert(std::make_pair( |
+ gatt_service->GetIdentifier(), std::move(gatt_service))); |
+ if (!insertion.second) { |
+ VLOG(1) << "Insertion of service failed."; |
+ continue; |
+ } |
+ adapter_->NotifyGattServiceAdded(insertion.first->second.get()); |
} |
} |
- for (GattServiceMap::const_iterator it = gatt_services_.begin(); |
- it != gatt_services_.end(); ++it) { |
- device::BluetoothRemoteGattService* gatt_service = it->second; |
+ for (auto& gatt_service : gatt_services_) { |
device::BluetoothRemoteGattServiceMac* gatt_service_mac = |
- static_cast<BluetoothRemoteGattServiceMac*>(gatt_service); |
+ static_cast<BluetoothRemoteGattServiceMac*>(gatt_service.second.get()); |
gatt_service_mac->DiscoverCharacteristics(); |
} |
} |
@@ -248,8 +249,10 @@ void BluetoothLowEnergyDeviceMac::DidDiscoverCharacteristics( |
bool discovery_complete = |
std::find_if_not( |
gatt_services_.begin(), gatt_services_.end(), |
- [](std::pair<std::string, BluetoothRemoteGattService*> pair) { |
- BluetoothRemoteGattService* gatt_service = pair.second; |
+ [](std::pair<const std::string, |
+ std::unique_ptr<device::BluetoothRemoteGattService>>& |
+ pair) { |
+ BluetoothRemoteGattService* gatt_service = pair.second.get(); |
return static_cast<BluetoothRemoteGattServiceMac*>(gatt_service) |
->IsDiscoveryComplete(); |
}) == gatt_services_.end(); |
@@ -269,8 +272,14 @@ void BluetoothLowEnergyDeviceMac::DidModifyServices( |
GetBluetoothRemoteGattService(cb_service); |
DCHECK(gatt_service); |
VLOG(1) << gatt_service->GetUUID().canonical_value(); |
- std::unique_ptr<BluetoothRemoteGattService> scoped_service = |
- gatt_services_.take_and_erase(gatt_service->GetIdentifier()); |
+ |
+ auto iter = gatt_services_.find(gatt_service->GetIdentifier()); |
+ if (iter == gatt_services_.end()) |
+ return; |
+ |
+ auto scoped_service = std::move(iter->second); |
+ gatt_services_.erase(iter); |
+ |
adapter_->NotifyGattServiceRemoved(scoped_service.get()); |
} |
device_uuids_.ClearServiceUUIDs(); |
@@ -342,7 +351,7 @@ BluetoothLowEnergyDeviceMac::GetBluetoothRemoteGattService( |
CBService* cb_service) const { |
for (GattServiceMap::const_iterator it = gatt_services_.begin(); |
it != gatt_services_.end(); ++it) { |
- device::BluetoothRemoteGattService* gatt_service = it->second; |
+ device::BluetoothRemoteGattService* gatt_service = it->second.get(); |
device::BluetoothRemoteGattServiceMac* gatt_service_mac = |
static_cast<BluetoothRemoteGattServiceMac*>(gatt_service); |
if (gatt_service_mac->GetService() == cb_service) |