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

Side by Side Diff: extensions/browser/api/usb/usb_api.cc

Issue 567003002: Revert of 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/browser/api/usb/usb_api.h" 5 #include "extensions/browser/api/usb/usb_api.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 using usb::RequestType; 49 using usb::RequestType;
50 using usb::SynchronizationType; 50 using usb::SynchronizationType;
51 using usb::TransferType; 51 using usb::TransferType;
52 using usb::UsageType; 52 using usb::UsageType;
53 using device::UsbConfigDescriptor; 53 using device::UsbConfigDescriptor;
54 using device::UsbDevice; 54 using device::UsbDevice;
55 using device::UsbDeviceFilter; 55 using device::UsbDeviceFilter;
56 using device::UsbDeviceHandle; 56 using device::UsbDeviceHandle;
57 using device::UsbEndpointDescriptor; 57 using device::UsbEndpointDescriptor;
58 using device::UsbEndpointDirection; 58 using device::UsbEndpointDirection;
59 using device::UsbInterfaceAltSettingDescriptor;
59 using device::UsbInterfaceDescriptor; 60 using device::UsbInterfaceDescriptor;
60 using device::UsbService; 61 using device::UsbService;
61 using device::UsbSynchronizationType; 62 using device::UsbSynchronizationType;
62 using device::UsbTransferStatus; 63 using device::UsbTransferStatus;
63 using device::UsbTransferType; 64 using device::UsbTransferType;
64 using device::UsbUsageType; 65 using device::UsbUsageType;
65 66
66 typedef std::vector<scoped_refptr<UsbDevice> > DeviceVector; 67 typedef std::vector<scoped_refptr<UsbDevice> > DeviceVector;
67 typedef scoped_ptr<DeviceVector> ScopedDeviceVector; 68 typedef scoped_ptr<DeviceVector> ScopedDeviceVector;
68 69
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 EXTENSION_FUNCTION_VALIDATE(parameters_.get()); 754 EXTENSION_FUNCTION_VALIDATE(parameters_.get());
754 return true; 755 return true;
755 } 756 }
756 757
757 void UsbListInterfacesFunction::AsyncWorkStart() { 758 void UsbListInterfacesFunction::AsyncWorkStart() {
758 scoped_refptr<UsbDeviceHandle> device_handle = 759 scoped_refptr<UsbDeviceHandle> device_handle =
759 GetDeviceHandleOrCompleteWithError(parameters_->handle); 760 GetDeviceHandleOrCompleteWithError(parameters_->handle);
760 if (!device_handle.get()) 761 if (!device_handle.get())
761 return; 762 return;
762 763
763 const UsbConfigDescriptor& config = 764 scoped_refptr<UsbConfigDescriptor> config =
764 device_handle->GetDevice()->GetConfiguration(); 765 device_handle->GetDevice()->ListInterfaces();
765 766
766 scoped_ptr<base::ListValue> result(new base::ListValue()); 767 if (!config.get()) {
768 SetError(kErrorCannotListInterfaces);
769 AsyncWorkCompleted();
770 return;
771 }
767 772
768 for (UsbInterfaceDescriptor::Iterator interfaceIt = config.interfaces.begin(); 773 result_.reset(new base::ListValue());
769 interfaceIt != config.interfaces.end();
770 ++interfaceIt) {
771 std::vector<linked_ptr<EndpointDescriptor> > endpoints;
772 774
773 for (UsbEndpointDescriptor::Iterator endpointIt = 775 for (size_t i = 0, num_interfaces = config->GetNumInterfaces();
774 interfaceIt->endpoints.begin(); 776 i < num_interfaces;
775 endpointIt != interfaceIt->endpoints.end(); 777 ++i) {
776 ++endpointIt) { 778 scoped_refptr<const UsbInterfaceDescriptor> usb_interface(
777 linked_ptr<EndpointDescriptor> endpoint_desc(new EndpointDescriptor()); 779 config->GetInterface(i));
780 for (size_t j = 0, num_descriptors = usb_interface->GetNumAltSettings();
781 j < num_descriptors;
782 ++j) {
783 scoped_refptr<const UsbInterfaceAltSettingDescriptor> descriptor =
784 usb_interface->GetAltSetting(j);
785 std::vector<linked_ptr<EndpointDescriptor> > endpoints;
786 for (size_t k = 0, num_endpoints = descriptor->GetNumEndpoints();
787 k < num_endpoints;
788 k++) {
789 scoped_refptr<const UsbEndpointDescriptor> endpoint =
790 descriptor->GetEndpoint(k);
791 linked_ptr<EndpointDescriptor> endpoint_desc(new EndpointDescriptor());
778 792
779 TransferType type; 793 TransferType type;
780 Direction direction; 794 Direction direction;
781 SynchronizationType synchronization; 795 SynchronizationType synchronization;
782 UsageType usage; 796 UsageType usage;
783 797
784 if (!ConvertTransferTypeSafely(endpointIt->transfer_type, &type) || 798 if (!ConvertTransferTypeSafely(endpoint->GetTransferType(), &type) ||
785 !ConvertDirectionSafely(endpointIt->direction, &direction) || 799 !ConvertDirectionSafely(endpoint->GetDirection(), &direction) ||
786 !ConvertSynchronizationTypeSafely(endpointIt->synchronization_type, 800 !ConvertSynchronizationTypeSafely(
787 &synchronization) || 801 endpoint->GetSynchronizationType(), &synchronization) ||
788 !ConvertUsageTypeSafely(endpointIt->usage_type, &usage)) { 802 !ConvertUsageTypeSafely(endpoint->GetUsageType(), &usage)) {
789 SetError(kErrorCannotListInterfaces); 803 SetError(kErrorCannotListInterfaces);
790 AsyncWorkCompleted(); 804 AsyncWorkCompleted();
791 return; 805 return;
806 }
807
808 endpoint_desc->address = endpoint->GetAddress();
809 endpoint_desc->type = type;
810 endpoint_desc->direction = direction;
811 endpoint_desc->maximum_packet_size = endpoint->GetMaximumPacketSize();
812 endpoint_desc->synchronization = synchronization;
813 endpoint_desc->usage = usage;
814
815 int* polling_interval = new int;
816 endpoint_desc->polling_interval.reset(polling_interval);
817 *polling_interval = endpoint->GetPollingInterval();
818
819 endpoints.push_back(endpoint_desc);
792 } 820 }
793 821
794 endpoint_desc->address = endpointIt->address; 822 result_->Append(
795 endpoint_desc->type = type; 823 PopulateInterfaceDescriptor(descriptor->GetInterfaceNumber(),
796 endpoint_desc->direction = direction; 824 descriptor->GetAlternateSetting(),
797 endpoint_desc->maximum_packet_size = endpointIt->maximum_packet_size; 825 descriptor->GetInterfaceClass(),
798 endpoint_desc->synchronization = synchronization; 826 descriptor->GetInterfaceSubclass(),
799 endpoint_desc->usage = usage; 827 descriptor->GetInterfaceProtocol(),
800 endpoint_desc->polling_interval.reset( 828 &endpoints));
801 new int(endpointIt->polling_interval));
802
803 endpoints.push_back(endpoint_desc);
804 } 829 }
805
806 result->Append(PopulateInterfaceDescriptor(interfaceIt->interface_number,
807 interfaceIt->alternate_setting,
808 interfaceIt->interface_class,
809 interfaceIt->interface_subclass,
810 interfaceIt->interface_protocol,
811 &endpoints));
812 } 830 }
813 831
814 SetResult(result.release()); 832 SetResult(result_.release());
815 AsyncWorkCompleted(); 833 AsyncWorkCompleted();
816 } 834 }
817 835
818 bool UsbListInterfacesFunction::ConvertDirectionSafely( 836 bool UsbListInterfacesFunction::ConvertDirectionSafely(
819 const UsbEndpointDirection& input, 837 const UsbEndpointDirection& input,
820 usb::Direction* output) { 838 usb::Direction* output) {
821 const bool converted = ConvertDirectionToApi(input, output); 839 const bool converted = ConvertDirectionToApi(input, output);
822 if (!converted) 840 if (!converted)
823 SetError(kErrorConvertDirection); 841 SetError(kErrorConvertDirection);
824 return converted; 842 return converted;
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 SetResult(new base::FundamentalValue(false)); 1216 SetResult(new base::FundamentalValue(false));
1199 CompleteWithError(kErrorResetDevice); 1217 CompleteWithError(kErrorResetDevice);
1200 return; 1218 return;
1201 } 1219 }
1202 1220
1203 SetResult(new base::FundamentalValue(true)); 1221 SetResult(new base::FundamentalValue(true));
1204 AsyncWorkCompleted(); 1222 AsyncWorkCompleted();
1205 } 1223 }
1206 1224
1207 } // namespace extensions 1225 } // namespace extensions
OLDNEW
« 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