Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef DEVICE_USB_USB_DEVICE_HANDLE_WIN_H_ | |
| 6 #define DEVICE_USB_USB_DEVICE_HANDLE_WIN_H_ | |
| 7 | |
| 8 #include <list> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 #include "base/threading/thread_checker.h" | |
| 16 #include "base/win/scoped_handle.h" | |
| 17 #include "device/usb/usb_device_handle.h" | |
| 18 | |
| 19 namespace base { | |
| 20 class SequencedTaskRunner; | |
| 21 class SingleThreadTaskRunner; | |
| 22 } | |
| 23 | |
| 24 namespace net { | |
| 25 class IOBuffer; | |
| 26 } | |
| 27 | |
| 28 namespace device { | |
| 29 | |
| 30 class UsbDeviceWin; | |
| 31 | |
| 32 // UsbDeviceHandle class provides basic I/O related functionalities. | |
| 33 class UsbDeviceHandleWin : public UsbDeviceHandle { | |
| 34 public: | |
| 35 scoped_refptr<UsbDevice> GetDevice() const override; | |
| 36 void Close() override; | |
| 37 void SetConfiguration(int configuration_value, | |
| 38 const ResultCallback& callback) override; | |
| 39 void ClaimInterface(int interface_number, | |
| 40 const ResultCallback& callback) override; | |
| 41 void ReleaseInterface(int interface_number, | |
| 42 const ResultCallback& callback) override; | |
| 43 void SetInterfaceAlternateSetting(int interface_number, | |
| 44 int alternate_setting, | |
| 45 const ResultCallback& callback) override; | |
| 46 void ResetDevice(const ResultCallback& callback) override; | |
| 47 void ClearHalt(uint8_t endpoint, const ResultCallback& callback) override; | |
| 48 | |
| 49 void ControlTransfer(UsbEndpointDirection direction, | |
| 50 TransferRequestType request_type, | |
| 51 TransferRecipient recipient, | |
| 52 uint8_t request, | |
| 53 uint16_t value, | |
| 54 uint16_t index, | |
| 55 scoped_refptr<net::IOBuffer> buffer, | |
| 56 size_t length, | |
| 57 unsigned int timeout, | |
| 58 const TransferCallback& callback) override; | |
| 59 | |
| 60 void IsochronousTransferIn( | |
| 61 uint8_t endpoint, | |
| 62 const std::vector<uint32_t>& packet_lengths, | |
| 63 unsigned int timeout, | |
| 64 const IsochronousTransferCallback& callback) override; | |
| 65 | |
| 66 void IsochronousTransferOut( | |
| 67 uint8_t endpoint, | |
| 68 scoped_refptr<net::IOBuffer> buffer, | |
| 69 const std::vector<uint32_t>& packet_lengths, | |
| 70 unsigned int timeout, | |
| 71 const IsochronousTransferCallback& callback) override; | |
| 72 | |
| 73 void GenericTransfer(UsbEndpointDirection direction, | |
| 74 uint8_t endpoint_number, | |
| 75 scoped_refptr<net::IOBuffer> buffer, | |
| 76 size_t length, | |
| 77 unsigned int timeout, | |
| 78 const TransferCallback& callback) override; | |
| 79 const UsbInterfaceDescriptor* FindInterfaceByEndpoint( | |
| 80 uint8_t endpoint_address) override; | |
| 81 | |
| 82 protected: | |
| 83 friend class UsbDeviceWin; | |
| 84 | |
| 85 // Constructor used to build a connection to the device's parent hub. | |
| 86 UsbDeviceHandleWin( | |
| 87 scoped_refptr<UsbDeviceWin> device, | |
| 88 base::win::ScopedHandle handle, | |
| 89 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner); | |
| 90 | |
| 91 ~UsbDeviceHandleWin() override; | |
| 92 | |
| 93 private: | |
| 94 class Request; | |
| 95 | |
| 96 std::unique_ptr<Request> UnlinkRequest(Request* request); | |
| 97 void GotNodeConnectionInformation(const TransferCallback& callback, | |
| 98 void* node_connection_info, | |
| 99 scoped_refptr<net::IOBuffer> buffer, | |
| 100 size_t buffer_length, | |
| 101 Request* request_ptr, | |
| 102 DWORD win32_result, | |
| 103 size_t bytes_transferred); | |
| 104 void GotDescriptorFromNodeConnection( | |
| 105 const TransferCallback& callback, | |
| 106 scoped_refptr<net::IOBuffer> request_buffer, | |
| 107 scoped_refptr<net::IOBuffer> original_buffer, | |
| 108 size_t original_buffer_length, | |
| 109 Request* request_ptr, | |
| 110 DWORD win32_result, | |
| 111 size_t bytes_transferred); | |
| 112 | |
| 113 base::ThreadChecker thread_checker_; | |
| 114 | |
| 115 scoped_refptr<UsbDeviceWin> device_; | |
| 116 | |
| 117 base::win::ScopedHandle hub_handle_; | |
| 118 std::list<std::unique_ptr<Request>> requests_; | |
|
Ken Rockot(use gerrit already)
2017/02/17 20:27:07
nit: Maybe worth documenting that hub_handle_ must
Reilly Grant (use Gerrit)
2017/02/18 00:45:49
Done.
| |
| 119 | |
| 120 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 121 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | |
| 122 | |
| 123 base::WeakPtrFactory<UsbDeviceHandleWin> weak_factory_; | |
| 124 | |
| 125 DISALLOW_COPY_AND_ASSIGN(UsbDeviceHandleWin); | |
| 126 }; | |
| 127 | |
| 128 } // namespace device | |
| 129 | |
| 130 #endif // DEVICE_USB_USB_DEVICE_HANDLE_WIN_H_ | |
| OLD | NEW |