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

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: Add interface and endpoint descriptor iterator typedefs. 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
« no previous file with comments | « extensions/browser/api/usb/usb_api.h ('k') | extensions/browser/api/usb/usb_apitest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..22e19c4084a5efdc937f54323069dae6b6117ad3 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,58 @@ 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 (UsbInterfaceDescriptor::Iterator interfaceIt = config.interfaces.begin();
+ interfaceIt != config.interfaces.end();
+ ++interfaceIt) {
+ std::vector<linked_ptr<EndpointDescriptor> > endpoints;
+
+ for (UsbEndpointDescriptor::Iterator endpointIt =
+ interfaceIt->endpoints.begin();
+ endpointIt != interfaceIt->endpoints.end();
+ ++endpointIt) {
+ linked_ptr<EndpointDescriptor> endpoint_desc(new EndpointDescriptor());
+
+ TransferType type;
+ Direction direction;
+ SynchronizationType synchronization;
+ UsageType usage;
+
+ if (!ConvertTransferTypeSafely(endpointIt->transfer_type, &type) ||
+ !ConvertDirectionSafely(endpointIt->direction, &direction) ||
+ !ConvertSynchronizationTypeSafely(endpointIt->synchronization_type,
+ &synchronization) ||
+ !ConvertUsageTypeSafely(endpointIt->usage_type, &usage)) {
+ SetError(kErrorCannotListInterfaces);
+ AsyncWorkCompleted();
+ return;
}
- result_->Append(
- PopulateInterfaceDescriptor(descriptor->GetInterfaceNumber(),
- descriptor->GetAlternateSetting(),
- descriptor->GetInterfaceClass(),
- descriptor->GetInterfaceSubclass(),
- descriptor->GetInterfaceProtocol(),
- &endpoints));
+ endpoint_desc->address = endpointIt->address;
+ endpoint_desc->type = type;
+ endpoint_desc->direction = direction;
+ endpoint_desc->maximum_packet_size = endpointIt->maximum_packet_size;
+ endpoint_desc->synchronization = synchronization;
+ endpoint_desc->usage = usage;
+ endpoint_desc->polling_interval.reset(
+ new int(endpointIt->polling_interval));
+
+ endpoints.push_back(endpoint_desc);
}
+
+ result->Append(PopulateInterfaceDescriptor(interfaceIt->interface_number,
+ interfaceIt->alternate_setting,
+ interfaceIt->interface_class,
+ interfaceIt->interface_subclass,
+ interfaceIt->interface_protocol,
+ &endpoints));
}
- SetResult(result_.release());
+ SetResult(result.release());
AsyncWorkCompleted();
}
« no previous file with comments | « extensions/browser/api/usb/usb_api.h ('k') | extensions/browser/api/usb/usb_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698