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

Unified Diff: device/bluetooth/bluetooth_low_energy_device_mac.mm

Issue 2567903004: Replace ScopedVector/ScopedPtrHashMap with std::vector and std::unordered_map (Closed)
Patch Set: Replace ScopedVector/ScopedPtrHashMap with std::vector and std::unordered_map Created 4 years 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 ba9eedab577539b073adee51cef7bd48698397c6..1f4287fbe9a71f554a56e0cb626da039566e09bd 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,13 +249,15 @@ 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();
if (discovery_complete) {
- device_uuids_.ReplaceServiceUUIDs(gatt_services_);
+ device_uuids_.ReplaceServiceUUIDs(*(gatt_services_.get()));
Reilly Grant (use Gerrit) 2016/12/21 22:25:14 no parenthesis needed
dougt 2016/12/22 01:18:02 Done.
SetGattServicesDiscoveryComplete(true);
adapter_->NotifyGattServicesDiscovered(this);
adapter_->NotifyDeviceChanged(this);
@@ -269,8 +272,15 @@ 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;
+ }
Reilly Grant (use Gerrit) 2016/12/21 22:25:14 no braces around single-line if
dougt 2016/12/22 01:18:02 Done.
+
+ auto scoped_service = std::move(iter->second);
+ gatt_services_.erase(iter);
+
adapter_->NotifyGattServiceRemoved(scoped_service.get());
}
device_uuids_.ClearServiceUUIDs();
@@ -342,7 +352,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)

Powered by Google App Engine
This is Rietveld 408576698