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

Side by Side Diff: device/usb/usb_device_handle_win.h

Issue 2702623002: Add support for reading USB descriptors to the new Windows backend. (Closed)
Patch Set: Addressed rockot@'s feedback and rebased. Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « device/usb/usb_device.h ('k') | device/usb/usb_device_handle_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 <unordered_map>
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 Request* MakeRequest(HANDLE handle);
97 std::unique_ptr<Request> UnlinkRequest(Request* request);
98 void GotNodeConnectionInformation(const TransferCallback& callback,
99 void* node_connection_info,
100 scoped_refptr<net::IOBuffer> buffer,
101 size_t buffer_length,
102 Request* request_ptr,
103 DWORD win32_result,
104 size_t bytes_transferred);
105 void GotDescriptorFromNodeConnection(
106 const TransferCallback& callback,
107 scoped_refptr<net::IOBuffer> request_buffer,
108 scoped_refptr<net::IOBuffer> original_buffer,
109 size_t original_buffer_length,
110 Request* request_ptr,
111 DWORD win32_result,
112 size_t bytes_transferred);
113
114 base::ThreadChecker thread_checker_;
115
116 scoped_refptr<UsbDeviceWin> device_;
117
118 // |hub_handle_| must outlive |requests_| because individual Request objects
119 // hold on to the handle for the purpose of calling GetOverlappedResult().
120 base::win::ScopedHandle hub_handle_;
121 std::unordered_map<Request*, std::unique_ptr<Request>> requests_;
122
123 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
124 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
125
126 base::WeakPtrFactory<UsbDeviceHandleWin> weak_factory_;
127
128 DISALLOW_COPY_AND_ASSIGN(UsbDeviceHandleWin);
129 };
130
131 } // namespace device
132
133 #endif // DEVICE_USB_USB_DEVICE_HANDLE_WIN_H_
OLDNEW
« no previous file with comments | « device/usb/usb_device.h ('k') | device/usb/usb_device_handle_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698