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

Unified Diff: extensions/browser/api/usb/usb_api.cc

Issue 562763002: Convert device::UsbConfigDescriptor and friends to structs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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: extensions/browser/api/usb/usb_api.cc
diff --git a/extensions/browser/api/usb/usb_api.cc b/extensions/browser/api/usb/usb_api.cc
index 53f5c5bdf84b9d3d41904b007c2b5460ca9ad67e..5369bf3123c30535ecbd7a8212fa034de1ab996b 100644
--- a/extensions/browser/api/usb/usb_api.cc
+++ b/extensions/browser/api/usb/usb_api.cc
@@ -56,7 +56,6 @@ using device::UsbDeviceFilter;
using device::UsbDeviceHandle;
using device::UsbEndpointDescriptor;
using device::UsbEndpointDirection;
-using device::UsbInterfaceAltSettingDescriptor;
using device::UsbInterfaceDescriptor;
using device::UsbService;
using device::UsbSynchronizationType;
@@ -761,75 +760,54 @@ void UsbListInterfacesFunction::AsyncWorkStart() {
if (!device_handle.get())
return;
- scoped_refptr<UsbConfigDescriptor> config =
- device_handle->GetDevice()->ListInterfaces();
+ const UsbConfigDescriptor& config =
+ device_handle->GetDevice()->GetConfiguration();
- if (!config.get()) {
- SetError(kErrorCannotListInterfaces);
- AsyncWorkCompleted();
- return;
- }
+ scoped_ptr<base::ListValue> result(new base::ListValue());
- result_.reset(new base::ListValue());
-
- for (size_t i = 0, num_interfaces = config->GetNumInterfaces();
- i < num_interfaces;
- ++i) {
- scoped_refptr<const UsbInterfaceDescriptor> usb_interface(
- config->GetInterface(i));
- for (size_t j = 0, num_descriptors = usb_interface->GetNumAltSettings();
- j < num_descriptors;
- ++j) {
- scoped_refptr<const UsbInterfaceAltSettingDescriptor> descriptor =
- usb_interface->GetAltSetting(j);
- std::vector<linked_ptr<EndpointDescriptor> > endpoints;
- for (size_t k = 0, num_endpoints = descriptor->GetNumEndpoints();
- k < num_endpoints;
- k++) {
- scoped_refptr<const UsbEndpointDescriptor> endpoint =
- descriptor->GetEndpoint(k);
- linked_ptr<EndpointDescriptor> endpoint_desc(new EndpointDescriptor());
-
- TransferType type;
- Direction direction;
- SynchronizationType synchronization;
- UsageType usage;
-
- if (!ConvertTransferTypeSafely(endpoint->GetTransferType(), &type) ||
- !ConvertDirectionSafely(endpoint->GetDirection(), &direction) ||
- !ConvertSynchronizationTypeSafely(
- endpoint->GetSynchronizationType(), &synchronization) ||
- !ConvertUsageTypeSafely(endpoint->GetUsageType(), &usage)) {
- SetError(kErrorCannotListInterfaces);
- AsyncWorkCompleted();
- return;
- }
-
- endpoint_desc->address = endpoint->GetAddress();
- endpoint_desc->type = type;
- endpoint_desc->direction = direction;
- endpoint_desc->maximum_packet_size = endpoint->GetMaximumPacketSize();
- endpoint_desc->synchronization = synchronization;
- endpoint_desc->usage = usage;
-
- int* polling_interval = new int;
- endpoint_desc->polling_interval.reset(polling_interval);
- *polling_interval = endpoint->GetPollingInterval();
-
- endpoints.push_back(endpoint_desc);
+ for (size_t i = 0; i < config.interfaces.size(); ++i) {
+ const UsbInterfaceDescriptor& usb_interface = config.interfaces[i];
+ std::vector<linked_ptr<EndpointDescriptor> > endpoints;
+
+ for (size_t j = 0; j < usb_interface.endpoints.size(); ++j) {
+ const UsbEndpointDescriptor& endpoint = usb_interface.endpoints[j];
+ linked_ptr<EndpointDescriptor> endpoint_desc(new EndpointDescriptor());
+
+ TransferType type;
+ Direction direction;
+ SynchronizationType synchronization;
+ UsageType usage;
+
+ if (!ConvertTransferTypeSafely(endpoint.transfer_type, &type) ||
+ !ConvertDirectionSafely(endpoint.direction, &direction) ||
+ !ConvertSynchronizationTypeSafely(endpoint.synchronization_type,
+ &synchronization) ||
+ !ConvertUsageTypeSafely(endpoint.usage_type, &usage)) {
+ SetError(kErrorCannotListInterfaces);
+ AsyncWorkCompleted();
+ return;
}
- result_->Append(
- PopulateInterfaceDescriptor(descriptor->GetInterfaceNumber(),
- descriptor->GetAlternateSetting(),
- descriptor->GetInterfaceClass(),
- descriptor->GetInterfaceSubclass(),
- descriptor->GetInterfaceProtocol(),
- &endpoints));
+ endpoint_desc->address = endpoint.address;
+ endpoint_desc->type = type;
+ endpoint_desc->direction = direction;
+ endpoint_desc->maximum_packet_size = endpoint.maximum_packet_size;
+ endpoint_desc->synchronization = synchronization;
+ endpoint_desc->usage = usage;
+ endpoint_desc->polling_interval.reset(new int(endpoint.polling_interval));
+
+ endpoints.push_back(endpoint_desc);
}
+
+ result->Append(PopulateInterfaceDescriptor(usb_interface.interface_number,
+ usb_interface.alternate_setting,
+ usb_interface.interface_class,
+ usb_interface.interface_subclass,
+ usb_interface.interface_protocol,
+ &endpoints));
}
- SetResult(result_.release());
+ SetResult(result.release());
AsyncWorkCompleted();
}

Powered by Google App Engine
This is Rietveld 408576698