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

Unified Diff: device/usb/usb_device_impl.cc

Issue 1897483003: Revert of Replace libusb in the Linux/Chrome OS USB I/O path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/usb/usb_device_impl.cc
diff --git a/device/usb/usb_device_impl.cc b/device/usb/usb_device_impl.cc
index 520b9efeb164ad22b9da49f5dec4f9899151b2f1..4a134bf4d1311e367567d2ba9faaa47acc6ab273 100644
--- a/device/usb/usb_device_impl.cc
+++ b/device/usb/usb_device_impl.cc
@@ -4,14 +4,12 @@
#include "device/usb/usb_device_impl.h"
-#include <fcntl.h>
#include <stddef.h>
#include <algorithm>
#include "base/bind.h"
#include "base/location.h"
-#include "base/posix/eintr_wrapper.h"
#include "base/sequenced_task_runner.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
@@ -20,14 +18,9 @@
#include "components/device_event_log/device_event_log.h"
#include "device/usb/usb_context.h"
#include "device/usb/usb_descriptors.h"
+#include "device/usb/usb_device_handle_impl.h"
#include "device/usb/usb_error.h"
#include "third_party/libusb/src/libusb/libusb.h"
-
-#if defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_LINUX)
-#include "device/usb/usb_device_handle_usbfs.h"
-#else
-#include "device/usb/usb_device_handle_impl.h"
-#endif
#if defined(OS_CHROMEOS)
#include "chromeos/dbus/dbus_thread_manager.h"
@@ -208,9 +201,9 @@
#endif // defined(OS_CHROMEOS)
}
-void UsbDeviceImpl::HandleClosed(UsbDeviceHandle* handle) {
- DCHECK(thread_checker_.CalledOnValidThread());
- handles_.remove(handle);
+void UsbDeviceImpl::HandleClosed(scoped_refptr<UsbDeviceHandle> handle) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ handles_.remove(handle.get());
}
const UsbConfigDescriptor* UsbDeviceImpl::GetActiveConfiguration() const {
@@ -257,15 +250,6 @@
}
}
-void UsbDeviceImpl::ActiveConfigurationChanged(int configuration_value) {
- for (const auto& config : configurations_) {
- if (config.configuration_value == configuration_value) {
- active_configuration_ = &config;
- return;
- }
- }
-}
-
void UsbDeviceImpl::RefreshActiveConfiguration() {
active_configuration_ = nullptr;
libusb_config_descriptor* platform_config;
@@ -277,7 +261,13 @@
return;
}
- ActiveConfigurationChanged(platform_config->bConfigurationValue);
+ for (const auto& config : configurations_) {
+ if (config.configuration_value == platform_config->bConfigurationValue) {
+ active_configuration_ = &config;
+ break;
+ }
+ }
+
libusb_free_config_descriptor(platform_config);
}
@@ -301,32 +291,21 @@
void UsbDeviceImpl::OpenOnBlockingThreadWithFd(dbus::FileDescriptor fd,
const OpenCallback& callback) {
fd.CheckValidity();
- if (fd.is_valid()) {
- base::ScopedFD scoped_fd(fd.TakeValue());
- task_runner_->PostTask(FROM_HERE,
- base::Bind(&UsbDeviceImpl::Opened, this,
- base::Passed(&scoped_fd), callback));
+ DCHECK(fd.is_valid());
+
+ PlatformUsbDeviceHandle handle;
+ const int rv = libusb_open_fd(platform_device_, fd.TakeValue(), &handle);
+ if (LIBUSB_SUCCESS == rv) {
+ task_runner_->PostTask(
+ FROM_HERE, base::Bind(&UsbDeviceImpl::Opened, this, handle, callback));
} else {
- USB_LOG(EVENT) << "Did not get valid device handle from permission broker.";
+ USB_LOG(EVENT) << "Failed to open device: "
+ << ConvertPlatformUsbErrorToString(rv);
task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr));
}
}
-#else
-#if defined(OS_LINUX)
-
-void UsbDeviceImpl::OpenOnBlockingThread(const OpenCallback& callback) {
- base::ScopedFD fd(HANDLE_EINTR(open(device_path_.c_str(), O_RDWR)));
- if (fd.is_valid()) {
- task_runner_->PostTask(FROM_HERE, base::Bind(&UsbDeviceImpl::Opened, this,
- base::Passed(&fd), callback));
- } else {
- USB_PLOG(EVENT) << "Failed to open device";
- task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr));
- }
-}
-
-#else
+#endif // defined(OS_CHROMEOS)
void UsbDeviceImpl::OpenOnBlockingThread(const OpenCallback& callback) {
PlatformUsbDeviceHandle handle;
@@ -337,33 +316,17 @@
} else {
USB_LOG(EVENT) << "Failed to open device: "
<< ConvertPlatformUsbErrorToString(rv);
- }
-}
-
-#endif // defined(OS_LINUX)
-#endif // defined(OS_CHROMEOS)
-
-#if defined(OS_LINUX)
-
-void UsbDeviceImpl::Opened(base::ScopedFD fd, const OpenCallback& callback) {
- DCHECK(thread_checker_.CalledOnValidThread());
- scoped_refptr<UsbDeviceHandle> device_handle =
- new UsbDeviceHandleUsbfs(this, std::move(fd), blocking_task_runner_);
- handles_.push_back(device_handle.get());
- callback.Run(device_handle);
-}
-
-#else
+ task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr));
+ }
+}
void UsbDeviceImpl::Opened(PlatformUsbDeviceHandle platform_handle,
const OpenCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
- scoped_refptr<UsbDeviceHandle> device_handle = new UsbDeviceHandleImpl(
+ scoped_refptr<UsbDeviceHandleImpl> device_handle = new UsbDeviceHandleImpl(
context_, this, platform_handle, blocking_task_runner_);
handles_.push_back(device_handle.get());
callback.Run(device_handle);
}
-#endif // defined(OS_LINUX)
-
} // namespace device
« no previous file with comments | « device/usb/usb_device_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698