summaryrefslogtreecommitdiffstats
path: root/device/devices_app/usb
diff options
context:
space:
mode:
authorjuncai <juncai@chromium.org>2015-09-02 16:17:03 -0700
committerCommit bot <commit-bot@chromium.org>2015-09-02 23:17:48 +0000
commit83a819e8c160f3aa1a718e044bb6a46b9db99b28 (patch)
tree86758c27b3f1d5dfd2a2681ac37bd90be79e99e7 /device/devices_app/usb
parent82adc49d7906cdde494f72cdbf5aecbf457a79c7 (diff)
downloadchromium_src-83a819e8c160f3aa1a718e044bb6a46b9db99b28.zip
chromium_src-83a819e8c160f3aa1a718e044bb6a46b9db99b28.tar.gz
chromium_src-83a819e8c160f3aa1a718e044bb6a46b9db99b28.tar.bz2
Add generic transfer functions to device.mojom
This patch replaced BulkTransferIn, BulkTransferOut, InterruptTransferIn, InterruptTransferOut with GenericTransferIn and GenericTransferOut. Review URL: https://codereview.chromium.org/1325083003 Cr-Commit-Position: refs/heads/master@{#347058}
Diffstat (limited to 'device/devices_app/usb')
-rw-r--r--device/devices_app/usb/device_impl.cc51
-rw-r--r--device/devices_app/usb/device_impl.h26
-rw-r--r--device/devices_app/usb/device_impl_unittest.cc78
-rw-r--r--device/devices_app/usb/public/interfaces/device.mojom42
4 files changed, 37 insertions, 160 deletions
diff --git a/device/devices_app/usb/device_impl.cc b/device/devices_app/usb/device_impl.cc
index 798c115..8cf6dbd 100644
--- a/device/devices_app/usb/device_impl.cc
+++ b/device/devices_app/usb/device_impl.cc
@@ -234,62 +234,27 @@ void DeviceImpl::ControlTransferOut(
weak_factory_.GetWeakPtr(), callback));
}
-void DeviceImpl::BulkTransferIn(uint8_t endpoint_number,
- uint32_t length,
- uint32_t timeout,
- const BulkTransferInCallback& callback) {
- if (!device_handle_) {
- callback.Run(TRANSFER_STATUS_ERROR, mojo::Array<uint8_t>());
- return;
- }
-
- scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(length);
- device_handle_->BulkTransfer(
- USB_DIRECTION_INBOUND, endpoint_number, buffer, length, timeout,
- base::Bind(&DeviceImpl::OnTransferIn, weak_factory_.GetWeakPtr(),
- callback));
-}
-
-void DeviceImpl::BulkTransferOut(uint8_t endpoint_number,
- mojo::Array<uint8_t> data,
- uint32_t timeout,
- const BulkTransferOutCallback& callback) {
- if (!device_handle_) {
- callback.Run(TRANSFER_STATUS_ERROR);
- return;
- }
-
- scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(data.size());
- const std::vector<uint8_t>& storage = data.storage();
- std::copy(storage.begin(), storage.end(), buffer->data());
- device_handle_->BulkTransfer(
- USB_DIRECTION_OUTBOUND, endpoint_number, buffer, data.size(), timeout,
- base::Bind(&DeviceImpl::OnTransferOut, weak_factory_.GetWeakPtr(),
- callback));
-}
-
-void DeviceImpl::InterruptTransferIn(
- uint8_t endpoint_number,
- uint32_t length,
- uint32_t timeout,
- const InterruptTransferInCallback& callback) {
+void DeviceImpl::GenericTransferIn(uint8_t endpoint_number,
+ uint32_t length,
+ uint32_t timeout,
+ const GenericTransferInCallback& callback) {
if (!device_handle_) {
callback.Run(TRANSFER_STATUS_ERROR, mojo::Array<uint8_t>());
return;
}
scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(length);
- device_handle_->InterruptTransfer(
+ device_handle_->GenericTransfer(
USB_DIRECTION_INBOUND, endpoint_number, buffer, length, timeout,
base::Bind(&DeviceImpl::OnTransferIn, weak_factory_.GetWeakPtr(),
callback));
}
-void DeviceImpl::InterruptTransferOut(
+void DeviceImpl::GenericTransferOut(
uint8_t endpoint_number,
mojo::Array<uint8_t> data,
uint32_t timeout,
- const InterruptTransferOutCallback& callback) {
+ const GenericTransferOutCallback& callback) {
if (!device_handle_) {
callback.Run(TRANSFER_STATUS_ERROR);
return;
@@ -298,7 +263,7 @@ void DeviceImpl::InterruptTransferOut(
scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(data.size());
const std::vector<uint8_t>& storage = data.storage();
std::copy(storage.begin(), storage.end(), buffer->data());
- device_handle_->InterruptTransfer(
+ device_handle_->GenericTransfer(
USB_DIRECTION_OUTBOUND, endpoint_number, buffer, data.size(), timeout,
base::Bind(&DeviceImpl::OnTransferOut, weak_factory_.GetWeakPtr(),
callback));
diff --git a/device/devices_app/usb/device_impl.h b/device/devices_app/usb/device_impl.h
index a62a385..c827835 100644
--- a/device/devices_app/usb/device_impl.h
+++ b/device/devices_app/usb/device_impl.h
@@ -95,24 +95,14 @@ class DeviceImpl : public Device {
mojo::Array<uint8_t> data,
uint32_t timeout,
const ControlTransferOutCallback& callback) override;
- void BulkTransferIn(uint8_t endpoint_number,
- uint32_t length,
- uint32_t timeout,
- const BulkTransferInCallback& callback) override;
- void BulkTransferOut(uint8_t endpoint_number,
- mojo::Array<uint8_t> data,
- uint32_t timeout,
- const BulkTransferOutCallback& callback) override;
- void InterruptTransferIn(
- uint8_t endpoint_number,
- uint32_t length,
- uint32_t timeout,
- const InterruptTransferInCallback& callback) override;
- void InterruptTransferOut(
- uint8_t endpoint_number,
- mojo::Array<uint8_t> data,
- uint32_t timeout,
- const InterruptTransferOutCallback& callback) override;
+ void GenericTransferIn(uint8_t endpoint_number,
+ uint32_t length,
+ uint32_t timeout,
+ const GenericTransferInCallback& callback) override;
+ void GenericTransferOut(uint8_t endpoint_number,
+ mojo::Array<uint8_t> data,
+ uint32_t timeout,
+ const GenericTransferOutCallback& callback) override;
void IsochronousTransferIn(
uint8_t endpoint_number,
uint32_t num_packets,
diff --git a/device/devices_app/usb/device_impl_unittest.cc b/device/devices_app/usb/device_impl_unittest.cc
index 2cb1a83..433cbff 100644
--- a/device/devices_app/usb/device_impl_unittest.cc
+++ b/device/devices_app/usb/device_impl_unittest.cc
@@ -165,12 +165,8 @@ class USBDeviceImplTest : public testing::Test {
.WillByDefault(Invoke(this, &USBDeviceImplTest::ResetDevice));
ON_CALL(mock_handle(), ControlTransfer(_, _, _, _, _, _, _, _, _, _))
.WillByDefault(Invoke(this, &USBDeviceImplTest::ControlTransfer));
- ON_CALL(mock_handle(), BulkTransfer(_, _, _, _, _, _))
- .WillByDefault(
- Invoke(this, &USBDeviceImplTest::BulkOrInterruptTransfer));
- ON_CALL(mock_handle(), InterruptTransfer(_, _, _, _, _, _))
- .WillByDefault(
- Invoke(this, &USBDeviceImplTest::BulkOrInterruptTransfer));
+ ON_CALL(mock_handle(), GenericTransfer(_, _, _, _, _, _))
+ .WillByDefault(Invoke(this, &USBDeviceImplTest::GenericTransfer));
ON_CALL(mock_handle(), IsochronousTransfer(_, _, _, _, _, _, _, _))
.WillByDefault(Invoke(this, &USBDeviceImplTest::IsochronousTransfer));
@@ -293,13 +289,12 @@ class USBDeviceImplTest : public testing::Test {
OutboundTransfer(buffer, length, callback);
}
- void BulkOrInterruptTransfer(
- UsbEndpointDirection direction,
- uint8_t endpoint,
- scoped_refptr<net::IOBuffer> buffer,
- size_t length,
- unsigned int timeout,
- const UsbDeviceHandle::TransferCallback& callback) {
+ void GenericTransfer(UsbEndpointDirection direction,
+ uint8_t endpoint,
+ scoped_refptr<net::IOBuffer> buffer,
+ size_t length,
+ unsigned int timeout,
+ const UsbDeviceHandle::TransferCallback& callback) {
if (direction == USB_DIRECTION_INBOUND)
InboundTransfer(callback);
else
@@ -557,49 +552,7 @@ TEST_F(USBDeviceImplTest, ControlTransfer) {
EXPECT_CALL(mock_handle(), Close());
}
-TEST_F(USBDeviceImplTest, BulkTransfer) {
- DevicePtr device = GetMockDeviceProxy();
-
- std::string message1 = "say hello please";
- std::vector<uint8_t> fake_outbound_data(message1.size());
- std::copy(message1.begin(), message1.end(), fake_outbound_data.begin());
-
- std::string message2 = "hello world!";
- std::vector<uint8_t> fake_inbound_data(message2.size());
- std::copy(message2.begin(), message2.end(), fake_inbound_data.begin());
-
- AddMockConfig(ConfigBuilder(0).AddInterface(7, 0, 1, 2, 3));
- AddMockOutboundData(fake_outbound_data);
- AddMockInboundData(fake_inbound_data);
-
- EXPECT_CALL(mock_handle(), BulkTransfer(USB_DIRECTION_OUTBOUND, 0, _,
- fake_outbound_data.size(), 0, _));
-
- {
- base::RunLoop loop;
- device->BulkTransferOut(
- 0, mojo::Array<uint8_t>::From(fake_outbound_data), 0,
- base::Bind(&ExpectTransferStatusAndThen, TRANSFER_STATUS_COMPLETED,
- loop.QuitClosure()));
- loop.Run();
- }
-
- EXPECT_CALL(mock_handle(), BulkTransfer(USB_DIRECTION_INBOUND, 0, _,
- fake_inbound_data.size(), 0, _));
-
- {
- base::RunLoop loop;
- device->BulkTransferIn(
- 0, static_cast<uint32_t>(fake_inbound_data.size()), 0,
- base::Bind(&ExpectTransferInAndThen, TRANSFER_STATUS_COMPLETED,
- fake_inbound_data, loop.QuitClosure()));
- loop.Run();
- }
-
- EXPECT_CALL(mock_handle(), Close());
-}
-
-TEST_F(USBDeviceImplTest, InterruptTransfer) {
+TEST_F(USBDeviceImplTest, GenericTransfer) {
DevicePtr device = GetMockDeviceProxy();
std::string message1 = "say hello please";
@@ -614,25 +567,24 @@ TEST_F(USBDeviceImplTest, InterruptTransfer) {
AddMockOutboundData(fake_outbound_data);
AddMockInboundData(fake_inbound_data);
- EXPECT_CALL(mock_handle(),
- InterruptTransfer(USB_DIRECTION_OUTBOUND, 0, _,
- fake_outbound_data.size(), 0, _));
+ EXPECT_CALL(mock_handle(), GenericTransfer(USB_DIRECTION_OUTBOUND, 0, _,
+ fake_outbound_data.size(), 0, _));
{
base::RunLoop loop;
- device->InterruptTransferOut(
+ device->GenericTransferOut(
0, mojo::Array<uint8_t>::From(fake_outbound_data), 0,
base::Bind(&ExpectTransferStatusAndThen, TRANSFER_STATUS_COMPLETED,
loop.QuitClosure()));
loop.Run();
}
- EXPECT_CALL(mock_handle(), InterruptTransfer(USB_DIRECTION_INBOUND, 0, _,
- fake_inbound_data.size(), 0, _));
+ EXPECT_CALL(mock_handle(), GenericTransfer(USB_DIRECTION_INBOUND, 0, _,
+ fake_inbound_data.size(), 0, _));
{
base::RunLoop loop;
- device->InterruptTransferIn(
+ device->GenericTransferIn(
0, static_cast<uint32_t>(fake_inbound_data.size()), 0,
base::Bind(&ExpectTransferInAndThen, TRANSFER_STATUS_COMPLETED,
fake_inbound_data, loop.QuitClosure()));
diff --git a/device/devices_app/usb/public/interfaces/device.mojom b/device/devices_app/usb/public/interfaces/device.mojom
index 32181b1..ce600ec 100644
--- a/device/devices_app/usb/public/interfaces/device.mojom
+++ b/device/devices_app/usb/public/interfaces/device.mojom
@@ -168,11 +168,11 @@ interface Device {
uint32 timeout)
=> (TransferStatus status);
- // Initiates an inbound bulk transfer request on a specific endpoint. The
+ // Initiates an inbound generic transfer request on a specific endpoint. The
// interface to which |endpoint_number| belongs must be claimed, and the
// appropriate alternate setting must be set on that interface before
// transfers can be initiated on the endpoint. The endpoint must be of type
- // BULK.
+ // BULK or INTERRUPT.
//
// |length| specifies the expected number of bytes to receive for this
// transfer. The size of |data| will never exceed |length|, and |data| will be
@@ -181,51 +181,21 @@ interface Device {
// |timeout| specifies the request timeout in milliseconds. A timeout of 0
// indicates no timeout: the request will remain pending indefinitely until
// completed or otherwise terminated.
- BulkTransferIn(uint8 endpoint_number, uint32 length, uint32 timeout)
+ GenericTransferIn(uint8 endpoint_number, uint32 length, uint32 timeout)
=> (TransferStatus status, array<uint8>? data);
- // Initiates an outbound bulk transfer request on a specific endpoint. The
+ // Initiates an outbound generic transfer request on a specific endpoint. The
// interface to which |endpoint_number| belongs must be claimed, and the
// appropriate alternate setting must be set on that interface before
// transfers can be initiated on the endpoint. The endpoint must be of type
- // BULK.
+ // BULK or INTERRUPT.
//
// |data| specifies the bytes to send the device in the body of the request.
//
// |timeout| specifies the request timeout in milliseconds. A timeout of 0
// indicates no timeout: the request will remain pending indefinitely until
// completed or otherwise terminated.
- BulkTransferOut(uint8 endpoint_number, array<uint8> data, uint32 timeout)
- => (TransferStatus status);
-
- // Initiates an inbound interrupt transfer request on a specific endpoint. The
- // interface to which |endpoint_number| belongs must be claimed, and the
- // appropriate alternate setting must be set on that interface before
- // transfers can be initiated on the endpoint. The endpoint must be of type
- // INTERRUPT.
- //
- // |length| specifies the expected number of bytes to receive for this
- // transfer. The size of |data| will never exceed |length|, and |data| will be
- // null if |status| is neither COMPLETED, BABBLE, or SHORT_PACKET.
- //
- // |timeout| specifies the request timeout in milliseconds. A timeout of 0
- // indicates no timeout: the request will remain pending indefinitely until
- // completed or otherwise terminated.
- InterruptTransferIn(uint8 endpoint_number, uint32 length, uint32 timeout)
- => (TransferStatus status, array<uint8>? data);
-
- // Initiates an outbound interrupt transfer request on a specific endpoint.
- // The interface to which |endpoint_number| belongs must be claimed, and the
- // appropriate alternate setting must be set on that interface before
- // transfers can be initiated on the endpoint. The endpoint must be of type
- // INTERRUPT.
- //
- // |data| specifies the bytes to send the device in the body of the request.
- //
- // |timeout| specifies the request timeout in milliseconds. A timeout of 0
- // indicates no timeout: the request will remain pending indefinitely until
- // completed or otherwise terminated.
- InterruptTransferOut(uint8 endpoint_number, array<uint8> data, uint32 timeout)
+ GenericTransferOut(uint8 endpoint_number, array<uint8> data, uint32 timeout)
=> (TransferStatus status);
// Initiates an inbound isochronous transfer request on a specific endpoint.