Index: chrome/browser/devtools/device/usb/android_usb_device.cc |
diff --git a/chrome/browser/devtools/device/usb/android_usb_device.cc b/chrome/browser/devtools/device/usb/android_usb_device.cc |
index 8ef9416ff8ca1b28054c3e241325e3ed1fd9b45e..55b47c7bf3a734641bb3e2cec9e2c438d53f5848 100644 |
--- a/chrome/browser/devtools/device/usb/android_usb_device.cc |
+++ b/chrome/browser/devtools/device/usb/android_usb_device.cc |
@@ -19,8 +19,8 @@ |
#include "content/public/browser/browser_thread.h" |
#include "crypto/rsa_private_key.h" |
#include "device/core/device_client.h" |
+#include "device/usb/usb_descriptors.h" |
#include "device/usb/usb_device.h" |
-#include "device/usb/usb_interface.h" |
#include "device/usb/usb_service.h" |
#include "net/base/ip_endpoint.h" |
#include "net/base/net_errors.h" |
@@ -29,7 +29,6 @@ |
using device::UsbConfigDescriptor; |
using device::UsbDevice; |
using device::UsbDeviceHandle; |
-using device::UsbInterfaceAltSettingDescriptor; |
using device::UsbInterfaceDescriptor; |
using device::UsbEndpointDescriptor; |
using device::UsbService; |
@@ -59,17 +58,12 @@ typedef std::set<scoped_refptr<UsbDevice> > UsbDeviceSet; |
base::LazyInstance<std::vector<AndroidUsbDevice*> >::Leaky g_devices = |
LAZY_INSTANCE_INITIALIZER; |
-bool IsAndroidInterface(scoped_refptr<const UsbInterfaceDescriptor> interface) { |
- if (interface->GetNumAltSettings() == 0) |
- return false; |
- |
- scoped_refptr<const UsbInterfaceAltSettingDescriptor> idesc = |
- interface->GetAltSetting(0); |
- |
- if (idesc->GetInterfaceClass() != kAdbClass || |
- idesc->GetInterfaceSubclass() != kAdbSubclass || |
- idesc->GetInterfaceProtocol() != kAdbProtocol || |
- idesc->GetNumEndpoints() != 2) { |
+bool IsAndroidInterface(const UsbInterfaceDescriptor& interface) { |
+ if (interface.alternate_setting != 0 || |
+ interface.interface_class != kAdbClass || |
+ interface.interface_subclass != kAdbSubclass || |
+ interface.interface_protocol != kAdbProtocol || |
+ interface.endpoints.size() != 2) { |
return false; |
} |
return true; |
@@ -78,40 +72,40 @@ bool IsAndroidInterface(scoped_refptr<const UsbInterfaceDescriptor> interface) { |
scoped_refptr<AndroidUsbDevice> ClaimInterface( |
crypto::RSAPrivateKey* rsa_key, |
scoped_refptr<UsbDeviceHandle> usb_handle, |
- scoped_refptr<const UsbInterfaceDescriptor> interface, |
- int interface_id) { |
- scoped_refptr<const UsbInterfaceAltSettingDescriptor> idesc = |
- interface->GetAltSetting(0); |
- |
+ const UsbInterfaceDescriptor& interface) { |
int inbound_address = 0; |
int outbound_address = 0; |
int zero_mask = 0; |
- for (size_t i = 0; i < idesc->GetNumEndpoints(); ++i) { |
- scoped_refptr<const UsbEndpointDescriptor> edesc = |
- idesc->GetEndpoint(i); |
- if (edesc->GetTransferType() != device::USB_TRANSFER_BULK) |
+ for (UsbEndpointDescriptor::Iterator endpointIt = interface.endpoints.begin(); |
+ endpointIt != interface.endpoints.end(); |
+ ++endpointIt) { |
+ if (endpointIt->transfer_type != device::USB_TRANSFER_BULK) |
continue; |
- if (edesc->GetDirection() == device::USB_DIRECTION_INBOUND) |
- inbound_address = edesc->GetAddress(); |
+ if (endpointIt->direction == device::USB_DIRECTION_INBOUND) |
+ inbound_address = endpointIt->address; |
else |
- outbound_address = edesc->GetAddress(); |
- zero_mask = edesc->GetMaximumPacketSize() - 1; |
+ outbound_address = endpointIt->address; |
+ zero_mask = endpointIt->maximum_packet_size - 1; |
} |
if (inbound_address == 0 || outbound_address == 0) |
return NULL; |
- if (!usb_handle->ClaimInterface(interface_id)) |
+ if (!usb_handle->ClaimInterface(interface.interface_number)) |
return NULL; |
base::string16 serial; |
if (!usb_handle->GetSerial(&serial) || serial.empty()) |
return NULL; |
- return new AndroidUsbDevice(rsa_key, usb_handle, base::UTF16ToASCII(serial), |
- inbound_address, outbound_address, zero_mask, |
- interface_id); |
+ return new AndroidUsbDevice(rsa_key, |
+ usb_handle, |
+ base::UTF16ToASCII(serial), |
+ inbound_address, |
+ outbound_address, |
+ zero_mask, |
+ interface.interface_number); |
} |
uint32 Checksum(const std::string& data) { |
@@ -207,12 +201,11 @@ static void OpenAndroidDeviceOnFileThread( |
bool success) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
if (success) { |
- scoped_refptr<UsbConfigDescriptor> config = device->ListInterfaces(); |
+ const UsbConfigDescriptor& config = device->GetConfiguration(); |
scoped_refptr<UsbDeviceHandle> usb_handle = device->Open(); |
if (usb_handle.get()) { |
scoped_refptr<AndroidUsbDevice> android_device = |
- ClaimInterface(rsa_key, usb_handle, config->GetInterface(interface_id), |
- interface_id); |
+ ClaimInterface(rsa_key, usb_handle, config.interfaces[interface_id]); |
if (android_device.get()) |
devices->push_back(android_device.get()); |
else |
@@ -229,15 +222,17 @@ static int CountOnFileThread() { |
if (service != NULL) |
service->GetDevices(&usb_devices); |
int device_count = 0; |
- for (UsbDevices::iterator it = usb_devices.begin(); it != usb_devices.end(); |
- ++it) { |
- scoped_refptr<UsbConfigDescriptor> config = (*it)->ListInterfaces(); |
- if (!config.get()) |
- continue; |
- |
- for (size_t j = 0; j < config->GetNumInterfaces(); ++j) { |
- if (IsAndroidInterface(config->GetInterface(j))) |
+ for (UsbDevices::iterator deviceIt = usb_devices.begin(); |
+ deviceIt != usb_devices.end(); |
+ ++deviceIt) { |
+ const UsbConfigDescriptor& config = (*deviceIt)->GetConfiguration(); |
+ |
+ for (UsbInterfaceDescriptor::Iterator ifaceIt = config.interfaces.begin(); |
+ ifaceIt != config.interfaces.end(); |
+ ++ifaceIt) { |
+ if (IsAndroidInterface(*ifaceIt)) { |
++device_count; |
+ } |
} |
} |
return device_count; |
@@ -264,16 +259,13 @@ static void EnumerateOnFileThread( |
for (UsbDevices::iterator it = usb_devices.begin(); it != usb_devices.end(); |
++it) { |
- scoped_refptr<UsbConfigDescriptor> config = (*it)->ListInterfaces(); |
- if (!config.get()) { |
- barrier.Run(); |
- continue; |
- } |
+ const UsbConfigDescriptor& config = (*it)->GetConfiguration(); |
bool has_android_interface = false; |
- for (size_t j = 0; j < config->GetNumInterfaces(); ++j) { |
- if (!IsAndroidInterface(config->GetInterface(j))) |
+ for (size_t j = 0; j < config.interfaces.size(); ++j) { |
+ if (!IsAndroidInterface(config.interfaces[j])) { |
continue; |
+ } |
// Request permission on Chrome OS. |
#if defined(OS_CHROMEOS) |