Index: device/bluetooth/bluez/bluetooth_adapter_bluez.cc |
diff --git a/device/bluetooth/bluez/bluetooth_adapter_bluez.cc b/device/bluetooth/bluez/bluetooth_adapter_bluez.cc |
index e1ed672fff233aa616cd97d843953299ad373e1d..f2a688473b24e60ac2496d5247b73fd96ace97eb 100644 |
--- a/device/bluetooth/bluez/bluetooth_adapter_bluez.cc |
+++ b/device/bluetooth/bluez/bluetooth_adapter_bluez.cc |
@@ -15,6 +15,7 @@ |
#include "base/bind.h" |
#include "base/location.h" |
#include "base/logging.h" |
+#include "base/memory/ptr_util.h" |
#include "base/metrics/histogram.h" |
#include "base/sequenced_task_runner.h" |
#include "base/single_thread_task_runner.h" |
@@ -509,10 +510,9 @@ void BluetoothAdapterBlueZ::RemovePairingDelegateInternal( |
BluetoothDevice::PairingDelegate* pairing_delegate) { |
// Check if any device is using the pairing delegate. |
// If so, clear the pairing context which will make any responses no-ops. |
- for (DevicesMap::const_iterator iter = devices_.begin(); |
- iter != devices_.end(); ++iter) { |
+ for (auto iter = devices_.begin(); iter != devices_.end(); ++iter) { |
BluetoothDeviceBlueZ* device_bluez = |
- static_cast<BluetoothDeviceBlueZ*>(iter->second); |
+ static_cast<BluetoothDeviceBlueZ*>(iter->second.get()); |
BluetoothPairingBlueZ* pairing = device_bluez->GetPairing(); |
if (pairing && pairing->GetPairingDelegate() == pairing_delegate) |
@@ -566,21 +566,19 @@ void BluetoothAdapterBlueZ::DeviceAdded(const dbus::ObjectPath& object_path) { |
this, object_path, ui_task_runner_, socket_thread_); |
DCHECK(devices_.find(device_bluez->GetAddress()) == devices_.end()); |
- devices_.set(device_bluez->GetAddress(), |
- std::unique_ptr<BluetoothDevice>(device_bluez)); |
+ devices_[device_bluez->GetAddress()] = base::WrapUnique(device_bluez); |
for (auto& observer : observers_) |
observer.DeviceAdded(this, device_bluez); |
} |
void BluetoothAdapterBlueZ::DeviceRemoved(const dbus::ObjectPath& object_path) { |
- for (DevicesMap::const_iterator iter = devices_.begin(); |
- iter != devices_.end(); ++iter) { |
+ for (auto iter = devices_.begin(); iter != devices_.end(); ++iter) { |
BluetoothDeviceBlueZ* device_bluez = |
- static_cast<BluetoothDeviceBlueZ*>(iter->second); |
+ static_cast<BluetoothDeviceBlueZ*>(iter->second.get()); |
if (device_bluez->object_path() == object_path) { |
- std::unique_ptr<BluetoothDevice> scoped_device = |
- devices_.take_and_erase(iter->first); |
+ std::unique_ptr<BluetoothDevice> scoped_device = std::move(iter->second); |
+ devices_.erase(iter); |
for (auto& observer : observers_) |
observer.DeviceRemoved(this, device_bluez); |
@@ -601,19 +599,17 @@ void BluetoothAdapterBlueZ::DevicePropertyChanged( |
object_path); |
if (property_name == properties->address.name()) { |
- for (DevicesMap::iterator iter = devices_.begin(); iter != devices_.end(); |
- ++iter) { |
+ for (auto iter = devices_.begin(); iter != devices_.end(); ++iter) { |
if (iter->second->GetAddress() == device_bluez->GetAddress()) { |
std::string old_address = iter->first; |
VLOG(1) << "Device changed address, old: " << old_address |
<< " new: " << device_bluez->GetAddress(); |
std::unique_ptr<BluetoothDevice> scoped_device = |
- devices_.take_and_erase(iter); |
- ignore_result(scoped_device.release()); |
+ std::move(iter->second); |
+ devices_.erase(iter); |
DCHECK(devices_.find(device_bluez->GetAddress()) == devices_.end()); |
- devices_.set(device_bluez->GetAddress(), |
- std::unique_ptr<BluetoothDevice>(device_bluez)); |
+ devices_[device_bluez->GetAddress()] = std::move(scoped_device); |
NotifyDeviceAddressChanged(device_bluez, old_address); |
break; |
} |
@@ -670,8 +666,7 @@ void BluetoothAdapterBlueZ::DevicePropertyChanged( |
int count = 0; |
- for (DevicesMap::const_iterator iter = devices_.begin(); |
- iter != devices_.end(); ++iter) { |
+ for (auto iter = devices_.begin(); iter != devices_.end(); ++iter) { |
if (iter->second->IsPaired() && iter->second->IsConnected()) |
++count; |
} |
@@ -903,10 +898,9 @@ BluetoothDeviceBlueZ* BluetoothAdapterBlueZ::GetDeviceWithPath( |
if (!IsPresent()) |
return nullptr; |
- for (DevicesMap::const_iterator iter = devices_.begin(); |
- iter != devices_.end(); ++iter) { |
+ for (auto iter = devices_.begin(); iter != devices_.end(); ++iter) { |
BluetoothDeviceBlueZ* device_bluez = |
- static_cast<BluetoothDeviceBlueZ*>(iter->second); |
+ static_cast<BluetoothDeviceBlueZ*>(iter->second.get()); |
if (device_bluez->object_path() == object_path) |
return device_bluez; |
} |
@@ -1041,7 +1035,7 @@ void BluetoothAdapterBlueZ::RemoveAdapter() { |
for (auto& iter : devices_swapped) { |
for (auto& observer : observers_) |
- observer.DeviceRemoved(this, iter.second); |
+ observer.DeviceRemoved(this, iter.second.get()); |
} |
PresentChanged(false); |