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

Unified Diff: device/usb/usb_device_impl.cc

Issue 2857473002: Use the task scheduler in the USB service on macOS and Windows (Closed)
Patch Set: Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: device/usb/usb_device_impl.cc
diff --git a/device/usb/usb_device_impl.cc b/device/usb/usb_device_impl.cc
index b686efc3dbd17bbe472f4bb0f308954ce49f603d..8b00a94e889c13df7914b4cb6d5bc81e14591e3b 100644
--- a/device/usb/usb_device_impl.cc
+++ b/device/usb/usb_device_impl.cc
@@ -22,15 +22,14 @@
#include "device/usb/usb_descriptors.h"
#include "device/usb/usb_device_handle_impl.h"
#include "device/usb/usb_error.h"
+#include "device/usb/usb_service.h"
#include "third_party/libusb/src/libusb/libusb.h"
namespace device {
-UsbDeviceImpl::UsbDeviceImpl(
- scoped_refptr<UsbContext> context,
- PlatformUsbDevice platform_device,
- const libusb_device_descriptor& descriptor,
- scoped_refptr<base::SequencedTaskRunner> blocking_task_runner)
+UsbDeviceImpl::UsbDeviceImpl(scoped_refptr<UsbContext> context,
+ PlatformUsbDevice platform_device,
+ const libusb_device_descriptor& descriptor)
: UsbDevice(descriptor.bcdUSB,
descriptor.bDeviceClass,
descriptor.bDeviceSubClass,
@@ -42,9 +41,7 @@ UsbDeviceImpl::UsbDeviceImpl(
base::string16(),
base::string16()),
platform_device_(platform_device),
- context_(context),
- task_runner_(base::ThreadTaskRunnerHandle::Get()),
- blocking_task_runner_(blocking_task_runner) {
+ context_(context) {
CHECK(platform_device) << "platform_device cannot be NULL";
libusb_ref_device(platform_device);
ReadAllConfigurations();
@@ -59,9 +56,12 @@ UsbDeviceImpl::~UsbDeviceImpl() {
void UsbDeviceImpl::Open(const OpenCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
- blocking_task_runner_->PostTask(
+ scoped_refptr<base::SequencedTaskRunner> blocking_task_runner =
+ UsbService::CreateBlockingTaskRunner();
+ blocking_task_runner->PostTask(
FROM_HERE,
- base::Bind(&UsbDeviceImpl::OpenOnBlockingThread, this, callback));
+ base::Bind(&UsbDeviceImpl::OpenOnBlockingThread, this, callback,
+ base::ThreadTaskRunnerHandle::Get(), blocking_task_runner));
}
void UsbDeviceImpl::ReadAllConfigurations() {
@@ -99,24 +99,30 @@ void UsbDeviceImpl::RefreshActiveConfiguration() {
ActiveConfigurationChanged(config_value);
}
-void UsbDeviceImpl::OpenOnBlockingThread(const OpenCallback& callback) {
+void UsbDeviceImpl::OpenOnBlockingThread(
+ const OpenCallback& callback,
+ scoped_refptr<base::TaskRunner> task_runner,
+ scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) {
PlatformUsbDeviceHandle handle;
robliao 2017/05/02 14:32:59 Optional: You can do a base::ThreadRestrictions::A
Reilly Grant (use Gerrit) 2017/05/02 23:41:44 Done.
const int rv = libusb_open(platform_device_, &handle);
if (LIBUSB_SUCCESS == rv) {
- task_runner_->PostTask(
- FROM_HERE, base::Bind(&UsbDeviceImpl::Opened, this, handle, callback));
+ task_runner->PostTask(
+ FROM_HERE, base::Bind(&UsbDeviceImpl::Opened, this, handle, callback,
+ blocking_task_runner));
} else {
USB_LOG(EVENT) << "Failed to open device: "
<< ConvertPlatformUsbErrorToString(rv);
- task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr));
+ task_runner->PostTask(FROM_HERE, base::Bind(callback, nullptr));
}
}
-void UsbDeviceImpl::Opened(PlatformUsbDeviceHandle platform_handle,
- const OpenCallback& callback) {
+void UsbDeviceImpl::Opened(
+ PlatformUsbDeviceHandle platform_handle,
+ const OpenCallback& callback,
+ scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) {
DCHECK(thread_checker_.CalledOnValidThread());
scoped_refptr<UsbDeviceHandle> device_handle = new UsbDeviceHandleImpl(
- context_, this, platform_handle, blocking_task_runner_);
+ context_, this, platform_handle, blocking_task_runner);
handles().push_back(device_handle.get());
callback.Run(device_handle);
}

Powered by Google App Engine
This is Rietveld 408576698