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

Unified Diff: components/usb_service/usb_device_handle_impl.h

Issue 278633003: Extracted UsbDeviceHandle as interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
« no previous file with comments | « components/usb_service/usb_device_handle.cc ('k') | components/usb_service/usb_device_handle_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/usb_service/usb_device_handle_impl.h
diff --git a/components/usb_service/usb_device_handle.h b/components/usb_service/usb_device_handle_impl.h
similarity index 61%
copy from components/usb_service/usb_device_handle.h
copy to components/usb_service/usb_device_handle_impl.h
index 2b03a8a93a7ad66501780d6cc13dadbe407a4eae..0af9f3a50536cd881b115fc3d543d921939b10af 100644
--- a/components/usb_service/usb_device_handle.h
+++ b/components/usb_service/usb_device_handle_impl.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_USB_SERVICE_USB_DEVICE_HANDLE_H_
-#define COMPONENTS_USB_SERVICE_USB_DEVICE_HANDLE_H_
+#ifndef COMPONENTS_USB_SERVICE_USB_DEVICE_HANDLE_IMPL_H_
+#define COMPONENTS_USB_SERVICE_USB_DEVICE_HANDLE_IMPL_H_
#include <map>
#include <vector>
@@ -12,8 +12,8 @@
#include "base/memory/ref_counted.h"
#include "base/strings/string16.h"
#include "base/threading/thread_checker.h"
+#include "components/usb_service/usb_device_handle.h"
#include "components/usb_service/usb_interface.h"
-#include "components/usb_service/usb_service_export.h"
#include "net/base/io_buffer.h"
struct libusb_device_handle;
@@ -28,54 +28,24 @@ namespace usb_service {
class UsbContext;
class UsbConfigDescriptor;
-class UsbDevice;
+class UsbDeviceImpl;
typedef libusb_device_handle* PlatformUsbDeviceHandle;
typedef libusb_iso_packet_descriptor* PlatformUsbIsoPacketDescriptor;
typedef libusb_transfer* PlatformUsbTransferHandle;
-enum UsbTransferStatus {
- USB_TRANSFER_COMPLETED = 0,
- USB_TRANSFER_ERROR,
- USB_TRANSFER_TIMEOUT,
- USB_TRANSFER_CANCELLED,
- USB_TRANSFER_STALLED,
- USB_TRANSFER_DISCONNECT,
- USB_TRANSFER_OVERFLOW,
- USB_TRANSFER_LENGTH_SHORT,
-};
-
-typedef base::Callback<
- void(UsbTransferStatus, scoped_refptr<net::IOBuffer>, size_t)>
- UsbTransferCallback;
-
// UsbDeviceHandle class provides basic I/O related functionalities.
-class USB_SERVICE_EXPORT UsbDeviceHandle
- : public base::RefCountedThreadSafe<UsbDeviceHandle> {
+class UsbDeviceHandleImpl : public UsbDeviceHandle {
public:
- enum TransferRequestType { STANDARD, CLASS, VENDOR, RESERVED };
- enum TransferRecipient { DEVICE, INTERFACE, ENDPOINT, OTHER };
-
- scoped_refptr<UsbDevice> device() const;
- PlatformUsbDeviceHandle handle() const { return handle_; }
-
- // Notifies UsbDevice to drop the reference of this object; cancels all the
- // flying transfers.
- // It is possible that the object has no other reference after this call. So
- // if it is called using a raw pointer, it could be invalidated.
- // The platform device handle will be closed when UsbDeviceHandle destructs.
- virtual void Close();
-
- // Device manipulation operations. These methods are blocking and must be
- // called on FILE thread.
- virtual bool ClaimInterface(const int interface_number);
- virtual bool ReleaseInterface(const int interface_number);
- virtual bool SetInterfaceAlternateSetting(const int interface_number,
- const int alternate_setting);
- virtual bool ResetDevice();
- virtual bool GetSerial(base::string16* serial);
-
- // Async IO. Can be called on any thread.
+ virtual scoped_refptr<UsbDevice> GetDevice() const OVERRIDE;
+ virtual void Close() OVERRIDE;
+ virtual bool ClaimInterface(const int interface_number) OVERRIDE;
+ virtual bool ReleaseInterface(const int interface_number) OVERRIDE;
+ virtual bool SetInterfaceAlternateSetting(
+ const int interface_number,
+ const int alternate_setting) OVERRIDE;
+ virtual bool ResetDevice() OVERRIDE;
+ virtual bool GetSerial(base::string16* serial) OVERRIDE;
virtual void ControlTransfer(const UsbEndpointDirection direction,
const TransferRequestType request_type,
const TransferRecipient recipient,
@@ -85,46 +55,44 @@ class USB_SERVICE_EXPORT UsbDeviceHandle
net::IOBuffer* buffer,
const size_t length,
const unsigned int timeout,
- const UsbTransferCallback& callback);
+ const UsbTransferCallback& callback) OVERRIDE;
virtual void BulkTransfer(const UsbEndpointDirection direction,
const uint8 endpoint,
net::IOBuffer* buffer,
const size_t length,
const unsigned int timeout,
- const UsbTransferCallback& callback);
+ const UsbTransferCallback& callback) OVERRIDE;
virtual void InterruptTransfer(const UsbEndpointDirection direction,
const uint8 endpoint,
net::IOBuffer* buffer,
const size_t length,
const unsigned int timeout,
- const UsbTransferCallback& callback);
+ const UsbTransferCallback& callback) OVERRIDE;
+
+ virtual void 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) OVERRIDE;
- virtual void 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);
+ PlatformUsbDeviceHandle handle() const { return handle_; }
protected:
- friend class base::RefCountedThreadSafe<UsbDeviceHandle>;
friend class UsbDeviceImpl;
// This constructor is called by UsbDevice.
- UsbDeviceHandle(scoped_refptr<UsbContext> context,
- UsbDevice* device,
- PlatformUsbDeviceHandle handle,
- scoped_refptr<UsbConfigDescriptor> interfaces);
+ UsbDeviceHandleImpl(scoped_refptr<UsbContext> context,
+ UsbDeviceImpl* device,
+ PlatformUsbDeviceHandle handle,
+ scoped_refptr<UsbConfigDescriptor> interfaces);
- // This constructor variant is for use in testing only.
- UsbDeviceHandle();
- virtual ~UsbDeviceHandle();
-
- UsbDevice* device_;
+ virtual ~UsbDeviceHandleImpl();
private:
friend void HandleTransferCompletion(PlatformUsbTransferHandle handle);
@@ -158,6 +126,8 @@ class USB_SERVICE_EXPORT UsbDeviceHandle
// Informs the object to drop internal references.
void InternalClose();
+ UsbDeviceImpl* device_;
+
PlatformUsbDeviceHandle handle_;
scoped_refptr<UsbConfigDescriptor> interfaces_;
@@ -178,9 +148,9 @@ class USB_SERVICE_EXPORT UsbDeviceHandle
base::ThreadChecker thread_checker_;
- DISALLOW_COPY_AND_ASSIGN(UsbDeviceHandle);
+ DISALLOW_COPY_AND_ASSIGN(UsbDeviceHandleImpl);
};
} // namespace usb_service
-#endif // COMPONENTS_USB_SERVICE_USB_DEVICE_HANDLE_H_
+#endif // COMPONENTS_USB_SERVICE_USB_DEVICE_HANDLE_IMPL_H_
« no previous file with comments | « components/usb_service/usb_device_handle.cc ('k') | components/usb_service/usb_device_handle_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698