Chromium Code Reviews| 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..645fde30f791f154309f42ff5c23cb16caf9d182 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; |
| + } |
|
Reilly Grant (use Gerrit)
2016/12/21 22:25:15
It does seem like the existing pattern in most pla
|
| + 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. |
|
Reilly Grant (use Gerrit)
2016/12/21 22:25:15
Sentences begin with a capital letter.
dougt
2016/12/22 01:18:03
Done.
|
| + 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( |