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

Side by Side Diff: device/usb/usb_service_win.cc

Issue 2905153002: Move off of deprecated base::NonThreadSafe in device/ (Closed)
Patch Set: ThreadChecker => SequenceChecker Created 3 years, 6 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
« no previous file with comments | « device/usb/usb_service_linux.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/usb/usb_service_win.h" 5 #include "device/usb/usb_service_win.h"
6 6
7 #include <setupapi.h> 7 #include <setupapi.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <usbiodef.h> 9 #include <usbiodef.h>
10 10
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 blocking_task_runner()->PostTask( 289 blocking_task_runner()->PostTask(
290 FROM_HERE, base::Bind(&BlockingTaskHelper::EnumerateDevices, 290 FROM_HERE, base::Bind(&BlockingTaskHelper::EnumerateDevices,
291 base::Unretained(helper_.get()))); 291 base::Unretained(helper_.get())));
292 } 292 }
293 293
294 UsbServiceWin::~UsbServiceWin() { 294 UsbServiceWin::~UsbServiceWin() {
295 blocking_task_runner()->DeleteSoon(FROM_HERE, helper_.release()); 295 blocking_task_runner()->DeleteSoon(FROM_HERE, helper_.release());
296 } 296 }
297 297
298 void UsbServiceWin::GetDevices(const GetDevicesCallback& callback) { 298 void UsbServiceWin::GetDevices(const GetDevicesCallback& callback) {
299 DCHECK(CalledOnValidThread()); 299 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
300 if (enumeration_ready()) 300 if (enumeration_ready())
301 UsbService::GetDevices(callback); 301 UsbService::GetDevices(callback);
302 else 302 else
303 enumeration_callbacks_.push_back(callback); 303 enumeration_callbacks_.push_back(callback);
304 } 304 }
305 305
306 void UsbServiceWin::OnDeviceAdded(const GUID& class_guid, 306 void UsbServiceWin::OnDeviceAdded(const GUID& class_guid,
307 const std::string& device_path) { 307 const std::string& device_path) {
308 blocking_task_runner()->PostTask( 308 blocking_task_runner()->PostTask(
309 FROM_HERE, base::Bind(&BlockingTaskHelper::EnumerateDevicePath, 309 FROM_HERE, base::Bind(&BlockingTaskHelper::EnumerateDevicePath,
310 base::Unretained(helper_.get()), device_path)); 310 base::Unretained(helper_.get()), device_path));
311 } 311 }
312 312
313 void UsbServiceWin::OnDeviceRemoved(const GUID& class_guid, 313 void UsbServiceWin::OnDeviceRemoved(const GUID& class_guid,
314 const std::string& device_path) { 314 const std::string& device_path) {
315 DCHECK(CalledOnValidThread()); 315 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
316 auto by_path_it = devices_by_path_.find(device_path); 316 auto by_path_it = devices_by_path_.find(device_path);
317 if (by_path_it == devices_by_path_.end()) 317 if (by_path_it == devices_by_path_.end())
318 return; 318 return;
319 319
320 scoped_refptr<UsbDeviceWin> device = by_path_it->second; 320 scoped_refptr<UsbDeviceWin> device = by_path_it->second;
321 devices_by_path_.erase(by_path_it); 321 devices_by_path_.erase(by_path_it);
322 device->OnDisconnect(); 322 device->OnDisconnect();
323 323
324 auto by_guid_it = devices().find(device->guid()); 324 auto by_guid_it = devices().find(device->guid());
325 if (by_guid_it != devices().end() && enumeration_ready()) { 325 if (by_guid_it != devices().end() && enumeration_ready()) {
326 USB_LOG(USER) << "USB device removed: path=" << device->device_path() 326 USB_LOG(USER) << "USB device removed: path=" << device->device_path()
327 << " guid=" << device->guid(); 327 << " guid=" << device->guid();
328 328
329 devices().erase(by_guid_it); 329 devices().erase(by_guid_it);
330 NotifyDeviceRemoved(device); 330 NotifyDeviceRemoved(device);
331 } 331 }
332 } 332 }
333 333
334 void UsbServiceWin::HelperStarted() { 334 void UsbServiceWin::HelperStarted() {
335 DCHECK(CalledOnValidThread()); 335 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
336 helper_started_ = true; 336 helper_started_ = true;
337 if (enumeration_ready()) { 337 if (enumeration_ready()) {
338 std::vector<scoped_refptr<UsbDevice>> result; 338 std::vector<scoped_refptr<UsbDevice>> result;
339 result.reserve(devices().size()); 339 result.reserve(devices().size());
340 for (const auto& map_entry : devices()) 340 for (const auto& map_entry : devices())
341 result.push_back(map_entry.second); 341 result.push_back(map_entry.second);
342 for (const auto& callback : enumeration_callbacks_) 342 for (const auto& callback : enumeration_callbacks_)
343 callback.Run(result); 343 callback.Run(result);
344 enumeration_callbacks_.clear(); 344 enumeration_callbacks_.clear();
345 } 345 }
(...skipping 11 matching lines...) Expand all
357 357
358 scoped_refptr<UsbDeviceWin> device(new UsbDeviceWin( 358 scoped_refptr<UsbDeviceWin> device(new UsbDeviceWin(
359 device_path, hub_path, port_number, driver_name, blocking_task_runner())); 359 device_path, hub_path, port_number, driver_name, blocking_task_runner()));
360 devices_by_path_[device->device_path()] = device; 360 devices_by_path_[device->device_path()] = device;
361 device->ReadDescriptors(base::Bind(&UsbServiceWin::DeviceReady, 361 device->ReadDescriptors(base::Bind(&UsbServiceWin::DeviceReady,
362 weak_factory_.GetWeakPtr(), device)); 362 weak_factory_.GetWeakPtr(), device));
363 } 363 }
364 364
365 void UsbServiceWin::DeviceReady(scoped_refptr<UsbDeviceWin> device, 365 void UsbServiceWin::DeviceReady(scoped_refptr<UsbDeviceWin> device,
366 bool success) { 366 bool success) {
367 DCHECK(CalledOnValidThread()); 367 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
368 368
369 bool enumeration_became_ready = false; 369 bool enumeration_became_ready = false;
370 if (!enumeration_ready()) { 370 if (!enumeration_ready()) {
371 DCHECK_GT(first_enumeration_countdown_, 0u); 371 DCHECK_GT(first_enumeration_countdown_, 0u);
372 first_enumeration_countdown_--; 372 first_enumeration_countdown_--;
373 if (enumeration_ready()) 373 if (enumeration_ready())
374 enumeration_became_ready = true; 374 enumeration_became_ready = true;
375 } 375 }
376 376
377 // If |device| was disconnected while descriptors were being read then it 377 // If |device| was disconnected while descriptors were being read then it
(...skipping 23 matching lines...) Expand all
401 result.push_back(map_entry.second); 401 result.push_back(map_entry.second);
402 for (const auto& callback : enumeration_callbacks_) 402 for (const auto& callback : enumeration_callbacks_)
403 callback.Run(result); 403 callback.Run(result);
404 enumeration_callbacks_.clear(); 404 enumeration_callbacks_.clear();
405 } else if (success && enumeration_ready()) { 405 } else if (success && enumeration_ready()) {
406 NotifyDeviceAdded(device); 406 NotifyDeviceAdded(device);
407 } 407 }
408 } 408 }
409 409
410 } // namespace device 410 } // namespace device
OLDNEW
« no previous file with comments | « device/usb/usb_service_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698