| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_USB_USB_DEVICE_H_ | 5 #ifndef CHROME_BROWSER_USB_USB_DEVICE_H_ |
| 6 #define CHROME_BROWSER_USB_USB_DEVICE_H_ | 6 #define CHROME_BROWSER_USB_USB_DEVICE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 USB_TRANSFER_COMPLETED = 0, | 30 USB_TRANSFER_COMPLETED = 0, |
| 31 USB_TRANSFER_ERROR, | 31 USB_TRANSFER_ERROR, |
| 32 USB_TRANSFER_TIMEOUT, | 32 USB_TRANSFER_TIMEOUT, |
| 33 USB_TRANSFER_CANCELLED, | 33 USB_TRANSFER_CANCELLED, |
| 34 USB_TRANSFER_STALLED, | 34 USB_TRANSFER_STALLED, |
| 35 USB_TRANSFER_DISCONNECT, | 35 USB_TRANSFER_DISCONNECT, |
| 36 USB_TRANSFER_OVERFLOW, | 36 USB_TRANSFER_OVERFLOW, |
| 37 USB_TRANSFER_LENGTH_SHORT, | 37 USB_TRANSFER_LENGTH_SHORT, |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 typedef base::Callback<void(UsbTransferStatus)> UsbTransferCallback; | 40 typedef base::Callback<void(UsbTransferStatus, scoped_refptr<net::IOBuffer>, |
| 41 size_t)> UsbTransferCallback; |
| 41 | 42 |
| 42 // A UsbDevice wraps the platform's underlying representation of what a USB | 43 // A UsbDevice wraps the platform's underlying representation of what a USB |
| 43 // device actually is, and provides accessors for performing many of the | 44 // device actually is, and provides accessors for performing many of the |
| 44 // standard USB operations. | 45 // standard USB operations. |
| 45 class UsbDevice : public base::RefCounted<UsbDevice> { | 46 class UsbDevice : public base::RefCounted<UsbDevice> { |
| 46 public: | 47 public: |
| 47 enum TransferDirection { INBOUND, OUTBOUND }; | 48 enum TransferDirection { INBOUND, OUTBOUND }; |
| 48 enum TransferRequestType { STANDARD, CLASS, VENDOR, RESERVED }; | 49 enum TransferRequestType { STANDARD, CLASS, VENDOR, RESERVED }; |
| 49 enum TransferRecipient { DEVICE, INTERFACE, ENDPOINT, OTHER }; | 50 enum TransferRecipient { DEVICE, INTERFACE, ENDPOINT, OTHER }; |
| 50 | 51 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 UsbDevice(); | 104 UsbDevice(); |
| 104 | 105 |
| 105 friend class base::RefCounted<UsbDevice>; | 106 friend class base::RefCounted<UsbDevice>; |
| 106 virtual ~UsbDevice(); | 107 virtual ~UsbDevice(); |
| 107 | 108 |
| 108 private: | 109 private: |
| 109 struct Transfer { | 110 struct Transfer { |
| 110 Transfer(); | 111 Transfer(); |
| 111 ~Transfer(); | 112 ~Transfer(); |
| 112 | 113 |
| 114 bool control_transfer; |
| 113 scoped_refptr<net::IOBuffer> buffer; | 115 scoped_refptr<net::IOBuffer> buffer; |
| 116 size_t length; |
| 114 UsbTransferCallback callback; | 117 UsbTransferCallback callback; |
| 115 }; | 118 }; |
| 116 | 119 |
| 117 // Checks that the device has not yet been closed. | 120 // Checks that the device has not yet been closed. |
| 118 void CheckDevice(); | 121 void CheckDevice(); |
| 119 | 122 |
| 120 // Submits a transfer and starts tracking it. Retains the buffer and copies | 123 // Submits a transfer and starts tracking it. Retains the buffer and copies |
| 121 // the completion callback until the transfer finishes, whereupon it invokes | 124 // the completion callback until the transfer finishes, whereupon it invokes |
| 122 // the callback then releases the buffer. | 125 // the callback then releases the buffer. |
| 123 void SubmitTransfer(PlatformUsbTransferHandle handle, net::IOBuffer* buffer, | 126 void SubmitTransfer(PlatformUsbTransferHandle handle, |
| 127 bool control_transfer, |
| 128 net::IOBuffer* buffer, |
| 129 const size_t length, |
| 124 const UsbTransferCallback& callback); | 130 const UsbTransferCallback& callback); |
| 125 | 131 |
| 126 // The UsbService isn't referenced here to prevent a dependency cycle between | 132 // The UsbService isn't referenced here to prevent a dependency cycle between |
| 127 // the service and the devices. Since a service owns every device, and is | 133 // the service and the devices. Since a service owns every device, and is |
| 128 // responsible for its destruction, there is no case where a UsbDevice can | 134 // responsible for its destruction, there is no case where a UsbDevice can |
| 129 // have outlived its originating UsbService. | 135 // have outlived its originating UsbService. |
| 130 UsbService* const service_; | 136 UsbService* const service_; |
| 131 PlatformUsbDeviceHandle handle_; | 137 PlatformUsbDeviceHandle handle_; |
| 132 | 138 |
| 133 // transfers_ tracks all in-flight transfers associated with this device, | 139 // transfers_ tracks all in-flight transfers associated with this device, |
| 134 // allowing the device to retain the buffer and callback associated with a | 140 // allowing the device to retain the buffer and callback associated with a |
| 135 // transfer until such time that it completes. It is protected by lock_. | 141 // transfer until such time that it completes. It is protected by lock_. |
| 136 base::Lock lock_; | 142 base::Lock lock_; |
| 137 std::map<PlatformUsbTransferHandle, Transfer> transfers_; | 143 std::map<PlatformUsbTransferHandle, Transfer> transfers_; |
| 138 | 144 |
| 139 DISALLOW_EVIL_CONSTRUCTORS(UsbDevice); | 145 DISALLOW_EVIL_CONSTRUCTORS(UsbDevice); |
| 140 }; | 146 }; |
| 141 | 147 |
| 142 #endif // CHROME_BROWSER_USB_USB_DEVICE_H_ | 148 #endif // CHROME_BROWSER_USB_USB_DEVICE_H_ |
| OLD | NEW |