diff options
author | ikarienator@chromium.org <ikarienator@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-23 19:26:48 +0000 |
---|---|---|
committer | ikarienator@chromium.org <ikarienator@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-23 19:26:48 +0000 |
commit | 57a6bfecf8ad89bc7855f08bb304b3a118e0d951 (patch) | |
tree | f340a8a2df43013d58e4546d7af2d2d8fb70e3f8 /chrome | |
parent | 093d9ba90484bf3a5a6e7a0558e32dc95bbbfa43 (diff) | |
download | chromium_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')
-rw-r--r-- | chrome/browser/devtools/adb/android_usb_device.cc | 16 | ||||
-rw-r--r-- | chrome/browser/devtools/adb/android_usb_device.h | 6 | ||||
-rw-r--r-- | chrome/browser/extensions/api/usb/usb_api.cc | 35 | ||||
-rw-r--r-- | chrome/browser/extensions/api/usb/usb_api.h | 13 | ||||
-rw-r--r-- | chrome/browser/extensions/api/usb/usb_apitest.cc | 17 | ||||
-rw-r--r-- | chrome/browser/extensions/api/usb/usb_device_resource.cc | 4 | ||||
-rw-r--r-- | chrome/browser/extensions/api/usb/usb_device_resource.h | 11 | ||||
-rw-r--r-- | chrome/browser/usb/usb_device_handle.cc (renamed from chrome/browser/usb/usb_device.cc) | 66 | ||||
-rw-r--r-- | chrome/browser/usb/usb_device_handle.h (renamed from chrome/browser/usb/usb_device.h) | 24 | ||||
-rw-r--r-- | chrome/browser/usb/usb_interface.h | 2 | ||||
-rw-r--r-- | chrome/browser/usb/usb_service.cc | 27 | ||||
-rw-r--r-- | chrome/browser/usb/usb_service.h | 15 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 4 |
13 files changed, 125 insertions, 115 deletions
diff --git a/chrome/browser/devtools/adb/android_usb_device.cc b/chrome/browser/devtools/adb/android_usb_device.cc index 0f662d5..4fd1390 100644 --- a/chrome/browser/devtools/adb/android_usb_device.cc +++ b/chrome/browser/devtools/adb/android_usb_device.cc @@ -38,7 +38,7 @@ const uint32 kVersion = 0x01000000; static const char kHostConnectMessage[] = "host::"; -typedef std::vector<scoped_refptr<UsbDevice> > UsbDevices; +typedef std::vector<scoped_refptr<UsbDeviceHandle> > UsbDevices; base::LazyInstance<AndroidUsbDevices>::Leaky g_devices = LAZY_INSTANCE_INITIALIZER; @@ -94,7 +94,7 @@ static std::string ReadSerialNumSync(libusb_device_handle* handle) { } static void InterfaceClaimed(crypto::RSAPrivateKey* rsa_key, - scoped_refptr<UsbDevice> usb_device, + scoped_refptr<UsbDeviceHandle> usb_device, int inbound_address, int outbound_address, int zero_mask, @@ -112,7 +112,7 @@ static void InterfaceClaimed(crypto::RSAPrivateKey* rsa_key, static void ClaimInterface( crypto::RSAPrivateKey* rsa_key, - scoped_refptr<UsbDevice> usb_device, + scoped_refptr<UsbDeviceHandle> usb_device, const UsbInterface* interface, AndroidUsbDevices* devices) { if (interface->GetNumAltSettings() == 0) @@ -155,7 +155,7 @@ static void ClaimInterface( static void InterfacesListed( crypto::RSAPrivateKey* rsa_key, - scoped_refptr<UsbDevice> usb_device, + scoped_refptr<UsbDeviceHandle> usb_device, scoped_refptr<UsbConfigDescriptor> config, AndroidUsbDevices* devices, bool success) { @@ -231,12 +231,12 @@ void AndroidUsbDevice::Enumerate(Profile* profile, // GC Android devices with no actual usb device. AndroidUsbDevices::iterator it = g_devices.Get().begin(); - std::set<UsbDevice*> claimed_devices; + std::set<UsbDeviceHandle*> claimed_devices; while (it != g_devices.Get().end()) { bool found_device = false; for (UsbDevices::iterator it2 = usb_devices.begin(); it2 != usb_devices.end() && !found_device; ++it2) { - UsbDevice* usb_device = it2->get(); + UsbDeviceHandle* usb_device = it2->get(); AndroidUsbDevice* device = it->get(); if (usb_device == device->usb_device_) { found_device = true; @@ -253,7 +253,7 @@ void AndroidUsbDevice::Enumerate(Profile* profile, // Add new devices. for (UsbDevices::iterator it = usb_devices.begin(); it != usb_devices.end(); ++it) { - scoped_refptr<UsbDevice> usb_device = *it; + scoped_refptr<UsbDeviceHandle> usb_device = *it; if (claimed_devices.find(usb_device.get()) != claimed_devices.end()) continue; scoped_refptr<UsbConfigDescriptor> config = new UsbConfigDescriptor(); @@ -266,7 +266,7 @@ void AndroidUsbDevice::Enumerate(Profile* profile, } AndroidUsbDevice::AndroidUsbDevice(crypto::RSAPrivateKey* rsa_key, - scoped_refptr<UsbDevice> usb_device, + scoped_refptr<UsbDeviceHandle> usb_device, const std::string& serial, int inbound_address, int outbound_address, diff --git a/chrome/browser/devtools/adb/android_usb_device.h b/chrome/browser/devtools/adb/android_usb_device.h index 6a8292d..5578ea1 100644 --- a/chrome/browser/devtools/adb/android_usb_device.h +++ b/chrome/browser/devtools/adb/android_usb_device.h @@ -9,7 +9,7 @@ #include <queue> #include <vector> #include "base/memory/ref_counted.h" -#include "chrome/browser/usb/usb_device.h" +#include "chrome/browser/usb/usb_device_handle.h" namespace base { class MessageLoop; @@ -72,7 +72,7 @@ class AndroidUsbDevice : public base::RefCountedThreadSafe<AndroidUsbDevice> { const AndroidUsbDevicesCallback& callback); AndroidUsbDevice(crypto::RSAPrivateKey* rsa_key, - scoped_refptr<UsbDevice> device, + scoped_refptr<UsbDeviceHandle> device, const std::string& serial, int inbound_address, int outbound_address, @@ -127,7 +127,7 @@ class AndroidUsbDevice : public base::RefCountedThreadSafe<AndroidUsbDevice> { scoped_ptr<crypto::RSAPrivateKey> rsa_key_; // Device info - scoped_refptr<UsbDevice> usb_device_; + scoped_refptr<UsbDeviceHandle> usb_device_; std::string serial_; int inbound_address_; int outbound_address_; 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); }; diff --git a/chrome/browser/usb/usb_device.cc b/chrome/browser/usb/usb_device_handle.cc index 13fc395..bfac067 100644 --- a/chrome/browser/usb/usb_device.cc +++ b/chrome/browser/usb/usb_device_handle.cc @@ -1,9 +1,10 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/usb/usb_device.h" +#include "chrome/browser/usb/usb_device_handle.h" +#include <algorithm> #include <vector> #include "base/stl_util.h" @@ -28,36 +29,36 @@ static uint8 ConvertTransferDirection( } static uint8 CreateRequestType(const UsbEndpointDirection direction, - const UsbDevice::TransferRequestType request_type, - const UsbDevice::TransferRecipient recipient) { + const UsbDeviceHandle::TransferRequestType request_type, + const UsbDeviceHandle::TransferRecipient recipient) { uint8 result = ConvertTransferDirection(direction); switch (request_type) { - case UsbDevice::STANDARD: + case UsbDeviceHandle::STANDARD: result |= LIBUSB_REQUEST_TYPE_STANDARD; break; - case UsbDevice::CLASS: + case UsbDeviceHandle::CLASS: result |= LIBUSB_REQUEST_TYPE_CLASS; break; - case UsbDevice::VENDOR: + case UsbDeviceHandle::VENDOR: result |= LIBUSB_REQUEST_TYPE_VENDOR; break; - case UsbDevice::RESERVED: + case UsbDeviceHandle::RESERVED: result |= LIBUSB_REQUEST_TYPE_RESERVED; break; } switch (recipient) { - case UsbDevice::DEVICE: + case UsbDeviceHandle::DEVICE: result |= LIBUSB_RECIPIENT_DEVICE; break; - case UsbDevice::INTERFACE: + case UsbDeviceHandle::INTERFACE: result |= LIBUSB_RECIPIENT_INTERFACE; break; - case UsbDevice::ENDPOINT: + case UsbDeviceHandle::ENDPOINT: result |= LIBUSB_RECIPIENT_ENDPOINT; break; - case UsbDevice::OTHER: + case UsbDeviceHandle::OTHER: result |= LIBUSB_RECIPIENT_OTHER; break; } @@ -90,33 +91,36 @@ static UsbTransferStatus ConvertTransferStatus( static void LIBUSB_CALL HandleTransferCompletion( struct libusb_transfer* transfer) { - UsbDevice* const device = reinterpret_cast<UsbDevice*>(transfer->user_data); + UsbDeviceHandle* const device = + reinterpret_cast<UsbDeviceHandle*>(transfer->user_data); device->TransferComplete(transfer); } } // namespace -UsbDevice::Transfer::Transfer() : length(0) {} +UsbDeviceHandle::Transfer::Transfer() : length(0) {} -UsbDevice::Transfer::~Transfer() {} +UsbDeviceHandle::Transfer::~Transfer() {} -UsbDevice::UsbDevice(UsbService* service, PlatformUsbDeviceHandle handle) +UsbDeviceHandle::UsbDeviceHandle( + UsbService* service, + PlatformUsbDeviceHandle handle) : service_(service), handle_(handle) { DCHECK(handle) << "Cannot create device with NULL handle."; } -UsbDevice::UsbDevice() : service_(NULL), handle_(NULL) {} +UsbDeviceHandle::UsbDeviceHandle() : service_(NULL), handle_(NULL) {} -UsbDevice::~UsbDevice() {} +UsbDeviceHandle::~UsbDeviceHandle() {} -void UsbDevice::Close(const base::Callback<void()>& callback) { +void UsbDeviceHandle::Close(const base::Callback<void()>& callback) { CheckDevice(); service_->CloseDevice(this); handle_ = NULL; callback.Run(); } -void UsbDevice::TransferComplete(PlatformUsbTransferHandle handle) { +void UsbDeviceHandle::TransferComplete(PlatformUsbTransferHandle handle) { base::AutoLock lock(lock_); // TODO(gdk): Handle device disconnect. @@ -196,7 +200,7 @@ void UsbDevice::TransferComplete(PlatformUsbTransferHandle handle) { libusb_free_transfer(handle); } -void UsbDevice::ListInterfaces(UsbConfigDescriptor* config, +void UsbDeviceHandle::ListInterfaces(UsbConfigDescriptor* config, const UsbInterfaceCallback& callback) { CheckDevice(); @@ -211,7 +215,7 @@ void UsbDevice::ListInterfaces(UsbConfigDescriptor* config, callback.Run(list_result == 0); } -void UsbDevice::ClaimInterface(const int interface_number, +void UsbDeviceHandle::ClaimInterface(const int interface_number, const UsbInterfaceCallback& callback) { CheckDevice(); @@ -219,7 +223,7 @@ void UsbDevice::ClaimInterface(const int interface_number, callback.Run(claim_result == 0); } -void UsbDevice::ReleaseInterface(const int interface_number, +void UsbDeviceHandle::ReleaseInterface(const int interface_number, const UsbInterfaceCallback& callback) { CheckDevice(); @@ -228,7 +232,7 @@ void UsbDevice::ReleaseInterface(const int interface_number, callback.Run(release_result == 0); } -void UsbDevice::SetInterfaceAlternateSetting( +void UsbDeviceHandle::SetInterfaceAlternateSetting( const int interface_number, const int alternate_setting, const UsbInterfaceCallback& callback) { @@ -240,7 +244,7 @@ void UsbDevice::SetInterfaceAlternateSetting( callback.Run(setting_result == 0); } -void UsbDevice::ControlTransfer(const UsbEndpointDirection direction, +void UsbDeviceHandle::ControlTransfer(const UsbEndpointDirection direction, const TransferRequestType request_type, const TransferRecipient recipient, const uint8 request, const uint16 value, const uint16 index, net::IOBuffer* buffer, const size_t length, const unsigned int timeout, @@ -267,7 +271,7 @@ void UsbDevice::ControlTransfer(const UsbEndpointDirection direction, callback); } -void UsbDevice::BulkTransfer(const UsbEndpointDirection direction, +void UsbDeviceHandle::BulkTransfer(const UsbEndpointDirection direction, const uint8 endpoint, net::IOBuffer* buffer, const size_t length, const unsigned int timeout, const UsbTransferCallback& callback) { CheckDevice(); @@ -280,7 +284,7 @@ void UsbDevice::BulkTransfer(const UsbEndpointDirection direction, SubmitTransfer(transfer, USB_TRANSFER_BULK, buffer, length, callback); } -void UsbDevice::InterruptTransfer(const UsbEndpointDirection direction, +void UsbDeviceHandle::InterruptTransfer(const UsbEndpointDirection direction, const uint8 endpoint, net::IOBuffer* buffer, const size_t length, const unsigned int timeout, const UsbTransferCallback& callback) { CheckDevice(); @@ -293,7 +297,7 @@ void UsbDevice::InterruptTransfer(const UsbEndpointDirection direction, SubmitTransfer(transfer, USB_TRANSFER_INTERRUPT, buffer, length, callback); } -void UsbDevice::IsochronousTransfer(const UsbEndpointDirection direction, +void UsbDeviceHandle::IsochronousTransfer(const UsbEndpointDirection direction, const uint8 endpoint, net::IOBuffer* buffer, const size_t length, const unsigned int packets, const unsigned int packet_length, const unsigned int timeout, const UsbTransferCallback& callback) { @@ -313,16 +317,16 @@ void UsbDevice::IsochronousTransfer(const UsbEndpointDirection direction, SubmitTransfer(transfer, USB_TRANSFER_ISOCHRONOUS, buffer, length, callback); } -void UsbDevice::ResetDevice(const base::Callback<void(bool)>& callback) { +void UsbDeviceHandle::ResetDevice(const base::Callback<void(bool)>& callback) { CheckDevice(); callback.Run(libusb_reset_device(handle_) == 0); } -void UsbDevice::CheckDevice() { +void UsbDeviceHandle::CheckDevice() { DCHECK(handle_) << "Device is already closed."; } -void UsbDevice::SubmitTransfer(PlatformUsbTransferHandle handle, +void UsbDeviceHandle::SubmitTransfer(PlatformUsbTransferHandle handle, UsbTransferType transfer_type, net::IOBuffer* buffer, const size_t length, diff --git a/chrome/browser/usb/usb_device.h b/chrome/browser/usb/usb_device_handle.h index 0625e74..54ed216 100644 --- a/chrome/browser/usb/usb_device.h +++ b/chrome/browser/usb/usb_device_handle.h @@ -1,9 +1,9 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_USB_USB_DEVICE_H_ -#define CHROME_BROWSER_USB_USB_DEVICE_H_ +#ifndef CHROME_BROWSER_USB_USB_DEVICE_HANDLE_H_ +#define CHROME_BROWSER_USB_USB_DEVICE_HANDLE_H_ #include <map> #include <vector> @@ -43,12 +43,12 @@ enum UsbTransferStatus { typedef base::Callback<void(UsbTransferStatus, scoped_refptr<net::IOBuffer>, size_t)> UsbTransferCallback; -typedef base::Callback<void(bool)> UsbInterfaceCallback; +typedef base::Callback<void(bool success)> UsbInterfaceCallback; // A UsbDevice wraps the platform's underlying representation of what a USB // device actually is, and provides accessors for performing many of the // standard USB operations. -class UsbDevice : public base::RefCounted<UsbDevice> { +class UsbDeviceHandle : public base::RefCounted<UsbDeviceHandle> { public: enum TransferRequestType { STANDARD, CLASS, VENDOR, RESERVED }; enum TransferRecipient { DEVICE, INTERFACE, ENDPOINT, OTHER }; @@ -56,7 +56,7 @@ class UsbDevice : public base::RefCounted<UsbDevice> { // Usually you will not want to directly create a UsbDevice, favoring to let // the UsbService take care of the logistics of getting a platform device // handle and handling events for it. - UsbDevice(UsbService* service, PlatformUsbDeviceHandle handle); + UsbDeviceHandle(UsbService* service, PlatformUsbDeviceHandle handle); PlatformUsbDeviceHandle handle() { return handle_; } @@ -112,7 +112,7 @@ class UsbDevice : public base::RefCounted<UsbDevice> { const unsigned int timeout, const UsbTransferCallback& callback); - virtual void ResetDevice(const base::Callback<void(bool)>& callback); + virtual void ResetDevice(const base::Callback<void(bool success)>& callback); // Normal code should not call this function. It is called by the platform's // callback mechanism in such a way that it cannot be made private. Invokes @@ -122,10 +122,10 @@ class UsbDevice : public base::RefCounted<UsbDevice> { protected: // This constructor variant is for use in testing only. - UsbDevice(); + UsbDeviceHandle(); - friend class base::RefCounted<UsbDevice>; - virtual ~UsbDevice(); + friend class base::RefCounted<UsbDeviceHandle>; + virtual ~UsbDeviceHandle(); private: struct Transfer { @@ -163,7 +163,7 @@ class UsbDevice : public base::RefCounted<UsbDevice> { base::Lock lock_; std::map<PlatformUsbTransferHandle, Transfer> transfers_; - DISALLOW_COPY_AND_ASSIGN(UsbDevice); + DISALLOW_COPY_AND_ASSIGN(UsbDeviceHandle); }; -#endif // CHROME_BROWSER_USB_USB_DEVICE_H_ +#endif // CHROME_BROWSER_USB_USB_DEVICE_HANDLE_H_ diff --git a/chrome/browser/usb/usb_interface.h b/chrome/browser/usb/usb_interface.h index eb57f92..ca01210 100644 --- a/chrome/browser/usb/usb_interface.h +++ b/chrome/browser/usb/usb_interface.h @@ -18,7 +18,7 @@ typedef const libusb_endpoint_descriptor* PlatformUsbEndpointDescriptor; typedef const libusb_interface* PlatformUsbInterface; typedef const libusb_interface_descriptor* PlatformUsbInterfaceDescriptor; -class UsbDevice; +class UsbDeviceHandle; enum UsbTransferType { USB_TRANSFER_CONTROL = 0, diff --git a/chrome/browser/usb/usb_service.cc b/chrome/browser/usb/usb_service.cc index e44c8aa..e5ed092 100644 --- a/chrome/browser/usb/usb_service.cc +++ b/chrome/browser/usb/usb_service.cc @@ -10,7 +10,7 @@ #include "base/bind_helpers.h" #include "base/logging.h" #include "base/stl_util.h" -#include "chrome/browser/usb/usb_device.h" +#include "chrome/browser/usb/usb_device_handle.h" #include "third_party/libusb/src/libusb/libusb.h" #if defined(OS_CHROMEOS) @@ -72,7 +72,7 @@ void UsbService::Cleanup() { void UsbService::FindDevices(const uint16 vendor_id, const uint16 product_id, int interface_id, - vector<scoped_refptr<UsbDevice> >* devices, + vector<scoped_refptr<UsbDeviceHandle> >* devices, const base::Callback<void()>& callback) { DCHECK(event_handler_) << "FindDevices called after event handler stopped."; #if defined(OS_CHROMEOS) @@ -105,7 +105,7 @@ void UsbService::FindDevices(const uint16 vendor_id, } void UsbService::EnumerateDevices( - std::vector<scoped_refptr<UsbDevice> >* devices) { + std::vector<scoped_refptr<UsbDeviceHandle> >* devices) { devices->clear(); DeviceVector enumerated_devices; @@ -114,17 +114,18 @@ void UsbService::EnumerateDevices( for (DeviceVector::iterator it = enumerated_devices.begin(); it != enumerated_devices.end(); ++it) { PlatformUsbDevice device = it->device(); - UsbDevice* const wrapper = LookupOrCreateDevice(device); + UsbDeviceHandle* const wrapper = LookupOrCreateDevice(device); if (wrapper) devices->push_back(wrapper); } } -void UsbService::FindDevicesImpl(const uint16 vendor_id, - const uint16 product_id, - vector<scoped_refptr<UsbDevice> >* devices, - const base::Callback<void()>& callback, - bool success) { +void UsbService::FindDevicesImpl( + const uint16 vendor_id, + const uint16 product_id, + vector<scoped_refptr<UsbDeviceHandle> >* devices, + const base::Callback<void()>& callback, + bool success) { base::ScopedClosureRunner run_callback(callback); devices->clear(); @@ -142,14 +143,14 @@ void UsbService::FindDevicesImpl(const uint16 vendor_id, it != enumerated_devices.end(); ++it) { PlatformUsbDevice device = it->device(); if (DeviceMatches(device, vendor_id, product_id)) { - UsbDevice* const wrapper = LookupOrCreateDevice(device); + UsbDeviceHandle* const wrapper = LookupOrCreateDevice(device); if (wrapper) devices->push_back(wrapper); } } } -void UsbService::CloseDevice(scoped_refptr<UsbDevice> device) { +void UsbService::CloseDevice(scoped_refptr<UsbDeviceHandle> device) { DCHECK(event_handler_) << "CloseDevice called after event handler stopped."; PlatformUsbDevice platform_device = libusb_get_device(device->handle()); @@ -206,7 +207,7 @@ bool UsbService::DeviceMatches(PlatformUsbDevice device, return descriptor.idVendor == vendor_id && descriptor.idProduct == product_id; } -UsbDevice* UsbService::LookupOrCreateDevice(PlatformUsbDevice device) { +UsbDeviceHandle* UsbService::LookupOrCreateDevice(PlatformUsbDevice device) { if (!ContainsKey(devices_, device)) { libusb_device_handle* handle = NULL; if (libusb_open(device, &handle)) { @@ -214,7 +215,7 @@ UsbDevice* UsbService::LookupOrCreateDevice(PlatformUsbDevice device) { return NULL; } - UsbDevice* wrapper = new UsbDevice(this, handle); + UsbDeviceHandle* wrapper = new UsbDeviceHandle(this, handle); devices_[device] = wrapper; } return devices_[device].get(); diff --git a/chrome/browser/usb/usb_service.h b/chrome/browser/usb/usb_service.h index f2cfd3c..f91e28b 100644 --- a/chrome/browser/usb/usb_service.h +++ b/chrome/browser/usb/usb_service.h @@ -11,7 +11,7 @@ #include "base/basictypes.h" #include "base/threading/platform_thread.h" -#include "chrome/browser/usb/usb_device.h" +#include "chrome/browser/usb/usb_device_handle.h" #include "components/browser_context_keyed_service/browser_context_keyed_service.h" #include "third_party/libusb/src/libusb/libusb.h" @@ -37,16 +37,16 @@ class UsbService : public BrowserContextKeyedService { void FindDevices(const uint16 vendor_id, const uint16 product_id, int interface_id, - std::vector<scoped_refptr<UsbDevice> >* devices, + std::vector<scoped_refptr<UsbDeviceHandle> >* devices, const base::Callback<void()>& callback); // Find all of the devices attached to the system, inserting them into // |devices|. Clears |devices| before use. - void EnumerateDevices(std::vector<scoped_refptr<UsbDevice> >* devices); + void EnumerateDevices(std::vector<scoped_refptr<UsbDeviceHandle> >* devices); // This function should not be called by normal code. It is invoked by a // UsbDevice's Close function and disposes of the associated platform handle. - void CloseDevice(scoped_refptr<UsbDevice> device); + void CloseDevice(scoped_refptr<UsbDeviceHandle> device); private: // RefCountedPlatformUsbDevice takes care of managing the underlying reference @@ -78,7 +78,7 @@ class UsbService : public BrowserContextKeyedService { // FindDevices. void FindDevicesImpl(const uint16 vendor_id, const uint16 product_id, - std::vector<scoped_refptr<UsbDevice> >* devices, + std::vector<scoped_refptr<UsbDeviceHandle> >* devices, const base::Callback<void()>& callback, bool success); @@ -88,7 +88,7 @@ class UsbService : public BrowserContextKeyedService { // If a UsbDevice wrapper corresponding to |device| has already been created, // returns it. Otherwise, opens the device, creates a wrapper, and associates // the wrapper with the device internally. - UsbDevice* LookupOrCreateDevice(PlatformUsbDevice device); + UsbDeviceHandle* LookupOrCreateDevice(PlatformUsbDevice device); PlatformUsbContext context_; UsbEventHandler* event_handler_; @@ -96,7 +96,8 @@ class UsbService : public BrowserContextKeyedService { // The devices_ map contains scoped_refptrs to all open devices, indicated by // their vendor and product id. This allows for reusing an open device without // creating another platform handle for it. - typedef std::map<PlatformUsbDevice, scoped_refptr<UsbDevice> > DeviceMap; + typedef std::map<PlatformUsbDevice, scoped_refptr<UsbDeviceHandle> > + DeviceMap; DeviceMap devices_; DISALLOW_COPY_AND_ASSIGN(UsbService); diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 677749e..86676ab 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2272,8 +2272,8 @@ 'browser/upgrade_detector_impl.h', 'browser/upload_list.cc', 'browser/upload_list.h', - 'browser/usb/usb_device.cc', - 'browser/usb/usb_device.h', + 'browser/usb/usb_device_handle.cc', + 'browser/usb/usb_device_handle.h', 'browser/usb/usb_interface.cc', 'browser/usb/usb_interface.h', 'browser/usb/usb_service.cc', |