Skip to content

Commit

Permalink
Merge components/usb_service into device/usb.
Browse files Browse the repository at this point in the history
Unify these two parts of out USB device support. The //device tree is
the cannonical location for hardware device APIs.

BUG=

Review URL: https://codereview.chromium.org/497363004

Cr-Commit-Position: refs/heads/master@{#293246}
  • Loading branch information
reillyeon authored and Commit bot committed Sep 4, 2014
1 parent 6b0fbe4 commit d77718d
Show file tree
Hide file tree
Showing 58 changed files with 410 additions and 468 deletions.
8 changes: 7 additions & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ group("root") {
"//crypto",
"//device/bluetooth",
"//device/nfc",
"//device/usb",
"//extensions/browser",
"//extensions/common",
"//extensions/common/api",
Expand Down Expand Up @@ -237,4 +236,11 @@ group("root") {
"//ui/ozone/demo",
]
}

# Non-mobile builds.
if (!is_android && !is_ios) {
deps += [
"//device/usb",
]
}
}
2 changes: 1 addition & 1 deletion chrome/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ static_library("browser") {
sources += rebase_path(gypi_values.chrome_browser_non_mobile_sources,
".", "//chrome")
deps += [
"//components/usb_service",
"//device/core",
"//device/usb",
]
}

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ include_rules = [
"+components/translate/core/browser",
"+components/translate/core/common",
"+components/url_matcher",
"+components/usb_service",
"+components/user_manager",
"+components/user_prefs",
"+components/web_modal",
Expand All @@ -80,6 +79,7 @@ include_rules = [
"+courgette",
"+device/bluetooth",
"+device/core",
"+device/usb",
"+device/media_transfer_protocol",
"+extensions/browser",
"+extensions/common",
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/chrome_device_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
#include "chrome/browser/chrome_device_client.h"

#include "base/logging.h"
#include "components/usb_service/usb_service.h"
#include "content/public/browser/browser_thread.h"
#include "device/usb/usb_service.h"

ChromeDeviceClient::ChromeDeviceClient() {}

ChromeDeviceClient::~ChromeDeviceClient() {}

usb_service::UsbService* ChromeDeviceClient::GetUsbService() {
return usb_service::UsbService::GetInstance(
device::UsbService* ChromeDeviceClient::GetUsbService() {
return device::UsbService::GetInstance(
content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::UI));
}
2 changes: 1 addition & 1 deletion chrome/browser/chrome_device_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ChromeDeviceClient : device::DeviceClient {
virtual ~ChromeDeviceClient();

// device::DeviceClient implementation
virtual usb_service::UsbService* GetUsbService() OVERRIDE;
virtual device::UsbService* GetUsbService() OVERRIDE;

private:
DISALLOW_COPY_AND_ASSIGN(ChromeDeviceClient);
Expand Down
35 changes: 23 additions & 12 deletions chrome/browser/devtools/device/usb/android_usb_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,27 @@
#include "chrome/browser/devtools/device/usb/usb_device_provider.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/usb_service/usb_device.h"
#include "components/usb_service/usb_device_handle.h"
#include "components/usb_service/usb_interface.h"
#include "components/usb_service/usb_service.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/test_utils.h"
#include "device/usb/usb_device.h"
#include "device/usb/usb_device_handle.h"
#include "device/usb/usb_interface.h"
#include "device/usb/usb_service.h"
#include "testing/gtest/include/gtest/gtest.h"

using content::BrowserThread;
using namespace usb_service;
using device::UsbConfigDescriptor;
using device::UsbDevice;
using device::UsbDeviceHandle;
using device::UsbEndpointDescriptor;
using device::UsbEndpointDirection;
using device::UsbInterfaceDescriptor;
using device::UsbInterfaceAltSettingDescriptor;
using device::UsbService;
using device::UsbSynchronizationType;
using device::UsbTransferCallback;
using device::UsbTransferType;
using device::UsbUsageType;

namespace {

Expand Down Expand Up @@ -147,9 +158,9 @@ class MockUsbInterfaceAltSettingDescriptor
EXPECT_GT(static_cast<size_t>(2), index);
MockUsbEndpointDescriptor* result = new MockUsbEndpointDescriptor();
result->address_ = index + 1;
result->usb_transfer_type_ = USB_TRANSFER_BULK;
result->direction_ =
((index == 0) ? USB_DIRECTION_INBOUND : USB_DIRECTION_OUTBOUND);
result->usb_transfer_type_ = device::USB_TRANSFER_BULK;
result->direction_ = ((index == 0) ? device::USB_DIRECTION_INBOUND
: device::USB_DIRECTION_OUTBOUND);
result->maximum_packet_size_ = 1 << 20; // 1Mb maximum packet size
return result;
}
Expand Down Expand Up @@ -288,7 +299,7 @@ class MockUsbDeviceHandle : public UsbDeviceHandle {
const size_t length,
const unsigned int timeout,
const UsbTransferCallback& callback) OVERRIDE {
if (direction == USB_DIRECTION_OUTBOUND) {
if (direction == device::USB_DIRECTION_OUTBOUND) {
if (remaining_body_length_ == 0) {
std::vector<uint32> header(6);
memcpy(&header[0], buffer->data(), length);
Expand All @@ -312,11 +323,11 @@ class MockUsbDeviceHandle : public UsbDeviceHandle {
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(callback,
usb_service::USB_TRANSFER_COMPLETED,
device::USB_TRANSFER_COMPLETED,
scoped_refptr<net::IOBuffer>(),
0));

} else if (direction == USB_DIRECTION_INBOUND) {
} else if (direction == device::USB_DIRECTION_INBOUND) {
queries_.push(Query(callback, make_scoped_refptr(buffer), length));
ProcessQueries();
}
Expand Down Expand Up @@ -408,7 +419,7 @@ class MockUsbDeviceHandle : public UsbDeviceHandle {
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(query.callback,
usb_service::USB_TRANSFER_COMPLETED,
device::USB_TRANSFER_COMPLETED,
query.buffer,
query.size));
}
Expand Down
49 changes: 24 additions & 25 deletions chrome/browser/devtools/device/usb/android_usb_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/devtools/device/usb/android_rsa.h"
#include "chrome/browser/devtools/device/usb/android_usb_socket.h"
#include "components/usb_service/usb_device.h"
#include "components/usb_service/usb_interface.h"
#include "components/usb_service/usb_service.h"
#include "content/public/browser/browser_thread.h"
#include "crypto/rsa_private_key.h"
#include "device/core/device_client.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"
#include "net/socket/stream_socket.h"

using usb_service::UsbConfigDescriptor;
using usb_service::UsbDevice;
using usb_service::UsbDeviceHandle;
using usb_service::UsbInterfaceAltSettingDescriptor;
using usb_service::UsbInterfaceDescriptor;
using usb_service::UsbEndpointDescriptor;
using usb_service::UsbService;
using usb_service::UsbTransferStatus;
using device::UsbConfigDescriptor;
using device::UsbDevice;
using device::UsbDeviceHandle;
using device::UsbInterfaceAltSettingDescriptor;
using device::UsbInterfaceDescriptor;
using device::UsbEndpointDescriptor;
using device::UsbService;
using device::UsbTransferStatus;

namespace {

Expand All @@ -59,8 +59,7 @@ typedef std::set<scoped_refptr<UsbDevice> > UsbDeviceSet;
base::LazyInstance<std::vector<AndroidUsbDevice*> >::Leaky g_devices =
LAZY_INSTANCE_INITIALIZER;

bool IsAndroidInterface(
scoped_refptr<const usb_service::UsbInterfaceDescriptor> interface) {
bool IsAndroidInterface(scoped_refptr<const UsbInterfaceDescriptor> interface) {
if (interface->GetNumAltSettings() == 0)
return false;

Expand Down Expand Up @@ -91,9 +90,9 @@ scoped_refptr<AndroidUsbDevice> ClaimInterface(
for (size_t i = 0; i < idesc->GetNumEndpoints(); ++i) {
scoped_refptr<const UsbEndpointDescriptor> edesc =
idesc->GetEndpoint(i);
if (edesc->GetTransferType() != usb_service::USB_TRANSFER_BULK)
if (edesc->GetTransferType() != device::USB_TRANSFER_BULK)
continue;
if (edesc->GetDirection() == usb_service::USB_DIRECTION_INBOUND)
if (edesc->GetDirection() == device::USB_DIRECTION_INBOUND)
inbound_address = edesc->GetAddress();
else
outbound_address = edesc->GetAddress();
Expand Down Expand Up @@ -431,7 +430,7 @@ void AndroidUsbDevice::ProcessOutgoing() {
BulkMessage message = outgoing_queue_.front();
outgoing_queue_.pop();
DumpMessage(true, message->data(), message->size());
usb_handle_->BulkTransfer(usb_service::USB_DIRECTION_OUTBOUND,
usb_handle_->BulkTransfer(device::USB_DIRECTION_OUTBOUND,
outbound_address_,
message.get(),
message->size(),
Expand All @@ -445,7 +444,7 @@ void AndroidUsbDevice::OutgoingMessageSent(UsbTransferStatus status,
size_t result) {
DCHECK(message_loop_ == base::MessageLoop::current());

if (status != usb_service::USB_TRANSFER_COMPLETED)
if (status != device::USB_TRANSFER_COMPLETED)
return;
message_loop_->PostTask(FROM_HERE,
base::Bind(&AndroidUsbDevice::ProcessOutgoing, this));
Expand All @@ -458,7 +457,7 @@ void AndroidUsbDevice::ReadHeader() {
return;
scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kHeaderSize);
usb_handle_->BulkTransfer(
usb_service::USB_DIRECTION_INBOUND,
device::USB_DIRECTION_INBOUND,
inbound_address_,
buffer.get(),
kHeaderSize,
Expand All @@ -471,13 +470,13 @@ void AndroidUsbDevice::ParseHeader(UsbTransferStatus status,
size_t result) {
DCHECK(message_loop_ == base::MessageLoop::current());

if (status == usb_service::USB_TRANSFER_TIMEOUT) {
if (status == device::USB_TRANSFER_TIMEOUT) {
message_loop_->PostTask(FROM_HERE,
base::Bind(&AndroidUsbDevice::ReadHeader, this));
return;
}

if (status != usb_service::USB_TRANSFER_COMPLETED || result != kHeaderSize) {
if (status != device::USB_TRANSFER_COMPLETED || result != kHeaderSize) {
TransferError(status);
return;
}
Expand All @@ -491,7 +490,7 @@ void AndroidUsbDevice::ParseHeader(UsbTransferStatus status,
uint32 data_check = header[4];
uint32 magic = header[5];
if ((message->command ^ 0xffffffff) != magic) {
TransferError(usb_service::USB_TRANSFER_ERROR);
TransferError(device::USB_TRANSFER_ERROR);
return;
}

Expand All @@ -515,7 +514,7 @@ void AndroidUsbDevice::ReadBody(scoped_refptr<AdbMessage> message,
if (!usb_handle_.get())
return;
scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(data_length);
usb_handle_->BulkTransfer(usb_service::USB_DIRECTION_INBOUND,
usb_handle_->BulkTransfer(device::USB_DIRECTION_INBOUND,
inbound_address_,
buffer.get(),
data_length,
Expand All @@ -535,14 +534,14 @@ void AndroidUsbDevice::ParseBody(scoped_refptr<AdbMessage> message,
size_t result) {
DCHECK(message_loop_ == base::MessageLoop::current());

if (status == usb_service::USB_TRANSFER_TIMEOUT) {
if (status == device::USB_TRANSFER_TIMEOUT) {
message_loop_->PostTask(FROM_HERE,
base::Bind(&AndroidUsbDevice::ReadBody, this,
message, data_length, data_check));
return;
}

if (status != usb_service::USB_TRANSFER_COMPLETED ||
if (status != device::USB_TRANSFER_COMPLETED ||
static_cast<uint32>(result) != data_length) {
TransferError(status);
return;
Expand All @@ -551,7 +550,7 @@ void AndroidUsbDevice::ParseBody(scoped_refptr<AdbMessage> message,
DumpMessage(false, buffer->data(), data_length);
message->body = std::string(buffer->data(), result);
if (Checksum(message->body) != data_check) {
TransferError(usb_service::USB_TRANSFER_ERROR);
TransferError(device::USB_TRANSFER_ERROR);
return;
}

Expand Down
22 changes: 10 additions & 12 deletions chrome/browser/devtools/device/usb/android_usb_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
#include <map>
#include <queue>
#include <vector>

#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "components/usb_service/usb_device_handle.h"
#include "device/usb/usb_device_handle.h"

namespace base {
class MessageLoop;
Expand Down Expand Up @@ -73,7 +74,7 @@ class AndroidUsbDevice : public base::RefCountedThreadSafe<AndroidUsbDevice> {
static void CountDevices(const base::Callback<void(int)>& callback);

AndroidUsbDevice(crypto::RSAPrivateKey* rsa_key,
scoped_refptr<usb_service::UsbDeviceHandle> device,
scoped_refptr<device::UsbDeviceHandle> device,
const std::string& serial,
int inbound_address,
int outbound_address,
Expand All @@ -89,9 +90,7 @@ class AndroidUsbDevice : public base::RefCountedThreadSafe<AndroidUsbDevice> {
uint32 arg1,
const std::string& body);

scoped_refptr<usb_service::UsbDeviceHandle> usb_device() {
return usb_handle_;
}
scoped_refptr<device::UsbDeviceHandle> usb_device() { return usb_handle_; }

std::string serial() { return serial_; }

Expand All @@ -103,12 +102,12 @@ class AndroidUsbDevice : public base::RefCountedThreadSafe<AndroidUsbDevice> {

void Queue(scoped_refptr<AdbMessage> message);
void ProcessOutgoing();
void OutgoingMessageSent(usb_service::UsbTransferStatus status,
void OutgoingMessageSent(device::UsbTransferStatus status,
scoped_refptr<net::IOBuffer> buffer,
size_t result);

void ReadHeader();
void ParseHeader(usb_service::UsbTransferStatus status,
void ParseHeader(device::UsbTransferStatus status,
scoped_refptr<net::IOBuffer> buffer,
size_t result);

Expand All @@ -118,16 +117,15 @@ class AndroidUsbDevice : public base::RefCountedThreadSafe<AndroidUsbDevice> {
void ParseBody(scoped_refptr<AdbMessage> message,
uint32 data_length,
uint32 data_check,
usb_service::UsbTransferStatus status,
device::UsbTransferStatus status,
scoped_refptr<net::IOBuffer> buffer,
size_t result);

void HandleIncoming(scoped_refptr<AdbMessage> message);

void TransferError(usb_service::UsbTransferStatus status);
void TransferError(device::UsbTransferStatus status);

void TerminateIfReleased(
scoped_refptr<usb_service::UsbDeviceHandle> usb_handle);
void TerminateIfReleased(scoped_refptr<device::UsbDeviceHandle> usb_handle);
void Terminate();

void SocketDeleted(uint32 socket_id);
Expand All @@ -137,7 +135,7 @@ class AndroidUsbDevice : public base::RefCountedThreadSafe<AndroidUsbDevice> {
scoped_ptr<crypto::RSAPrivateKey> rsa_key_;

// Device info
scoped_refptr<usb_service::UsbDeviceHandle> usb_handle_;
scoped_refptr<device::UsbDeviceHandle> usb_handle_;
std::string serial_;
int inbound_address_;
int outbound_address_;
Expand Down
2 changes: 1 addition & 1 deletion chrome/chrome_browser.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -3239,8 +3239,8 @@
}, { # OS!="android" and OS!="ios"
'sources': [ '<@(chrome_browser_non_mobile_sources)' ],
'dependencies': [
'../components/components.gyp:usb_service',
'../device/core/core.gyp:device_core',
'../device/usb/usb.gyp:device_usb',
]
}],
['OS=="android"', {
Expand Down
2 changes: 0 additions & 2 deletions components/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ group("all_components") {
"//components/translate/core/common",
"//components/url_fixer",
"//components/url_matcher",
"//components/usb_service",
"//components/user_manager",
"//components/user_prefs",
"//components/variations",
Expand Down Expand Up @@ -167,7 +166,6 @@ group("all_components") {
"//components/translate/content/browser", # Blocked on content.
"//components/translate/content/common", # Blocked on content.
"//components/translate/content/renderer", # Blocked on content.
"//components/usb_service", # Blocked on content.
"//components/user_prefs", # Blocked on content.
"//components/visitedlink/browser", # Blocked on content.
"//components/visitedlink/common", # Blocked on content.
Expand Down
Loading

0 comments on commit d77718d

Please sign in to comment.