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

Side by Side Diff: device/bluetooth/bluetooth_adapter_win.cc

Issue 2614753004: Remove ScopedVector from bluetooth. (Closed)
Patch Set: last win bits Created 3 years, 11 months 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/bluetooth/bluetooth_adapter_win.h" 5 #include "device/bluetooth/bluetooth_adapter_win.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 for (auto& observer : observers_) 221 for (auto& observer : observers_)
222 observer.AdapterPoweredChanged(this, powered_); 222 observer.AdapterPoweredChanged(this, powered_);
223 } 223 }
224 if (!initialized_) { 224 if (!initialized_) {
225 initialized_ = true; 225 initialized_ = true;
226 init_callback_.Run(); 226 init_callback_.Run();
227 } 227 }
228 } 228 }
229 229
230 void BluetoothAdapterWin::DevicesPolled( 230 void BluetoothAdapterWin::DevicesPolled(
231 const ScopedVector<BluetoothTaskManagerWin::DeviceState>& devices) { 231 const std::vector<std::unique_ptr<BluetoothTaskManagerWin::DeviceState>>&
232 devices) {
232 DCHECK(thread_checker_.CalledOnValidThread()); 233 DCHECK(thread_checker_.CalledOnValidThread());
233 234
234 // We are receiving a new list of all devices known to the system. Merge this 235 // We are receiving a new list of all devices known to the system. Merge this
235 // new list with the list we know of (|devices_|) and raise corresponding 236 // new list with the list we know of (|devices_|) and raise corresponding
236 // DeviceAdded, DeviceRemoved and DeviceChanged events. 237 // DeviceAdded, DeviceRemoved and DeviceChanged events.
237 238
238 using DeviceAddressSet = std::set<std::string>; 239 using DeviceAddressSet = std::set<std::string>;
239 DeviceAddressSet known_devices; 240 DeviceAddressSet known_devices;
240 for (const auto& device : devices_) 241 for (const auto& device : devices_)
241 known_devices.insert(device.first); 242 known_devices.insert(device.first);
242 243
243 DeviceAddressSet new_devices; 244 DeviceAddressSet new_devices;
244 for (auto iter = devices.begin(); iter != devices.end(); ++iter) 245 for (const auto& device_state : devices)
245 new_devices.insert((*iter)->address); 246 new_devices.insert(device_state->address);
246 247
247 // Process device removal first. 248 // Process device removal first.
248 DeviceAddressSet removed_devices = 249 DeviceAddressSet removed_devices =
249 base::STLSetDifference<DeviceAddressSet>(known_devices, new_devices); 250 base::STLSetDifference<DeviceAddressSet>(known_devices, new_devices);
250 for (const auto& device : removed_devices) { 251 for (const auto& device : removed_devices) {
251 auto it = devices_.find(device); 252 auto it = devices_.find(device);
252 std::unique_ptr<BluetoothDevice> device_win = std::move(it->second); 253 std::unique_ptr<BluetoothDevice> device_win = std::move(it->second);
253 devices_.erase(it); 254 devices_.erase(it);
254 for (auto& observer : observers_) 255 for (auto& observer : observers_)
255 observer.DeviceRemoved(this, device_win.get()); 256 observer.DeviceRemoved(this, device_win.get());
256 } 257 }
257 258
258 // Process added and (maybe) changed devices in one pass. 259 // Process added and (maybe) changed devices in one pass.
259 DeviceAddressSet added_devices = 260 DeviceAddressSet added_devices =
260 base::STLSetDifference<DeviceAddressSet>(new_devices, known_devices); 261 base::STLSetDifference<DeviceAddressSet>(new_devices, known_devices);
261 DeviceAddressSet changed_devices = 262 DeviceAddressSet changed_devices =
262 base::STLSetIntersection<DeviceAddressSet>(known_devices, new_devices); 263 base::STLSetIntersection<DeviceAddressSet>(known_devices, new_devices);
263 for (auto iter = devices.begin(); iter != devices.end(); ++iter) { 264 for (const auto& device_state : devices) {
264 BluetoothTaskManagerWin::DeviceState* device_state = (*iter);
265 if (added_devices.find(device_state->address) != added_devices.end()) { 265 if (added_devices.find(device_state->address) != added_devices.end()) {
266 BluetoothDeviceWin* device_win = 266 BluetoothDeviceWin* device_win =
267 new BluetoothDeviceWin(this, *device_state, ui_task_runner_, 267 new BluetoothDeviceWin(this, *device_state, ui_task_runner_,
268 socket_thread_, NULL, net::NetLogSource()); 268 socket_thread_, NULL, net::NetLogSource());
269 devices_[device_state->address] = base::WrapUnique(device_win); 269 devices_[device_state->address] = base::WrapUnique(device_win);
270 for (auto& observer : observers_) 270 for (auto& observer : observers_)
271 observer.DeviceAdded(this, device_win); 271 observer.DeviceAdded(this, device_win);
272 } else if (changed_devices.find(device_state->address) != 272 } else if (changed_devices.find(device_state->address) !=
273 changed_devices.end()) { 273 changed_devices.end()) {
274 auto iter = devices_.find(device_state->address); 274 auto iter = devices_.find(device_state->address);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 num_discovery_listeners_ -= on_stop_discovery_callbacks_.size(); 369 num_discovery_listeners_ -= on_stop_discovery_callbacks_.size();
370 on_stop_discovery_callbacks_.clear(); 370 on_stop_discovery_callbacks_.clear();
371 return; 371 return;
372 } 372 }
373 373
374 discovery_status_ = DISCOVERY_STOPPING; 374 discovery_status_ = DISCOVERY_STOPPING;
375 task_manager_->PostStopDiscoveryTask(); 375 task_manager_->PostStopDiscoveryTask();
376 } 376 }
377 377
378 } // namespace device 378 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_win.h ('k') | device/bluetooth/bluetooth_adapter_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698