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

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

Issue 1916053006: Support USB transfers from arbitrary threads in the new Linux backend. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | device/usb/usb_device_handle_usbfs.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 DEVICE_USB_USB_DEVICE_HANDLE_USBFS_H_ 5 #ifndef DEVICE_USB_USB_DEVICE_HANDLE_USBFS_H_
6 #define DEVICE_USB_USB_DEVICE_HANDLE_USBFS_H_ 6 #define DEVICE_USB_USB_DEVICE_HANDLE_USBFS_H_
7 7
8 #include <list> 8 #include <list>
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/files/scoped_file.h" 13 #include "base/files/scoped_file.h"
14 #include "device/usb/usb_device_handle.h" 14 #include "device/usb/usb_device_handle.h"
15 15
16 struct usbdevfs_urb; 16 struct usbdevfs_urb;
17 17
18 namespace base { 18 namespace base {
19 class SequencedTaskRunner; 19 class SequencedTaskRunner;
20 class SingleThreadTaskRunner;
20 } 21 }
21 22
22 namespace device { 23 namespace device {
23 24
24 // Implementation of a USB device handle on top of the Linux USBFS ioctl 25 // Implementation of a USB device handle on top of the Linux USBFS ioctl
25 // interface available on Linux, Chrome OS and Android. 26 // interface available on Linux, Chrome OS and Android.
26 class UsbDeviceHandleUsbfs : public UsbDeviceHandle { 27 class UsbDeviceHandleUsbfs : public UsbDeviceHandle {
27 public: 28 public:
28 // Constructs a new device handle from an existing |device| and open file 29 // Constructs a new device handle from an existing |device| and open file
29 // descriptor to that device. |blocking_task_runner| must have a 30 // descriptor to that device. |blocking_task_runner| must have a
(...skipping 25 matching lines...) Expand all
55 uint16_t index, 56 uint16_t index,
56 scoped_refptr<net::IOBuffer> buffer, 57 scoped_refptr<net::IOBuffer> buffer,
57 size_t length, 58 size_t length,
58 unsigned int timeout, 59 unsigned int timeout,
59 const TransferCallback& callback) override; 60 const TransferCallback& callback) override;
60 void IsochronousTransferIn( 61 void IsochronousTransferIn(
61 uint8_t endpoint_number, 62 uint8_t endpoint_number,
62 const std::vector<uint32_t>& packet_lengths, 63 const std::vector<uint32_t>& packet_lengths,
63 unsigned int timeout, 64 unsigned int timeout,
64 const IsochronousTransferCallback& callback) override; 65 const IsochronousTransferCallback& callback) override;
65
66 void IsochronousTransferOut( 66 void IsochronousTransferOut(
67 uint8_t endpoint_number, 67 uint8_t endpoint_number,
68 scoped_refptr<net::IOBuffer> buffer, 68 scoped_refptr<net::IOBuffer> buffer,
69 const std::vector<uint32_t>& packet_lengths, 69 const std::vector<uint32_t>& packet_lengths,
70 unsigned int timeout, 70 unsigned int timeout,
71 const IsochronousTransferCallback& callback) override; 71 const IsochronousTransferCallback& callback) override;
72 // To support DevTools this function may be called from any thread and on
73 // completion |callback| will be run on that thread.
72 void GenericTransfer(UsbEndpointDirection direction, 74 void GenericTransfer(UsbEndpointDirection direction,
73 uint8_t endpoint_number, 75 uint8_t endpoint_number,
74 scoped_refptr<net::IOBuffer> buffer, 76 scoped_refptr<net::IOBuffer> buffer,
75 size_t length, 77 size_t length,
76 unsigned int timeout, 78 unsigned int timeout,
77 const TransferCallback& callback) override; 79 const TransferCallback& callback) override;
78 const UsbInterfaceDescriptor* FindInterfaceByEndpoint( 80 const UsbInterfaceDescriptor* FindInterfaceByEndpoint(
79 uint8_t endpoint_address) override; 81 uint8_t endpoint_address) override;
80 82
81 private: 83 private:
(...skipping 23 matching lines...) Expand all
105 const ResultCallback& callback); 107 const ResultCallback& callback);
106 void ResetDeviceBlocking(const ResultCallback& callback); 108 void ResetDeviceBlocking(const ResultCallback& callback);
107 void ClearHaltBlocking(uint8_t endpoint_address, 109 void ClearHaltBlocking(uint8_t endpoint_address,
108 const ResultCallback& callback); 110 const ResultCallback& callback);
109 void IsochronousTransferInternal(uint8_t endpoint_address, 111 void IsochronousTransferInternal(uint8_t endpoint_address,
110 scoped_refptr<net::IOBuffer> buffer, 112 scoped_refptr<net::IOBuffer> buffer,
111 size_t total_length, 113 size_t total_length,
112 const std::vector<uint32_t>& packet_lengths, 114 const std::vector<uint32_t>& packet_lengths,
113 unsigned int timeout, 115 unsigned int timeout,
114 const IsochronousTransferCallback& callback); 116 const IsochronousTransferCallback& callback);
117 void GenericTransferInternal(
118 UsbEndpointDirection direction,
119 uint8_t endpoint_number,
120 scoped_refptr<net::IOBuffer> buffer,
121 size_t length,
122 unsigned int timeout,
123 const TransferCallback& callback,
124 scoped_refptr<base::SingleThreadTaskRunner> callback_runner);
115 void ReapedUrbs(const std::vector<usbdevfs_urb*>& urbs); 125 void ReapedUrbs(const std::vector<usbdevfs_urb*>& urbs);
116 void TransferComplete(std::unique_ptr<Transfer> transfer); 126 void TransferComplete(std::unique_ptr<Transfer> transfer);
117 void RefreshEndpointInfo(); 127 void RefreshEndpointInfo();
118 void ReportIsochronousError( 128 void ReportIsochronousError(
119 const std::vector<uint32_t>& packet_lengths, 129 const std::vector<uint32_t>& packet_lengths,
120 const UsbDeviceHandle::IsochronousTransferCallback& callback, 130 const UsbDeviceHandle::IsochronousTransferCallback& callback,
121 UsbTransferStatus status); 131 UsbTransferStatus status);
122 void SetUpTimeoutCallback(Transfer* transfer, unsigned int timeout); 132 void SetUpTimeoutCallback(Transfer* transfer, unsigned int timeout);
123 133
124 static void CancelTransfer(Transfer* transfer, UsbTransferStatus status); 134 static void CancelTransfer(Transfer* transfer, UsbTransferStatus status);
125 135
126 scoped_refptr<UsbDevice> device_; 136 scoped_refptr<UsbDevice> device_;
127 base::ScopedFD fd_; 137 base::ScopedFD fd_;
128 scoped_refptr<base::SequencedTaskRunner> task_runner_; 138 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
129 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 139 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
130 base::ThreadChecker thread_checker_; 140 base::ThreadChecker thread_checker_;
131 141
132 // Maps claimed interfaces by interface number to their current alternate 142 // Maps claimed interfaces by interface number to their current alternate
133 // setting. 143 // setting.
134 std::map<uint8_t, InterfaceInfo> interfaces_; 144 std::map<uint8_t, InterfaceInfo> interfaces_;
135 145
136 // Maps endpoints (by endpoint address) to the interface they are a part of. 146 // Maps endpoints (by endpoint address) to the interface they are a part of.
137 // Only endpoints of currently claimed and selected interface alternates are 147 // Only endpoints of currently claimed and selected interface alternates are
138 // included in the map. 148 // included in the map.
139 std::map<uint8_t, EndpointInfo> endpoints_; 149 std::map<uint8_t, EndpointInfo> endpoints_;
140 150
141 // Helper object owned by the blocking task thread. It will be freed if that 151 // Helper object owned by the blocking task thread. It will be freed if that
142 // thread's message loop is destroyed but can also be freed by this class on 152 // thread's message loop is destroyed but can also be freed by this class on
143 // destruction. 153 // destruction.
144 FileThreadHelper* helper_; 154 FileThreadHelper* helper_;
145 155
146 std::list<std::unique_ptr<Transfer>> transfers_; 156 std::list<std::unique_ptr<Transfer>> transfers_;
147 }; 157 };
148 158
149 } // namespace device 159 } // namespace device
150 160
151 #endif // DEVICE_USB_USB_DEVICE_HANDLE_USBFS_H_ 161 #endif // DEVICE_USB_USB_DEVICE_HANDLE_USBFS_H_
OLDNEW
« no previous file with comments | « no previous file | device/usb/usb_device_handle_usbfs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698