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

Unified Diff: device/usb/usb_descriptors.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_descriptors.h ('k') | device/usb/usb_device.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/usb/usb_descriptors.cc
diff --git a/device/usb/usb_descriptors.cc b/device/usb/usb_descriptors.cc
index 18316c58dbfd7fafa7717df47c5b419973aa9fac..5ad332b4b123b4203916f9f0b527e7fc3ba1e62a 100644
--- a/device/usb/usb_descriptors.cc
+++ b/device/usb/usb_descriptors.cc
@@ -82,10 +82,14 @@ void OnDoneReadingConfigDescriptors(
std::unique_ptr<UsbDeviceDescriptor> desc,
const base::Callback<void(std::unique_ptr<UsbDeviceDescriptor>)>&
callback) {
- if (desc->num_configurations == desc->configurations.size())
+ if (desc->num_configurations == desc->configurations.size()) {
callback.Run(std::move(desc));
- else
+ } else {
+ LOG(ERROR) << "Failed to read all configuration descriptors. Expected "
+ << static_cast<int>(desc->num_configurations) << ", got "
+ << desc->configurations.size() << ".";
callback.Run(nullptr);
+ }
}
void OnReadConfigDescriptor(UsbDeviceDescriptor* desc,
@@ -93,8 +97,14 @@ void OnReadConfigDescriptor(UsbDeviceDescriptor* desc,
UsbTransferStatus status,
scoped_refptr<IOBuffer> buffer,
size_t length) {
- if (status == USB_TRANSFER_COMPLETED)
- desc->Parse(std::vector<uint8_t>(buffer->data(), buffer->data() + length));
+ if (status == USB_TRANSFER_COMPLETED) {
+ if (!desc->Parse(
+ std::vector<uint8_t>(buffer->data(), buffer->data() + length))) {
+ LOG(ERROR) << "Failed to parse configuration descriptor.";
+ }
+ } else {
+ LOG(ERROR) << "Failed to read configuration descriptor.";
+ }
closure.Run();
}
@@ -116,6 +126,8 @@ void OnReadConfigDescriptorHeader(scoped_refptr<UsbDeviceHandle> device_handle,
kControlTransferTimeout,
base::Bind(&OnReadConfigDescriptor, desc, closure));
} else {
+ LOG(ERROR) << "Failed to read length for configuration "
+ << static_cast<int>(index) << ".";
closure.Run();
}
}
@@ -127,6 +139,7 @@ void OnReadDeviceDescriptor(
scoped_refptr<IOBuffer> buffer,
size_t length) {
if (status != USB_TRANSFER_COMPLETED) {
+ LOG(ERROR) << "Failed to read device descriptor.";
callback.Run(nullptr);
return;
}
@@ -134,6 +147,7 @@ void OnReadDeviceDescriptor(
std::unique_ptr<UsbDeviceDescriptor> desc(new UsbDeviceDescriptor());
if (!desc->Parse(
std::vector<uint8_t>(buffer->data(), buffer->data() + length))) {
+ LOG(ERROR) << "Device descriptor parsing error.";
callback.Run(nullptr);
return;
}
@@ -430,6 +444,9 @@ bool UsbDeviceDescriptor::Parse(const std::vector<uint8_t>& buffer) {
vendor_id = data[8] | data[9] << 8;
product_id = data[10] | data[11] << 8;
device_version = data[12] | data[13] << 8;
+ i_manufacturer = data[14];
+ i_product = data[15];
+ i_serial_number = data[16];
num_configurations = data[17];
break;
case kConfigurationDescriptorType:
« no previous file with comments | « device/usb/usb_descriptors.h ('k') | device/usb/usb_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698