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

Unified Diff: chrome/browser/devtools/device/usb/android_usb_device.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: 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..6eab9e7594d5302dbbac91fd32786387208cae5e 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 ||
dgozman 2014/09/11 11:23:47 Did you change the meaning of this field? If not,
Reilly Grant (use Gerrit) 2014/09/11 17:49:26 I didn't change the meaning. alternate_setting ==
dgozman 2014/09/12 11:03:34 Thanks for clarification, was not obvious to me.
+ interface.interface_class != kAdbClass ||
+ interface.interface_subclass != kAdbSubclass ||
+ interface.interface_protocol != kAdbProtocol ||
+ interface.endpoints.size() != 2) {
return false;
}
return true;
@@ -78,40 +72,39 @@ 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 (size_t i = 0; i < interface.endpoints.size(); ++i) {
+ const UsbEndpointDescriptor& edesc = interface.endpoints[i];
+ if (edesc.transfer_type != device::USB_TRANSFER_BULK)
continue;
- if (edesc->GetDirection() == device::USB_DIRECTION_INBOUND)
- inbound_address = edesc->GetAddress();
+ if (edesc.direction == device::USB_DIRECTION_INBOUND)
+ inbound_address = edesc.address;
else
- outbound_address = edesc->GetAddress();
- zero_mask = edesc->GetMaximumPacketSize() - 1;
+ outbound_address = edesc.address;
+ zero_mask = edesc.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 +200,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
@@ -231,13 +223,12 @@ static int CountOnFileThread() {
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;
+ const UsbConfigDescriptor& config = (*it)->GetConfiguration();
- 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])) {
++device_count;
+ }
}
}
return device_count;
@@ -264,15 +255,11 @@ 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.

Powered by Google App Engine
This is Rietveld 408576698