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

Unified Diff: device/usb/usb_device_linux.cc

Issue 2849953003: Use the task scheduler for blocking tasks in the USB service on Linux (Closed)
Patch Set: Remove more passing of the SequencedTaskRunner 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
« no previous file with comments | « device/usb/usb_device_linux.h ('k') | device/usb/usb_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/usb/usb_device_linux.cc
diff --git a/device/usb/usb_device_linux.cc b/device/usb/usb_device_linux.cc
index 08a3329162ab703672631f3009ff8e508e12f6f7..dc423de10200d0242ccc058cb7bd75802eeae7a3 100644
--- a/device/usb/usb_device_linux.cc
+++ b/device/usb/usb_device_linux.cc
@@ -18,7 +18,7 @@
#include "components/device_event_log/device_event_log.h"
#include "device/usb/usb_descriptors.h"
#include "device/usb/usb_device_handle_usbfs.h"
-#include "device/usb/usb_error.h"
+#include "device/usb/usb_service.h"
#if defined(OS_CHROMEOS)
#include "chromeos/dbus/dbus_thread_manager.h"
@@ -27,21 +27,17 @@
namespace device {
-UsbDeviceLinux::UsbDeviceLinux(
- const std::string& device_path,
- const UsbDeviceDescriptor& descriptor,
- const std::string& manufacturer_string,
- const std::string& product_string,
- const std::string& serial_number,
- uint8_t active_configuration,
- scoped_refptr<base::SequencedTaskRunner> blocking_task_runner)
+UsbDeviceLinux::UsbDeviceLinux(const std::string& device_path,
+ const UsbDeviceDescriptor& descriptor,
+ const std::string& manufacturer_string,
+ const std::string& product_string,
+ const std::string& serial_number,
+ uint8_t active_configuration)
: UsbDevice(descriptor,
base::UTF8ToUTF16(manufacturer_string),
base::UTF8ToUTF16(product_string),
base::UTF8ToUTF16(serial_number)),
- device_path_(device_path),
- task_runner_(base::ThreadTaskRunnerHandle::Get()),
- blocking_task_runner_(blocking_task_runner) {
+ device_path_(device_path) {
ActiveConfigurationChanged(active_configuration);
}
@@ -50,7 +46,7 @@ UsbDeviceLinux::~UsbDeviceLinux() {}
#if defined(OS_CHROMEOS)
void UsbDeviceLinux::CheckUsbAccess(const ResultCallback& callback) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(sequence_checker_.CalledOnValidSequence());
chromeos::PermissionBrokerClient* client =
chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient();
DCHECK(client) << "Could not get permission broker client.";
@@ -60,7 +56,7 @@ void UsbDeviceLinux::CheckUsbAccess(const ResultCallback& callback) {
#endif // defined(OS_CHROMEOS)
void UsbDeviceLinux::Open(const OpenCallback& callback) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(sequence_checker_.CalledOnValidSequence());
#if defined(OS_CHROMEOS)
chromeos::PermissionBrokerClient* client =
@@ -71,9 +67,12 @@ void UsbDeviceLinux::Open(const OpenCallback& callback) {
base::Bind(&UsbDeviceLinux::OnOpenRequestComplete, this, callback),
base::Bind(&UsbDeviceLinux::OnOpenRequestError, this, callback));
#else
- blocking_task_runner_->PostTask(
+ scoped_refptr<base::SequencedTaskRunner> blocking_task_runner =
+ UsbService::CreateBlockingTaskRunner();
+ blocking_task_runner->PostTask(
FROM_HERE,
- base::Bind(&UsbDeviceLinux::OpenOnBlockingThread, this, callback));
+ base::Bind(&UsbDeviceLinux::OpenOnBlockingThread, this, callback,
+ base::ThreadTaskRunnerHandle::Get(), blocking_task_runner));
#endif // defined(OS_CHROMEOS)
}
@@ -86,7 +85,7 @@ void UsbDeviceLinux::OnOpenRequestComplete(const OpenCallback& callback,
callback.Run(nullptr);
return;
}
- Opened(std::move(fd), callback);
+ Opened(std::move(fd), callback, UsbService::CreateBlockingTaskRunner());
}
void UsbDeviceLinux::OnOpenRequestError(const OpenCallback& callback,
@@ -99,23 +98,30 @@ void UsbDeviceLinux::OnOpenRequestError(const OpenCallback& callback,
#else
-void UsbDeviceLinux::OpenOnBlockingThread(const OpenCallback& callback) {
+void UsbDeviceLinux::OpenOnBlockingThread(
+ const OpenCallback& callback,
+ scoped_refptr<base::SequencedTaskRunner> task_runner,
+ scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) {
base::ScopedFD fd(HANDLE_EINTR(open(device_path_.c_str(), O_RDWR)));
if (fd.is_valid()) {
- task_runner_->PostTask(FROM_HERE, base::Bind(&UsbDeviceLinux::Opened, this,
- base::Passed(&fd), callback));
+ task_runner->PostTask(
+ FROM_HERE, base::Bind(&UsbDeviceLinux::Opened, this, base::Passed(&fd),
+ callback, blocking_task_runner));
} else {
USB_PLOG(EVENT) << "Failed to open " << device_path_;
- task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr));
+ task_runner->PostTask(FROM_HERE, base::Bind(callback, nullptr));
}
}
#endif // defined(OS_CHROMEOS)
-void UsbDeviceLinux::Opened(base::ScopedFD fd, const OpenCallback& callback) {
- DCHECK(thread_checker_.CalledOnValidThread());
+void UsbDeviceLinux::Opened(
+ base::ScopedFD fd,
+ const OpenCallback& callback,
+ scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) {
+ DCHECK(sequence_checker_.CalledOnValidSequence());
scoped_refptr<UsbDeviceHandle> device_handle =
- new UsbDeviceHandleUsbfs(this, std::move(fd), blocking_task_runner_);
+ new UsbDeviceHandleUsbfs(this, std::move(fd), blocking_task_runner);
handles().push_back(device_handle.get());
callback.Run(device_handle);
}
« no previous file with comments | « device/usb/usb_device_linux.h ('k') | device/usb/usb_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698