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

Unified Diff: device/bluetooth/bluez/bluetooth_device_bluez.cc

Issue 2567903004: Replace ScopedVector/ScopedPtrHashMap with std::vector and std::unordered_map (Closed)
Patch Set: Mac bustage 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/bluez/bluetooth_device_bluez.cc
diff --git a/device/bluetooth/bluez/bluetooth_device_bluez.cc b/device/bluetooth/bluez/bluetooth_device_bluez.cc
index 273169fb091696278867a6f09fefd502eb658689..1de611f8368a25122593af6abd35d5de3b078b57 100644
--- a/device/bluetooth/bluez/bluetooth_device_bluez.cc
+++ b/device/bluetooth/bluez/bluetooth_device_bluez.cc
@@ -180,7 +180,7 @@ BluetoothDeviceBlueZ::~BluetoothDeviceBlueZ() {
for (const auto& iter : gatt_services_swapped) {
DCHECK(adapter());
adapter()->NotifyGattServiceRemoved(
- static_cast<BluetoothRemoteGattServiceBlueZ*>(iter.second));
+ static_cast<BluetoothRemoteGattServiceBlueZ*>(iter.second.get()));
}
}
@@ -675,41 +675,47 @@ void BluetoothDeviceBlueZ::GattServiceAdded(
VLOG(1) << "Adding new remote GATT service for device: " << GetAddress();
- BluetoothRemoteGattServiceBlueZ* service =
- new BluetoothRemoteGattServiceBlueZ(adapter(), this, object_path);
-
- gatt_services_.set(service->GetIdentifier(),
- std::unique_ptr<BluetoothRemoteGattService>(service));
- DCHECK(service->object_path() == object_path);
- DCHECK(service->GetUUID().IsValid());
+ std::unique_ptr<device::BluetoothRemoteGattService> service(
+ new BluetoothRemoteGattServiceBlueZ(adapter(), this, object_path));
+ auto insertion = gatt_services_.insert(
+ std::make_pair(service->GetIdentifier(), std::move(service)));
+ if (!insertion.second) {
+ // insertion failed.
+ VLOG(1) << "Insertion of new remote GATT service failed for device: "
+ << GetAddress();
+ return;
+ }
+ BluetoothRemoteGattServiceBlueZ* bluez =
+ static_cast<BluetoothRemoteGattServiceBlueZ*>(
+ insertion.first->second.get());
+ DCHECK(bluez->object_path() == object_path);
+ DCHECK(bluez->GetUUID().IsValid());
DCHECK(adapter());
- adapter()->NotifyGattServiceAdded(service);
+ adapter()->NotifyGattServiceAdded(bluez);
}
void BluetoothDeviceBlueZ::GattServiceRemoved(
const dbus::ObjectPath& object_path) {
- GattServiceMap::const_iterator iter =
- gatt_services_.find(object_path.value());
+ auto iter = gatt_services_.find(object_path.value());
if (iter == gatt_services_.end()) {
VLOG(3) << "Unknown GATT service removed: " << object_path.value();
return;
}
-
- BluetoothRemoteGattServiceBlueZ* service =
- static_cast<BluetoothRemoteGattServiceBlueZ*>(iter->second);
-
+ // Hold onto the service so that we can erase it safely.
+ auto scoped_service = std::move(iter->second);
+ gatt_services_.erase(iter);
+ discovery_complete_notified_.erase(scoped_service.get());
+
+ BluetoothRemoteGattServiceBlueZ* bluez =
+ static_cast<BluetoothRemoteGattServiceBlueZ*>(scoped_service.get());
+ DCHECK(bluez->object_path() == object_path);
VLOG(1) << "Removing remote GATT service with UUID: '"
- << service->GetUUID().canonical_value()
+ << scoped_service->GetUUID().canonical_value()
<< "' from device: " << GetAddress();
- DCHECK(service->object_path() == object_path);
- std::unique_ptr<BluetoothRemoteGattService> scoped_service =
- gatt_services_.take_and_erase(iter->first);
-
DCHECK(adapter());
- discovery_complete_notified_.erase(service);
- adapter()->NotifyGattServiceRemoved(service);
+ adapter()->NotifyGattServiceRemoved(scoped_service.get());
}
void BluetoothDeviceBlueZ::UpdateGattServices(

Powered by Google App Engine
This is Rietveld 408576698