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

Unified Diff: device/bluetooth/bluetooth_adapter_win.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/bluetooth_adapter_win.cc
diff --git a/device/bluetooth/bluetooth_adapter_win.cc b/device/bluetooth/bluetooth_adapter_win.cc
index 1bacaacf9b369bc692758ba72d4a1a483fdca2f0..5f52d5f6c8084ae28fbee89b1114eee6fea275b1 100644
--- a/device/bluetooth/bluetooth_adapter_win.cc
+++ b/device/bluetooth/bluetooth_adapter_win.cc
@@ -227,14 +227,15 @@ void BluetoothAdapterWin::AdapterStateChanged(
}
void BluetoothAdapterWin::DevicesPolled(
- const ScopedVector<BluetoothTaskManagerWin::DeviceState>& devices) {
+ const std::vector<std::unique_ptr<BluetoothTaskManagerWin::DeviceState>>&
+ devices) {
DCHECK(thread_checker_.CalledOnValidThread());
// We are receiving a new list of all devices known to the system. Merge this
// new list with the list we know of (|devices_|) and raise corresponding
// DeviceAdded, DeviceRemoved and DeviceChanged events.
- typedef std::set<std::string> DeviceAddressSet;
+ using DeviceAddressSet = std::set<std::string>;
DeviceAddressSet known_devices;
for (DevicesMap::const_iterator iter = devices_.begin();
iter != devices_.end();
@@ -243,11 +244,8 @@ void BluetoothAdapterWin::DevicesPolled(
}
DeviceAddressSet new_devices;
- for (ScopedVector<BluetoothTaskManagerWin::DeviceState>::const_iterator iter =
- devices.begin();
- iter != devices.end();
- ++iter) {
- new_devices.insert((*iter)->address);
+ for (auto& device : devices) {
+ new_devices.insert(device->address);
}
// Process device removal first
@@ -256,8 +254,11 @@ void BluetoothAdapterWin::DevicesPolled(
for (DeviceAddressSet::const_iterator iter = removed_devices.begin();
iter != removed_devices.end();
++iter) {
- std::unique_ptr<BluetoothDevice> device_win =
- devices_.take_and_erase(*iter);
+ auto found = devices_.find(*iter);
+ if (found == devices_.end())
+ continue;
+ auto device_win = std::move(found->second);
+ devices_.erase(*iter);
for (auto& observer : observers_)
observer.DeviceRemoved(this, device_win.get());
}
@@ -267,25 +268,23 @@ void BluetoothAdapterWin::DevicesPolled(
base::STLSetDifference<DeviceAddressSet>(new_devices, known_devices);
DeviceAddressSet changed_devices =
base::STLSetIntersection<DeviceAddressSet>(known_devices, new_devices);
- for (ScopedVector<BluetoothTaskManagerWin::DeviceState>::const_iterator iter =
- devices.begin();
- iter != devices.end();
- ++iter) {
- BluetoothTaskManagerWin::DeviceState* device_state = (*iter);
+ for (auto& device_state : devices) {
if (added_devices.find(device_state->address) != added_devices.end()) {
- BluetoothDeviceWin* device_win =
+ auto* device_win =
new BluetoothDeviceWin(this, *device_state, ui_task_runner_,
socket_thread_, NULL, net::NetLogSource());
- devices_.set(device_state->address,
- std::unique_ptr<BluetoothDevice>(device_win));
+ auto insertion = devices_.insert(
+ std::make_pair(device_state->address, std::move(device_win)));
+ if (!insertion.second)
+ continue;
for (auto& observer : observers_)
- observer.DeviceAdded(this, device_win);
+ observer.DeviceAdded(this, insertion.first->second.get());
} else if (changed_devices.find(device_state->address) !=
changed_devices.end()) {
DevicesMap::const_iterator iter = devices_.find(device_state->address);
DCHECK(iter != devices_.end());
BluetoothDeviceWin* device_win =
- static_cast<BluetoothDeviceWin*>(iter->second);
+ static_cast<BluetoothDeviceWin*>(iter->second.get());
if (!device_win->IsEqual(*device_state)) {
device_win->Update(*device_state);
for (auto& observer : observers_)

Powered by Google App Engine
This is Rietveld 408576698