OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_impl.h" | 5 #include "device/usb/usb_service_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <memory> | 10 #include <memory> |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 } // namespace | 218 } // namespace |
219 | 219 |
220 UsbServiceImpl::UsbServiceImpl() | 220 UsbServiceImpl::UsbServiceImpl() |
221 : UsbService(nullptr), | 221 : UsbService(nullptr), |
222 #if defined(OS_WIN) | 222 #if defined(OS_WIN) |
223 device_observer_(this), | 223 device_observer_(this), |
224 #endif | 224 #endif |
225 weak_factory_(this) { | 225 weak_factory_(this) { |
226 base::PostTaskWithTraits( | 226 base::PostTaskWithTraits( |
227 FROM_HERE, | 227 FROM_HERE, |
228 base::TaskTraits() | 228 {base::MayBlock(), base::TaskPriority::USER_VISIBLE, |
229 .MayBlock() | 229 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}, |
230 .WithPriority(base::TaskPriority::USER_VISIBLE) | |
231 .WithShutdownBehavior( | |
232 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), | |
233 base::Bind(&InitializeUsbContextOnBlockingThread, task_runner(), | 230 base::Bind(&InitializeUsbContextOnBlockingThread, task_runner(), |
234 base::Bind(&UsbServiceImpl::OnUsbContext, | 231 base::Bind(&UsbServiceImpl::OnUsbContext, |
235 weak_factory_.GetWeakPtr()))); | 232 weak_factory_.GetWeakPtr()))); |
236 } | 233 } |
237 | 234 |
238 UsbServiceImpl::~UsbServiceImpl() { | 235 UsbServiceImpl::~UsbServiceImpl() { |
239 if (hotplug_enabled_) | 236 if (hotplug_enabled_) |
240 libusb_hotplug_deregister_callback(context_->context(), hotplug_handle_); | 237 libusb_hotplug_deregister_callback(context_->context(), hotplug_handle_); |
241 for (auto* platform_device : ignored_devices_) | 238 for (auto* platform_device : ignored_devices_) |
242 libusb_unref_device(platform_device); | 239 libusb_unref_device(platform_device); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 | 319 |
323 enumeration_in_progress_ = true; | 320 enumeration_in_progress_ = true; |
324 DCHECK(devices_being_enumerated_.empty()); | 321 DCHECK(devices_being_enumerated_.empty()); |
325 | 322 |
326 std::string device_path; | 323 std::string device_path; |
327 if (!pending_path_enumerations_.empty()) { | 324 if (!pending_path_enumerations_.empty()) { |
328 device_path = pending_path_enumerations_.front(); | 325 device_path = pending_path_enumerations_.front(); |
329 pending_path_enumerations_.pop(); | 326 pending_path_enumerations_.pop(); |
330 } | 327 } |
331 | 328 |
332 base::PostTaskWithTraits( | 329 base::PostTaskWithTraits(FROM_HERE, |
333 FROM_HERE, | 330 {base::MayBlock(), base::TaskPriority::USER_VISIBLE, |
334 base::TaskTraits() | 331 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}, |
Reilly Grant (use Gerrit)
2017/05/03 20:27:00
Since these are the same traits I use in UsbServic
fdoray
2017/05/03 20:45:44
This would indeed be a nice improvement but in the
| |
335 .MayBlock() | 332 base::Bind(&GetDeviceListOnBlockingThread, |
336 .WithPriority(base::TaskPriority::USER_VISIBLE) | 333 device_path, context_, task_runner(), |
337 .WithShutdownBehavior( | 334 base::Bind(&UsbServiceImpl::OnDeviceList, |
338 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), | 335 weak_factory_.GetWeakPtr()))); |
339 base::Bind(&GetDeviceListOnBlockingThread, device_path, context_, | |
340 task_runner(), | |
341 base::Bind(&UsbServiceImpl::OnDeviceList, | |
342 weak_factory_.GetWeakPtr()))); | |
343 } | 336 } |
344 | 337 |
345 void UsbServiceImpl::OnDeviceList(libusb_device** platform_devices, | 338 void UsbServiceImpl::OnDeviceList(libusb_device** platform_devices, |
346 size_t device_count) { | 339 size_t device_count) { |
347 DCHECK(CalledOnValidThread()); | 340 DCHECK(CalledOnValidThread()); |
348 if (!platform_devices) { | 341 if (!platform_devices) { |
349 RefreshDevicesComplete(); | 342 RefreshDevicesComplete(); |
350 return; | 343 return; |
351 } | 344 } |
352 | 345 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
562 } | 555 } |
563 | 556 |
564 void UsbServiceImpl::EnumerationFailed(PlatformUsbDevice platform_device, | 557 void UsbServiceImpl::EnumerationFailed(PlatformUsbDevice platform_device, |
565 const base::Closure& refresh_complete) { | 558 const base::Closure& refresh_complete) { |
566 libusb_ref_device(platform_device); | 559 libusb_ref_device(platform_device); |
567 ignored_devices_.insert(platform_device); | 560 ignored_devices_.insert(platform_device); |
568 refresh_complete.Run(); | 561 refresh_complete.Run(); |
569 } | 562 } |
570 | 563 |
571 } // namespace device | 564 } // namespace device |
OLD | NEW |