summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/api/usb
diff options
context:
space:
mode:
authorikarienator@chromium.org <ikarienator@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-23 19:26:48 +0000
committerikarienator@chromium.org <ikarienator@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-23 19:26:48 +0000
commit57a6bfecf8ad89bc7855f08bb304b3a118e0d951 (patch)
treef340a8a2df43013d58e4546d7af2d2d8fb70e3f8 /chrome/browser/extensions/api/usb
parent093d9ba90484bf3a5a6e7a0558e32dc95bbbfa43 (diff)
downloadchromium_src-57a6bfecf8ad89bc7855f08bb304b3a118e0d951.zip
chromium_src-57a6bfecf8ad89bc7855f08bb304b3a118e0d951.tar.gz
chromium_src-57a6bfecf8ad89bc7855f08bb304b3a118e0d951.tar.bz2
As a part of the refactor, rename UsbDevice to UsbDeviceHandle.
BUG=223817 TBR=kalman (for plain rename under extensions/api/usb) Review URL: https://chromiumcodereview.appspot.com/19712005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213188 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/api/usb')
-rw-r--r--chrome/browser/extensions/api/usb/usb_api.cc35
-rw-r--r--chrome/browser/extensions/api/usb/usb_api.h13
-rw-r--r--chrome/browser/extensions/api/usb/usb_apitest.cc17
-rw-r--r--chrome/browser/extensions/api/usb/usb_device_resource.cc4
-rw-r--r--chrome/browser/extensions/api/usb/usb_device_resource.h11
5 files changed, 42 insertions, 38 deletions
diff --git a/chrome/browser/extensions/api/usb/usb_api.cc b/chrome/browser/extensions/api/usb/usb_api.cc
index c4bb050..7dc90e6 100644
--- a/chrome/browser/extensions/api/usb/usb_api.cc
+++ b/chrome/browser/extensions/api/usb/usb_api.cc
@@ -11,6 +11,7 @@
#include "chrome/browser/extensions/api/usb/usb_device_resource.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/usb/usb_device_handle.h"
#include "chrome/browser/usb/usb_service.h"
#include "chrome/browser/usb/usb_service_factory.h"
#include "chrome/common/extensions/api/usb.h"
@@ -89,7 +90,7 @@ static const size_t kMaxTransferLength = 100 * 1024 * 1024;
static const int kMaxPackets = 4 * 1024 * 1024;
static const int kMaxPacketLength = 64 * 1024;
-static UsbDevice* device_for_test_ = NULL;
+static UsbDeviceHandle* device_for_test_ = NULL;
static bool ConvertDirectionToApi(const UsbEndpointDirection& input,
Direction* output) {
@@ -184,19 +185,19 @@ static bool ConvertDirection(const Direction& input,
}
static bool ConvertRequestType(const RequestType& input,
- UsbDevice::TransferRequestType* output) {
+ UsbDeviceHandle::TransferRequestType* output) {
switch (input) {
case usb::REQUEST_TYPE_STANDARD:
- *output = UsbDevice::STANDARD;
+ *output = UsbDeviceHandle::STANDARD;
return true;
case usb::REQUEST_TYPE_CLASS:
- *output = UsbDevice::CLASS;
+ *output = UsbDeviceHandle::CLASS;
return true;
case usb::REQUEST_TYPE_VENDOR:
- *output = UsbDevice::VENDOR;
+ *output = UsbDeviceHandle::VENDOR;
return true;
case usb::REQUEST_TYPE_RESERVED:
- *output = UsbDevice::RESERVED;
+ *output = UsbDeviceHandle::RESERVED;
return true;
default:
NOTREACHED();
@@ -205,19 +206,19 @@ static bool ConvertRequestType(const RequestType& input,
}
static bool ConvertRecipient(const Recipient& input,
- UsbDevice::TransferRecipient* output) {
+ UsbDeviceHandle::TransferRecipient* output) {
switch (input) {
case usb::RECIPIENT_DEVICE:
- *output = UsbDevice::DEVICE;
+ *output = UsbDeviceHandle::DEVICE;
return true;
case usb::RECIPIENT_INTERFACE:
- *output = UsbDevice::INTERFACE;
+ *output = UsbDeviceHandle::INTERFACE;
return true;
case usb::RECIPIENT_ENDPOINT:
- *output = UsbDevice::ENDPOINT;
+ *output = UsbDeviceHandle::ENDPOINT;
return true;
case usb::RECIPIENT_OTHER:
- *output = UsbDevice::OTHER;
+ *output = UsbDeviceHandle::OTHER;
return true;
default:
NOTREACHED();
@@ -383,7 +384,7 @@ bool UsbAsyncApiTransferFunction::ConvertDirectionSafely(
}
bool UsbAsyncApiTransferFunction::ConvertRequestTypeSafely(
- const RequestType& input, UsbDevice::TransferRequestType* output) {
+ const RequestType& input, UsbDeviceHandle::TransferRequestType* output) {
const bool converted = ConvertRequestType(input, output);
if (!converted)
SetError(kErrorConvertRequestType);
@@ -391,7 +392,7 @@ bool UsbAsyncApiTransferFunction::ConvertRequestTypeSafely(
}
bool UsbAsyncApiTransferFunction::ConvertRecipientSafely(
- const Recipient& input, UsbDevice::TransferRecipient* output) {
+ const Recipient& input, UsbDeviceHandle::TransferRecipient* output) {
const bool converted = ConvertRecipient(input, output);
if (!converted)
SetError(kErrorConvertRecipient);
@@ -402,7 +403,7 @@ UsbFindDevicesFunction::UsbFindDevicesFunction() {}
UsbFindDevicesFunction::~UsbFindDevicesFunction() {}
-void UsbFindDevicesFunction::SetDeviceForTest(UsbDevice* device) {
+void UsbFindDevicesFunction::SetDeviceForTest(UsbDeviceHandle* device) {
device_for_test_ = device;
}
@@ -454,7 +455,7 @@ void UsbFindDevicesFunction::AsyncWorkStart() {
void UsbFindDevicesFunction::OnCompleted() {
for (size_t i = 0; i < devices_.size(); ++i) {
- UsbDevice* const device = devices_[i].get();
+ UsbDeviceHandle* const device = devices_[i].get();
UsbDeviceResource* const resource =
new UsbDeviceResource(extension_->id(), device);
@@ -729,8 +730,8 @@ void UsbControlTransferFunction::AsyncWorkStart() {
const ControlTransferInfo& transfer = parameters_->transfer_info;
UsbEndpointDirection direction;
- UsbDevice::TransferRequestType request_type;
- UsbDevice::TransferRecipient recipient;
+ UsbDeviceHandle::TransferRequestType request_type;
+ UsbDeviceHandle::TransferRecipient recipient;
size_t size = 0;
if (!ConvertDirectionSafely(transfer.direction, &direction) ||
diff --git a/chrome/browser/extensions/api/usb/usb_api.h b/chrome/browser/extensions/api/usb/usb_api.h
index f223016..80941fc 100644
--- a/chrome/browser/extensions/api/usb/usb_api.h
+++ b/chrome/browser/extensions/api/usb/usb_api.h
@@ -6,15 +6,16 @@
#define CHROME_BROWSER_EXTENSIONS_API_USB_USB_API_H_
#include <string>
+#include <vector>
#include "base/memory/ref_counted.h"
#include "chrome/browser/extensions/api/api_function.h"
#include "chrome/browser/extensions/api/api_resource_manager.h"
-#include "chrome/browser/usb/usb_device.h"
+#include "chrome/browser/usb/usb_device_handle.h"
#include "chrome/common/extensions/api/usb.h"
#include "net/base/io_buffer.h"
-class UsbDevice;
+class UsbDeviceHandle;
namespace extensions {
@@ -46,9 +47,9 @@ class UsbAsyncApiTransferFunction : public UsbAsyncApiFunction {
bool ConvertDirectionSafely(const extensions::api::usb::Direction& input,
UsbEndpointDirection* output);
bool ConvertRequestTypeSafely(const extensions::api::usb::RequestType& input,
- UsbDevice::TransferRequestType* output);
+ UsbDeviceHandle::TransferRequestType* output);
bool ConvertRecipientSafely(const extensions::api::usb::Recipient& input,
- UsbDevice::TransferRecipient* output);
+ UsbDeviceHandle::TransferRecipient* output);
void OnCompleted(UsbTransferStatus status,
scoped_refptr<net::IOBuffer> data,
@@ -61,7 +62,7 @@ class UsbFindDevicesFunction : public UsbAsyncApiFunction {
UsbFindDevicesFunction();
- static void SetDeviceForTest(UsbDevice* device);
+ static void SetDeviceForTest(UsbDeviceHandle* device);
protected:
virtual ~UsbFindDevicesFunction();
@@ -73,7 +74,7 @@ class UsbFindDevicesFunction : public UsbAsyncApiFunction {
void OnCompleted();
scoped_ptr<base::ListValue> result_;
- std::vector<scoped_refptr<UsbDevice> > devices_;
+ std::vector<scoped_refptr<UsbDeviceHandle> > devices_;
scoped_ptr<extensions::api::usb::FindDevices::Params> parameters_;
};
diff --git a/chrome/browser/extensions/api/usb/usb_apitest.cc b/chrome/browser/extensions/api/usb/usb_apitest.cc
index 20f37d9..19b3100 100644
--- a/chrome/browser/extensions/api/usb/usb_apitest.cc
+++ b/chrome/browser/extensions/api/usb/usb_apitest.cc
@@ -39,9 +39,9 @@ ACTION_TEMPLATE(InvokeUsbResultCallback,
#pragma warning(push)
#pragma warning(disable:4373)
#endif
-class MockUsbDevice : public UsbDevice {
+class MockUsbDeviceHandle : public UsbDeviceHandle {
public:
- MockUsbDevice() : UsbDevice() {}
+ MockUsbDeviceHandle() : UsbDeviceHandle() {}
MOCK_METHOD1(Close, void(const base::Callback<void()>& callback));
@@ -64,13 +64,14 @@ class MockUsbDevice : public UsbDevice {
const unsigned int packets, const unsigned int packet_length,
const unsigned int timeout, const UsbTransferCallback& callback));
- MOCK_METHOD1(ResetDevice, void(const base::Callback<void(bool)>& callback));
+ MOCK_METHOD1(ResetDevice, void(
+ const base::Callback<void(bool success)>& callback));
MOCK_METHOD2(ListInterfaces, void(UsbConfigDescriptor* config,
const UsbInterfaceCallback& callback));
protected:
- virtual ~MockUsbDevice() {}
+ virtual ~MockUsbDeviceHandle() {}
};
#if defined(OS_WIN)
#pragma warning(pop)
@@ -84,12 +85,12 @@ class UsbApiTest : public ExtensionApiTest {
}
virtual void SetUpOnMainThread() OVERRIDE {
- mock_device_ = new MockUsbDevice();
+ mock_device_ = new MockUsbDeviceHandle();
extensions::UsbFindDevicesFunction::SetDeviceForTest(mock_device_.get());
}
protected:
- scoped_refptr<MockUsbDevice> mock_device_;
+ scoped_refptr<MockUsbDeviceHandle> mock_device_;
};
} // namespace
@@ -116,8 +117,8 @@ IN_PROC_BROWSER_TEST_F(UsbApiTest, ListInterfaces) {
IN_PROC_BROWSER_TEST_F(UsbApiTest, TransferEvent) {
EXPECT_CALL(*mock_device_.get(),
ControlTransfer(USB_DIRECTION_OUTBOUND,
- UsbDevice::STANDARD,
- UsbDevice::DEVICE,
+ UsbDeviceHandle::STANDARD,
+ UsbDeviceHandle::DEVICE,
1,
2,
3,
diff --git a/chrome/browser/extensions/api/usb/usb_device_resource.cc b/chrome/browser/extensions/api/usb/usb_device_resource.cc
index 4d8aa95..685d24d 100644
--- a/chrome/browser/extensions/api/usb/usb_device_resource.cc
+++ b/chrome/browser/extensions/api/usb/usb_device_resource.cc
@@ -11,7 +11,7 @@
#include "base/bind_helpers.h"
#include "base/synchronization/lock.h"
#include "chrome/browser/extensions/api/api_resource.h"
-#include "chrome/browser/usb/usb_device.h"
+#include "chrome/browser/usb/usb_device_handle.h"
#include "chrome/common/extensions/api/usb.h"
namespace extensions {
@@ -28,7 +28,7 @@ ApiResourceManager<UsbDeviceResource>::GetFactoryInstance() {
}
UsbDeviceResource::UsbDeviceResource(const std::string& owner_extension_id,
- scoped_refptr<UsbDevice> device)
+ scoped_refptr<UsbDeviceHandle> device)
: ApiResource(owner_extension_id), device_(device) {}
UsbDeviceResource::~UsbDeviceResource() {}
diff --git a/chrome/browser/extensions/api/usb/usb_device_resource.h b/chrome/browser/extensions/api/usb/usb_device_resource.h
index 15fcca0..6592548 100644
--- a/chrome/browser/extensions/api/usb/usb_device_resource.h
+++ b/chrome/browser/extensions/api/usb/usb_device_resource.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_EXTENSIONS_API_USB_USB_DEVICE_RESOURCE_H_
#include <set>
+#include <string>
#include "base/basictypes.h"
#include "base/memory/linked_ptr.h"
@@ -13,10 +14,10 @@
#include "base/synchronization/lock.h"
#include "chrome/browser/extensions/api/api_resource.h"
#include "chrome/browser/extensions/api/api_resource_manager.h"
-#include "chrome/browser/usb/usb_device.h"
+#include "chrome/browser/usb/usb_device_handle.h"
#include "chrome/common/extensions/api/usb.h"
-class UsbDevice;
+class UsbDeviceHandle;
namespace net {
class IOBuffer;
@@ -28,10 +29,10 @@ namespace extensions {
class UsbDeviceResource : public ApiResource {
public:
UsbDeviceResource(const std::string& owner_extension_id,
- scoped_refptr<UsbDevice> device);
+ scoped_refptr<UsbDeviceHandle> device);
virtual ~UsbDeviceResource();
- scoped_refptr<UsbDevice> device() {
+ scoped_refptr<UsbDeviceHandle> device() {
return device_;
}
@@ -41,7 +42,7 @@ class UsbDeviceResource : public ApiResource {
return "UsbDeviceResourceManager";
}
- scoped_refptr<UsbDevice> device_;
+ scoped_refptr<UsbDeviceHandle> device_;
DISALLOW_COPY_AND_ASSIGN(UsbDeviceResource);
};