| Index: chrome/browser/usb/usb_device.cc
|
| diff --git a/chrome/browser/usb/usb_device.cc b/chrome/browser/usb/usb_device.cc
|
| index 544f49e1c6d5f0c498247fec47b46e5c393da7b4..3e30a0d3f723ccdf68150e4f1ff57b7b52e8e4ec 100644
|
| --- a/chrome/browser/usb/usb_device.cc
|
| +++ b/chrome/browser/usb/usb_device.cc
|
| @@ -4,26 +4,29 @@
|
|
|
| #include "chrome/browser/usb/usb_device.h"
|
|
|
| +#include <vector>
|
| +
|
| #include "base/stl_util.h"
|
| #include "base/synchronization/lock.h"
|
| +#include "chrome/browser/usb/usb_interface.h"
|
| #include "chrome/browser/usb/usb_service.h"
|
| #include "third_party/libusb/src/libusb/libusb.h"
|
|
|
| namespace {
|
|
|
| static uint8 ConvertTransferDirection(
|
| - const UsbDevice::TransferDirection direction) {
|
| + const UsbInterfaceDirection direction) {
|
| switch (direction) {
|
| - case UsbDevice::INBOUND:
|
| + case USB_DIRECTION_INBOUND:
|
| return LIBUSB_ENDPOINT_IN;
|
| - case UsbDevice::OUTBOUND:
|
| + case USB_DIRECTION_OUTBOUND:
|
| return LIBUSB_ENDPOINT_OUT;
|
| }
|
| NOTREACHED();
|
| return LIBUSB_ENDPOINT_OUT;
|
| }
|
|
|
| -static uint8 CreateRequestType(const UsbDevice::TransferDirection direction,
|
| +static uint8 CreateRequestType(const UsbInterfaceDirection direction,
|
| const UsbDevice::TransferRequestType request_type,
|
| const UsbDevice::TransferRecipient recipient) {
|
| uint8 result = ConvertTransferDirection(direction);
|
| @@ -127,7 +130,7 @@ void UsbDevice::TransferComplete(PlatformUsbTransferHandle handle) {
|
|
|
| scoped_refptr<net::IOBuffer> buffer = transfer->buffer;
|
| switch (transfer->transfer_type) {
|
| - case USB_TRANSFER_CONTROL:
|
| + case USB_ENDPOINT_CONTROL:
|
| // If the transfer is a control transfer we do not expose the control
|
| // setup header to the caller. This logic strips off the header if
|
| // present before invoking the callback provided with the transfer.
|
| @@ -149,7 +152,7 @@ void UsbDevice::TransferComplete(PlatformUsbTransferHandle handle) {
|
| }
|
| break;
|
|
|
| - case USB_TRANSFER_ISOCHRONOUS:
|
| + case USB_ENDPOINT_ISOCHRONOUS:
|
| // Isochronous replies might carry data in the different isoc packets even
|
| // if the transfer actual_data value is zero. Furthermore, not all of the
|
| // received packets might contain data, so we need to calculate how many
|
| @@ -176,8 +179,8 @@ void UsbDevice::TransferComplete(PlatformUsbTransferHandle handle) {
|
| }
|
| break;
|
|
|
| - case USB_TRANSFER_BULK:
|
| - case USB_TRANSFER_INTERRUPT:
|
| + case USB_ENDPOINT_BULK:
|
| + case USB_ENDPOINT_INTERRUPT:
|
| break;
|
|
|
| default:
|
| @@ -191,6 +194,14 @@ void UsbDevice::TransferComplete(PlatformUsbTransferHandle handle) {
|
| libusb_free_transfer(handle);
|
| }
|
|
|
| +void UsbDevice::ListInterfaces(PlatformUsbConfigDescriptor* config,
|
| + const UsbInterfaceCallback& callback) {
|
| + PlatformUsbDevice device = libusb_get_device(handle_);
|
| +
|
| + const int list_result = libusb_get_active_config_descriptor(device, config);
|
| + callback.Run(list_result == 0);
|
| +}
|
| +
|
| void UsbDevice::ClaimInterface(const int interface_number,
|
| const UsbInterfaceCallback& callback) {
|
| CheckDevice();
|
| @@ -220,7 +231,7 @@ void UsbDevice::SetInterfaceAlternateSetting(
|
| callback.Run(setting_result == 0);
|
| }
|
|
|
| -void UsbDevice::ControlTransfer(const TransferDirection direction,
|
| +void UsbDevice::ControlTransfer(const UsbInterfaceDirection direction,
|
| const TransferRequestType request_type, const TransferRecipient recipient,
|
| const uint8 request, const uint16 value, const uint16 index,
|
| net::IOBuffer* buffer, const size_t length, const unsigned int timeout,
|
| @@ -240,11 +251,11 @@ void UsbDevice::ControlTransfer(const TransferDirection direction,
|
| converted_type, request, value, index, length);
|
| libusb_fill_control_transfer(transfer, handle_, reinterpret_cast<uint8*>(
|
| resized_buffer->data()), HandleTransferCompletion, this, timeout);
|
| - SubmitTransfer(transfer, USB_TRANSFER_CONTROL, resized_buffer, resized_length,
|
| + SubmitTransfer(transfer, USB_ENDPOINT_CONTROL, resized_buffer, resized_length,
|
| callback);
|
| }
|
|
|
| -void UsbDevice::BulkTransfer(const TransferDirection direction,
|
| +void UsbDevice::BulkTransfer(const UsbInterfaceDirection direction,
|
| const uint8 endpoint, net::IOBuffer* buffer, const size_t length,
|
| const unsigned int timeout, const UsbTransferCallback& callback) {
|
| CheckDevice();
|
| @@ -254,10 +265,10 @@ void UsbDevice::BulkTransfer(const TransferDirection direction,
|
| libusb_fill_bulk_transfer(transfer, handle_, new_endpoint,
|
| reinterpret_cast<uint8*>(buffer->data()), length,
|
| HandleTransferCompletion, this, timeout);
|
| - SubmitTransfer(transfer, USB_TRANSFER_BULK, buffer, length, callback);
|
| + SubmitTransfer(transfer, USB_ENDPOINT_BULK, buffer, length, callback);
|
| }
|
|
|
| -void UsbDevice::InterruptTransfer(const TransferDirection direction,
|
| +void UsbDevice::InterruptTransfer(const UsbInterfaceDirection direction,
|
| const uint8 endpoint, net::IOBuffer* buffer, const size_t length,
|
| const unsigned int timeout, const UsbTransferCallback& callback) {
|
| CheckDevice();
|
| @@ -267,10 +278,10 @@ void UsbDevice::InterruptTransfer(const TransferDirection direction,
|
| libusb_fill_interrupt_transfer(transfer, handle_, new_endpoint,
|
| reinterpret_cast<uint8*>(buffer->data()), length,
|
| HandleTransferCompletion, this, timeout);
|
| - SubmitTransfer(transfer, USB_TRANSFER_INTERRUPT, buffer, length, callback);
|
| + SubmitTransfer(transfer, USB_ENDPOINT_INTERRUPT, buffer, length, callback);
|
| }
|
|
|
| -void UsbDevice::IsochronousTransfer(const TransferDirection direction,
|
| +void UsbDevice::IsochronousTransfer(const UsbInterfaceDirection direction,
|
| const uint8 endpoint, net::IOBuffer* buffer, const size_t length,
|
| const unsigned int packets, const unsigned int packet_length,
|
| const unsigned int timeout, const UsbTransferCallback& callback) {
|
| @@ -287,7 +298,7 @@ void UsbDevice::IsochronousTransfer(const TransferDirection direction,
|
| HandleTransferCompletion, this, timeout);
|
| libusb_set_iso_packet_lengths(transfer, packet_length);
|
|
|
| - SubmitTransfer(transfer, USB_TRANSFER_ISOCHRONOUS, buffer, length, callback);
|
| + SubmitTransfer(transfer, USB_ENDPOINT_ISOCHRONOUS, buffer, length, callback);
|
| }
|
|
|
| void UsbDevice::CheckDevice() {
|
| @@ -295,7 +306,7 @@ void UsbDevice::CheckDevice() {
|
| }
|
|
|
| void UsbDevice::SubmitTransfer(PlatformUsbTransferHandle handle,
|
| - UsbTransferType transfer_type,
|
| + UsbEndpointType transfer_type,
|
| net::IOBuffer* buffer,
|
| const size_t length,
|
| const UsbTransferCallback& callback) {
|
|
|