Chromium Code Reviews| Index: device/bluetooth/test/mock_bluetooth_adapter.cc |
| diff --git a/device/bluetooth/test/mock_bluetooth_adapter.cc b/device/bluetooth/test/mock_bluetooth_adapter.cc |
| index 2667650f40bf97e3f6678254e9593f482b1f128c..0d43faba459e0a53742611533e74bcc0edbc5d7b 100644 |
| --- a/device/bluetooth/test/mock_bluetooth_adapter.cc |
| +++ b/device/bluetooth/test/mock_bluetooth_adapter.cc |
| @@ -68,29 +68,32 @@ void MockBluetoothAdapter::AddMockDevice( |
| std::unique_ptr<MockBluetoothDevice> MockBluetoothAdapter::RemoveMockDevice( |
| const std::string& address) { |
| - for (auto it = mock_devices_.begin(); it != mock_devices_.end(); ++it) { |
| - if ((*it)->GetAddress() != address) { |
| + for (auto& device : mock_devices_) { |
| + if (device->GetAddress() != address) { |
| continue; |
| } |
| - std::unique_ptr<MockBluetoothDevice> removed_device(*it); |
| - mock_devices_.weak_erase(it); |
| - return removed_device; |
| + std::unique_ptr<MockBluetoothDevice> removed_device = std::move(device); |
| + auto it = std::find(mock_devices_.begin(), mock_devices_.end(), device); |
| + if (it != mock_devices_.end()) { |
| + mock_devices_.erase(it); |
| + return removed_device; |
| + } |
|
Reilly Grant (use Gerrit)
2016/12/21 22:25:15
This is a case where keeping the existing iterator
dougt
2016/12/22 01:18:03
Done.
|
| } |
| return nullptr; |
| } |
| BluetoothAdapter::ConstDeviceList MockBluetoothAdapter::GetConstMockDevices() { |
| BluetoothAdapter::ConstDeviceList devices; |
| - for (auto* it : mock_devices_) { |
| - devices.push_back(it); |
| + for (auto& device : mock_devices_) { |
| + devices.push_back(device.get()); |
| } |
| return devices; |
| } |
| BluetoothAdapter::DeviceList MockBluetoothAdapter::GetMockDevices() { |
| BluetoothAdapter::DeviceList devices; |
| - for (auto* it : mock_devices_) { |
| - devices.push_back(it); |
| + for (auto& device : mock_devices_) { |
| + devices.push_back(device.get()); |
| } |
| return devices; |
| } |