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

Unified Diff: device/usb/usb_device_win.cc

Issue 2702623002: Add support for reading USB descriptors to the new Windows backend. (Closed)
Patch Set: Addressed rockot@'s feedback and rebased. Created 3 years, 10 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_win.h ('k') | device/usb/usb_service_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/usb/usb_device_win.cc
diff --git a/device/usb/usb_device_win.cc b/device/usb/usb_device_win.cc
index 172858d5fa0a6c9c135b902f272007ec05b91282..e54d1c88d7b1dc5ffc1efaf8bc2aab5dcd0cacfd 100644
--- a/device/usb/usb_device_win.cc
+++ b/device/usb/usb_device_win.cc
@@ -10,7 +10,7 @@
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "components/device_event_log/device_event_log.h"
-#include "device/usb/usb_device_handle.h"
+#include "device/usb/usb_device_handle_win.h"
namespace device {
@@ -32,4 +32,67 @@ void UsbDeviceWin::Open(const OpenCallback& callback) {
task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr));
}
+void UsbDeviceWin::ReadDescriptors(const base::Callback<void(bool)>& callback) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ scoped_refptr<UsbDeviceHandle> device_handle;
+ base::win::ScopedHandle handle(
+ CreateFileA(hub_path_.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, nullptr,
+ OPEN_EXISTING, FILE_FLAG_OVERLAPPED, nullptr));
+ if (handle.IsValid()) {
+ device_handle =
+ new UsbDeviceHandleWin(this, std::move(handle), blocking_task_runner_);
+ } else {
+ USB_PLOG(ERROR) << "Failed to open " << hub_path_;
+ callback.Run(false);
+ return;
+ }
+
+ ReadUsbDescriptors(device_handle, base::Bind(&UsbDeviceWin::OnReadDescriptors,
+ this, callback, device_handle));
+}
+
+void UsbDeviceWin::OnReadDescriptors(
+ const base::Callback<void(bool)>& callback,
+ scoped_refptr<UsbDeviceHandle> device_handle,
+ std::unique_ptr<UsbDeviceDescriptor> descriptor) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (!descriptor) {
+ USB_LOG(ERROR) << "Failed to read descriptors from " << device_path_ << ".";
+ device_handle->Close();
+ callback.Run(false);
+ return;
+ }
+
+ descriptor_ = *descriptor;
+
+ auto string_map = base::MakeUnique<std::map<uint8_t, base::string16>>();
+ if (descriptor_.i_manufacturer)
+ (*string_map)[descriptor_.i_manufacturer] = base::string16();
+ if (descriptor_.i_product)
+ (*string_map)[descriptor_.i_product] = base::string16();
+ if (descriptor_.i_serial_number)
+ (*string_map)[descriptor_.i_serial_number] = base::string16();
+
+ ReadUsbStringDescriptors(device_handle, std::move(string_map),
+ base::Bind(&UsbDeviceWin::OnReadStringDescriptors,
+ this, callback, device_handle));
+}
+
+void UsbDeviceWin::OnReadStringDescriptors(
+ const base::Callback<void(bool)>& callback,
+ scoped_refptr<UsbDeviceHandle> device_handle,
+ std::unique_ptr<std::map<uint8_t, base::string16>> string_map) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ device_handle->Close();
+
+ if (descriptor_.i_manufacturer)
+ manufacturer_string_ = (*string_map)[descriptor_.i_manufacturer];
+ if (descriptor_.i_product)
+ product_string_ = (*string_map)[descriptor_.i_product];
+ if (descriptor_.i_serial_number)
+ serial_number_ = (*string_map)[descriptor_.i_serial_number];
+
+ callback.Run(true);
+}
+
} // namespace device
« no previous file with comments | « device/usb/usb_device_win.h ('k') | device/usb/usb_service_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698