OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 EXTENSIONS_BROWSER_API_USB_USB_API_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_USB_USB_API_H_ |
6 #define EXTENSIONS_BROWSER_API_USB_USB_API_H_ | 6 #define EXTENSIONS_BROWSER_API_USB_USB_API_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "device/usb/usb_device.h" | 13 #include "device/usb/usb_device.h" |
14 #include "device/usb/usb_device_filter.h" | 14 #include "device/usb/usb_device_filter.h" |
15 #include "device/usb/usb_device_handle.h" | 15 #include "device/usb/usb_device_handle.h" |
16 #include "extensions/browser/api/api_resource_manager.h" | 16 #include "extensions/browser/api/api_resource_manager.h" |
17 #include "extensions/browser/api/async_api_function.h" | |
18 #include "extensions/browser/api/device_permissions_prompt.h" | 17 #include "extensions/browser/api/device_permissions_prompt.h" |
| 18 #include "extensions/browser/extension_function.h" |
19 #include "extensions/common/api/usb.h" | 19 #include "extensions/common/api/usb.h" |
20 #include "net/base/io_buffer.h" | 20 #include "net/base/io_buffer.h" |
21 | 21 |
22 namespace extensions { | 22 namespace extensions { |
23 | 23 |
24 class DevicePermissionEntry; | 24 class DevicePermissionEntry; |
25 class DevicePermissions; | 25 class DevicePermissions; |
26 class DevicePermissionsManager; | 26 class DevicePermissionsManager; |
27 class UsbDeviceResource; | 27 class UsbDeviceResource; |
28 | 28 |
29 class UsbAsyncApiFunction : public AsyncApiFunction { | 29 class UsbPermissionCheckingFunction : public UIThreadExtensionFunction { |
30 public: | |
31 UsbAsyncApiFunction(); | |
32 | |
33 protected: | 30 protected: |
34 ~UsbAsyncApiFunction() override; | 31 UsbPermissionCheckingFunction(); |
35 | 32 ~UsbPermissionCheckingFunction() override; |
36 // AsyncApiFunction: | |
37 bool PrePrepare() override; | |
38 bool Respond() override; | |
39 | 33 |
40 bool HasDevicePermission(scoped_refptr<device::UsbDevice> device); | 34 bool HasDevicePermission(scoped_refptr<device::UsbDevice> device); |
41 scoped_refptr<device::UsbDeviceHandle> GetDeviceHandleOrCompleteWithError( | 35 void RecordDeviceLastUsed(); |
42 const extensions::core_api::usb::ConnectionHandle& input_device_handle); | |
43 void RemoveUsbDeviceResource(int api_resource_id); | |
44 void CompleteWithError(const std::string& error); | |
45 | 36 |
46 ApiResourceManager<UsbDeviceResource>* manager_; | 37 private: |
47 scoped_ptr<DevicePermissions> device_permissions_; | 38 DevicePermissionsManager* device_permissions_manager_; |
48 scoped_refptr<DevicePermissionEntry> permission_entry_; | 39 scoped_refptr<DevicePermissionEntry> permission_entry_; |
49 }; | 40 }; |
50 | 41 |
51 class UsbAsyncApiTransferFunction : public UsbAsyncApiFunction { | 42 class UsbConnectionFunction : public UIThreadExtensionFunction { |
52 protected: | 43 protected: |
53 UsbAsyncApiTransferFunction(); | 44 UsbConnectionFunction(); |
54 ~UsbAsyncApiTransferFunction() override; | 45 ~UsbConnectionFunction() override; |
55 | 46 |
56 bool ConvertDirectionSafely(const extensions::core_api::usb::Direction& input, | 47 scoped_refptr<device::UsbDeviceHandle> GetDeviceHandle( |
57 device::UsbEndpointDirection* output); | 48 const extensions::core_api::usb::ConnectionHandle& handle); |
58 bool ConvertRequestTypeSafely( | 49 void ReleaseDeviceHandle( |
59 const extensions::core_api::usb::RequestType& input, | 50 const extensions::core_api::usb::ConnectionHandle& handle); |
60 device::UsbDeviceHandle::TransferRequestType* output); | 51 }; |
61 bool ConvertRecipientSafely( | 52 |
62 const extensions::core_api::usb::Recipient& input, | 53 class UsbTransferFunction : public UsbConnectionFunction { |
63 device::UsbDeviceHandle::TransferRecipient* output); | 54 protected: |
| 55 UsbTransferFunction(); |
| 56 ~UsbTransferFunction() override; |
64 | 57 |
65 void OnCompleted(device::UsbTransferStatus status, | 58 void OnCompleted(device::UsbTransferStatus status, |
66 scoped_refptr<net::IOBuffer> data, | 59 scoped_refptr<net::IOBuffer> data, |
67 size_t length); | 60 size_t length); |
68 }; | 61 }; |
69 | 62 |
70 class UsbFindDevicesFunction : public UsbAsyncApiFunction { | 63 class UsbFindDevicesFunction : public UIThreadExtensionFunction { |
71 public: | 64 public: |
72 DECLARE_EXTENSION_FUNCTION("usb.findDevices", USB_FINDDEVICES) | 65 DECLARE_EXTENSION_FUNCTION("usb.findDevices", USB_FINDDEVICES) |
73 | 66 |
74 UsbFindDevicesFunction(); | 67 UsbFindDevicesFunction(); |
75 | 68 |
76 protected: | 69 private: |
77 ~UsbFindDevicesFunction() override; | 70 ~UsbFindDevicesFunction() override; |
78 | 71 |
79 // AsyncApiFunction: | 72 // ExtensionFunction: |
80 bool Prepare() override; | 73 ResponseAction Run() override; |
81 void AsyncWorkStart() override; | |
82 | 74 |
83 private: | 75 void OnGetDevicesComplete( |
84 void OpenDevices( | 76 const std::vector<scoped_refptr<device::UsbDevice>>& devices); |
85 scoped_ptr<std::vector<scoped_refptr<device::UsbDevice> > > devices); | 77 void OnRequestAccessComplete(scoped_refptr<device::UsbDevice> device, |
| 78 bool success); |
| 79 void OnDeviceOpened(scoped_refptr<device::UsbDeviceHandle> device_handle); |
| 80 void OpenComplete(); |
86 | 81 |
87 std::vector<scoped_refptr<device::UsbDeviceHandle> > device_handles_; | 82 uint16_t vendor_id_; |
88 scoped_ptr<extensions::core_api::usb::FindDevices::Params> parameters_; | 83 uint16_t product_id_; |
| 84 int interface_id_; |
| 85 scoped_ptr<base::ListValue> result_; |
| 86 base::Closure barrier_; |
| 87 |
| 88 DISALLOW_COPY_AND_ASSIGN(UsbFindDevicesFunction); |
89 }; | 89 }; |
90 | 90 |
91 class UsbGetDevicesFunction : public UsbAsyncApiFunction { | 91 class UsbGetDevicesFunction : public UsbPermissionCheckingFunction { |
92 public: | 92 public: |
93 DECLARE_EXTENSION_FUNCTION("usb.getDevices", USB_GETDEVICES) | 93 DECLARE_EXTENSION_FUNCTION("usb.getDevices", USB_GETDEVICES) |
94 | 94 |
95 UsbGetDevicesFunction(); | 95 UsbGetDevicesFunction(); |
96 | 96 |
97 // AsyncApiFunction: | 97 private: |
98 bool Prepare() override; | |
99 void AsyncWorkStart() override; | |
100 | |
101 protected: | |
102 ~UsbGetDevicesFunction() override; | 98 ~UsbGetDevicesFunction() override; |
103 | 99 |
104 private: | 100 // ExtensionFunction: |
105 scoped_ptr<extensions::core_api::usb::GetDevices::Params> parameters_; | 101 ResponseAction Run() override; |
| 102 |
| 103 void OnGetDevicesComplete( |
| 104 const std::vector<scoped_refptr<device::UsbDevice>>& devices); |
| 105 |
| 106 std::vector<device::UsbDeviceFilter> filters_; |
| 107 |
| 108 DISALLOW_COPY_AND_ASSIGN(UsbGetDevicesFunction); |
106 }; | 109 }; |
107 | 110 |
108 class UsbGetUserSelectedDevicesFunction | 111 class UsbGetUserSelectedDevicesFunction |
109 : public UIThreadExtensionFunction, | 112 : public UIThreadExtensionFunction, |
110 public DevicePermissionsPrompt::Delegate { | 113 public DevicePermissionsPrompt::Delegate { |
111 public: | 114 public: |
112 DECLARE_EXTENSION_FUNCTION("usb.getUserSelectedDevices", | 115 DECLARE_EXTENSION_FUNCTION("usb.getUserSelectedDevices", |
113 USB_GETUSERSELECTEDDEVICES) | 116 USB_GETUSERSELECTEDDEVICES) |
114 | 117 |
115 UsbGetUserSelectedDevicesFunction(); | 118 UsbGetUserSelectedDevicesFunction(); |
116 | 119 |
117 protected: | 120 private: |
118 ~UsbGetUserSelectedDevicesFunction() override; | 121 ~UsbGetUserSelectedDevicesFunction() override; |
119 | 122 |
120 // ExtensionFunction: | 123 // ExtensionFunction: |
121 ResponseAction Run() override; | 124 ResponseAction Run() override; |
122 | 125 |
123 private: | |
124 void OnUsbDevicesChosen( | 126 void OnUsbDevicesChosen( |
125 const std::vector<scoped_refptr<device::UsbDevice>>& devices) override; | 127 const std::vector<scoped_refptr<device::UsbDevice>>& devices) override; |
126 | 128 |
127 scoped_ptr<DevicePermissionsPrompt> prompt_; | 129 scoped_ptr<DevicePermissionsPrompt> prompt_; |
128 std::vector<uint32> device_ids_; | 130 |
129 std::vector<scoped_refptr<device::UsbDevice>> devices_; | 131 DISALLOW_COPY_AND_ASSIGN(UsbGetUserSelectedDevicesFunction); |
130 std::vector<base::string16> serial_numbers_; | |
131 }; | 132 }; |
132 | 133 |
133 class UsbRequestAccessFunction : public UsbAsyncApiFunction { | 134 class UsbRequestAccessFunction : public UIThreadExtensionFunction { |
134 public: | 135 public: |
135 DECLARE_EXTENSION_FUNCTION("usb.requestAccess", USB_REQUESTACCESS) | 136 DECLARE_EXTENSION_FUNCTION("usb.requestAccess", USB_REQUESTACCESS) |
136 | 137 |
137 UsbRequestAccessFunction(); | 138 UsbRequestAccessFunction(); |
138 | 139 |
139 // AsyncApiFunction: | 140 private: |
140 bool Prepare() override; | |
141 void AsyncWorkStart() override; | |
142 | |
143 protected: | |
144 ~UsbRequestAccessFunction() override; | 141 ~UsbRequestAccessFunction() override; |
145 | 142 |
146 private: | 143 // ExtensionFunction: |
147 scoped_ptr<extensions::core_api::usb::RequestAccess::Params> parameters_; | 144 ResponseAction Run() override; |
| 145 |
| 146 DISALLOW_COPY_AND_ASSIGN(UsbRequestAccessFunction); |
148 }; | 147 }; |
149 | 148 |
150 class UsbOpenDeviceFunction : public UsbAsyncApiFunction { | 149 class UsbOpenDeviceFunction : public UsbPermissionCheckingFunction { |
151 public: | 150 public: |
152 DECLARE_EXTENSION_FUNCTION("usb.openDevice", USB_OPENDEVICE) | 151 DECLARE_EXTENSION_FUNCTION("usb.openDevice", USB_OPENDEVICE) |
153 | 152 |
154 UsbOpenDeviceFunction(); | 153 UsbOpenDeviceFunction(); |
155 | 154 |
156 // AsyncApiFunction: | 155 private: |
157 bool Prepare() override; | |
158 void AsyncWorkStart() override; | |
159 bool Respond() override; | |
160 | |
161 protected: | |
162 ~UsbOpenDeviceFunction() override; | 156 ~UsbOpenDeviceFunction() override; |
163 | 157 |
164 private: | 158 // ExtensionFunction: |
165 void OnRequestAccessComplete(bool success); | 159 ResponseAction Run() override; |
166 | 160 |
167 DevicePermissionsManager* device_permissions_manager_; | 161 void OnRequestAccessComplete(scoped_refptr<device::UsbDevice> device, |
168 scoped_refptr<device::UsbDevice> device_; | 162 bool success); |
169 scoped_ptr<extensions::core_api::usb::OpenDevice::Params> parameters_; | 163 void OnDeviceOpened(scoped_refptr<device::UsbDeviceHandle> device_handle); |
| 164 |
| 165 DISALLOW_COPY_AND_ASSIGN(UsbOpenDeviceFunction); |
170 }; | 166 }; |
171 | 167 |
172 class UsbSetConfigurationFunction : public UsbAsyncApiFunction { | 168 class UsbSetConfigurationFunction : public UsbConnectionFunction { |
173 public: | 169 public: |
174 DECLARE_EXTENSION_FUNCTION("usb.setConfiguration", USB_SETCONFIGURATION) | 170 DECLARE_EXTENSION_FUNCTION("usb.setConfiguration", USB_SETCONFIGURATION) |
175 | 171 |
176 UsbSetConfigurationFunction(); | 172 UsbSetConfigurationFunction(); |
177 | 173 |
178 protected: | 174 private: |
179 ~UsbSetConfigurationFunction() override; | 175 ~UsbSetConfigurationFunction() override; |
180 | 176 |
181 // AsyncApiFunction: | 177 // ExtensionFunction: |
182 bool Prepare() override; | 178 ResponseAction Run() override; |
183 void AsyncWorkStart() override; | |
184 | 179 |
185 private: | 180 void OnComplete(bool success); |
186 scoped_ptr<extensions::core_api::usb::SetConfiguration::Params> parameters_; | 181 |
| 182 DISALLOW_COPY_AND_ASSIGN(UsbSetConfigurationFunction); |
187 }; | 183 }; |
188 | 184 |
189 class UsbGetConfigurationFunction : public UsbAsyncApiFunction { | 185 class UsbGetConfigurationFunction : public UsbConnectionFunction { |
190 public: | 186 public: |
191 DECLARE_EXTENSION_FUNCTION("usb.getConfiguration", USB_GETCONFIGURATION) | 187 DECLARE_EXTENSION_FUNCTION("usb.getConfiguration", USB_GETCONFIGURATION) |
192 | 188 |
193 UsbGetConfigurationFunction(); | 189 UsbGetConfigurationFunction(); |
194 | 190 |
195 protected: | 191 private: |
196 ~UsbGetConfigurationFunction() override; | 192 ~UsbGetConfigurationFunction() override; |
197 | 193 |
198 // AsyncApiFunction: | 194 // ExtensionFunction: |
199 bool Prepare() override; | 195 ResponseAction Run() override; |
200 void AsyncWorkStart() override; | |
201 | 196 |
202 private: | 197 DISALLOW_COPY_AND_ASSIGN(UsbGetConfigurationFunction); |
203 scoped_ptr<extensions::core_api::usb::GetConfiguration::Params> parameters_; | |
204 }; | 198 }; |
205 | 199 |
206 class UsbListInterfacesFunction : public UsbAsyncApiFunction { | 200 class UsbListInterfacesFunction : public UsbConnectionFunction { |
207 public: | 201 public: |
208 DECLARE_EXTENSION_FUNCTION("usb.listInterfaces", USB_LISTINTERFACES) | 202 DECLARE_EXTENSION_FUNCTION("usb.listInterfaces", USB_LISTINTERFACES) |
209 | 203 |
210 UsbListInterfacesFunction(); | 204 UsbListInterfacesFunction(); |
211 | 205 |
212 protected: | 206 private: |
213 ~UsbListInterfacesFunction() override; | 207 ~UsbListInterfacesFunction() override; |
214 | 208 |
215 // AsyncApiFunction: | 209 // ExtensionFunction: |
216 bool Prepare() override; | 210 ResponseAction Run() override; |
217 void AsyncWorkStart() override; | |
218 | 211 |
219 private: | 212 DISALLOW_COPY_AND_ASSIGN(UsbListInterfacesFunction); |
220 scoped_ptr<extensions::core_api::usb::ListInterfaces::Params> parameters_; | |
221 }; | 213 }; |
222 | 214 |
223 class UsbCloseDeviceFunction : public UsbAsyncApiFunction { | 215 class UsbCloseDeviceFunction : public UsbConnectionFunction { |
224 public: | 216 public: |
225 DECLARE_EXTENSION_FUNCTION("usb.closeDevice", USB_CLOSEDEVICE) | 217 DECLARE_EXTENSION_FUNCTION("usb.closeDevice", USB_CLOSEDEVICE) |
226 | 218 |
227 UsbCloseDeviceFunction(); | 219 UsbCloseDeviceFunction(); |
228 | 220 |
229 protected: | 221 private: |
230 ~UsbCloseDeviceFunction() override; | 222 ~UsbCloseDeviceFunction() override; |
231 | 223 |
232 // AsyncApiFunction: | 224 // ExtensionFunction: |
233 bool Prepare() override; | 225 ResponseAction Run() override; |
234 void AsyncWorkStart() override; | |
235 | 226 |
236 private: | 227 DISALLOW_COPY_AND_ASSIGN(UsbCloseDeviceFunction); |
237 scoped_ptr<extensions::core_api::usb::CloseDevice::Params> parameters_; | |
238 }; | 228 }; |
239 | 229 |
240 class UsbClaimInterfaceFunction : public UsbAsyncApiFunction { | 230 class UsbClaimInterfaceFunction : public UsbConnectionFunction { |
241 public: | 231 public: |
242 DECLARE_EXTENSION_FUNCTION("usb.claimInterface", USB_CLAIMINTERFACE) | 232 DECLARE_EXTENSION_FUNCTION("usb.claimInterface", USB_CLAIMINTERFACE) |
243 | 233 |
244 UsbClaimInterfaceFunction(); | 234 UsbClaimInterfaceFunction(); |
245 | 235 |
246 protected: | 236 protected: |
247 ~UsbClaimInterfaceFunction() override; | 237 ~UsbClaimInterfaceFunction() override; |
248 | 238 |
249 // AsyncApiFunction: | 239 // ExtensionFunction: |
250 bool Prepare() override; | 240 ResponseAction Run() override; |
251 void AsyncWorkStart() override; | |
252 | 241 |
253 private: | 242 void OnComplete(bool success); |
254 scoped_ptr<extensions::core_api::usb::ClaimInterface::Params> parameters_; | 243 |
| 244 DISALLOW_COPY_AND_ASSIGN(UsbClaimInterfaceFunction); |
255 }; | 245 }; |
256 | 246 |
257 class UsbReleaseInterfaceFunction : public UsbAsyncApiFunction { | 247 class UsbReleaseInterfaceFunction : public UsbConnectionFunction { |
258 public: | 248 public: |
259 DECLARE_EXTENSION_FUNCTION("usb.releaseInterface", USB_RELEASEINTERFACE) | 249 DECLARE_EXTENSION_FUNCTION("usb.releaseInterface", USB_RELEASEINTERFACE) |
260 | 250 |
261 UsbReleaseInterfaceFunction(); | 251 UsbReleaseInterfaceFunction(); |
262 | 252 |
263 protected: | 253 private: |
264 ~UsbReleaseInterfaceFunction() override; | 254 ~UsbReleaseInterfaceFunction() override; |
265 | 255 |
266 // AsyncApiFunction: | 256 // ExtensionFunction: |
267 bool Prepare() override; | 257 ResponseAction Run() override; |
268 void AsyncWorkStart() override; | |
269 | 258 |
270 private: | 259 DISALLOW_COPY_AND_ASSIGN(UsbReleaseInterfaceFunction); |
271 scoped_ptr<extensions::core_api::usb::ReleaseInterface::Params> parameters_; | |
272 }; | 260 }; |
273 | 261 |
274 class UsbSetInterfaceAlternateSettingFunction : public UsbAsyncApiFunction { | 262 class UsbSetInterfaceAlternateSettingFunction : public UsbConnectionFunction { |
275 public: | 263 public: |
276 DECLARE_EXTENSION_FUNCTION("usb.setInterfaceAlternateSetting", | 264 DECLARE_EXTENSION_FUNCTION("usb.setInterfaceAlternateSetting", |
277 USB_SETINTERFACEALTERNATESETTING) | 265 USB_SETINTERFACEALTERNATESETTING) |
278 | 266 |
279 UsbSetInterfaceAlternateSettingFunction(); | 267 UsbSetInterfaceAlternateSettingFunction(); |
280 | 268 |
281 private: | 269 private: |
282 ~UsbSetInterfaceAlternateSettingFunction() override; | 270 ~UsbSetInterfaceAlternateSettingFunction() override; |
283 | 271 |
284 // AsyncApiFunction: | 272 // ExtensionFunction: |
285 bool Prepare() override; | 273 ResponseAction Run() override; |
286 void AsyncWorkStart() override; | |
287 | 274 |
288 scoped_ptr<extensions::core_api::usb::SetInterfaceAlternateSetting::Params> | 275 void OnComplete(bool success); |
289 parameters_; | 276 |
| 277 DISALLOW_COPY_AND_ASSIGN(UsbSetInterfaceAlternateSettingFunction); |
290 }; | 278 }; |
291 | 279 |
292 class UsbControlTransferFunction : public UsbAsyncApiTransferFunction { | 280 class UsbControlTransferFunction : public UsbTransferFunction { |
293 public: | 281 public: |
294 DECLARE_EXTENSION_FUNCTION("usb.controlTransfer", USB_CONTROLTRANSFER) | 282 DECLARE_EXTENSION_FUNCTION("usb.controlTransfer", USB_CONTROLTRANSFER) |
295 | 283 |
296 UsbControlTransferFunction(); | 284 UsbControlTransferFunction(); |
297 | 285 |
298 protected: | 286 private: |
299 ~UsbControlTransferFunction() override; | 287 ~UsbControlTransferFunction() override; |
300 | 288 |
301 // AsyncApiFunction: | 289 // ExtensionFunction: |
302 bool Prepare() override; | 290 ResponseAction Run() override; |
303 void AsyncWorkStart() override; | |
304 | 291 |
305 private: | 292 DISALLOW_COPY_AND_ASSIGN(UsbControlTransferFunction); |
306 scoped_ptr<extensions::core_api::usb::ControlTransfer::Params> parameters_; | |
307 }; | 293 }; |
308 | 294 |
309 class UsbBulkTransferFunction : public UsbAsyncApiTransferFunction { | 295 class UsbBulkTransferFunction : public UsbTransferFunction { |
310 public: | 296 public: |
311 DECLARE_EXTENSION_FUNCTION("usb.bulkTransfer", USB_BULKTRANSFER) | 297 DECLARE_EXTENSION_FUNCTION("usb.bulkTransfer", USB_BULKTRANSFER) |
312 | 298 |
313 UsbBulkTransferFunction(); | 299 UsbBulkTransferFunction(); |
314 | 300 |
315 protected: | 301 private: |
316 ~UsbBulkTransferFunction() override; | 302 ~UsbBulkTransferFunction() override; |
317 | 303 |
318 // AsyncApiFunction: | 304 // ExtensionFunction: |
319 bool Prepare() override; | 305 ResponseAction Run() override; |
320 void AsyncWorkStart() override; | |
321 | 306 |
322 private: | 307 DISALLOW_COPY_AND_ASSIGN(UsbBulkTransferFunction); |
323 scoped_ptr<extensions::core_api::usb::BulkTransfer::Params> parameters_; | |
324 }; | 308 }; |
325 | 309 |
326 class UsbInterruptTransferFunction : public UsbAsyncApiTransferFunction { | 310 class UsbInterruptTransferFunction : public UsbTransferFunction { |
327 public: | 311 public: |
328 DECLARE_EXTENSION_FUNCTION("usb.interruptTransfer", USB_INTERRUPTTRANSFER) | 312 DECLARE_EXTENSION_FUNCTION("usb.interruptTransfer", USB_INTERRUPTTRANSFER) |
329 | 313 |
330 UsbInterruptTransferFunction(); | 314 UsbInterruptTransferFunction(); |
331 | 315 |
332 protected: | 316 private: |
333 ~UsbInterruptTransferFunction() override; | 317 ~UsbInterruptTransferFunction() override; |
334 | 318 |
335 // AsyncApiFunction: | 319 // ExtensionFunction: |
336 bool Prepare() override; | 320 ResponseAction Run() override; |
337 void AsyncWorkStart() override; | |
338 | 321 |
339 private: | 322 DISALLOW_COPY_AND_ASSIGN(UsbInterruptTransferFunction); |
340 scoped_ptr<extensions::core_api::usb::InterruptTransfer::Params> parameters_; | |
341 }; | 323 }; |
342 | 324 |
343 class UsbIsochronousTransferFunction : public UsbAsyncApiTransferFunction { | 325 class UsbIsochronousTransferFunction : public UsbTransferFunction { |
344 public: | 326 public: |
345 DECLARE_EXTENSION_FUNCTION("usb.isochronousTransfer", USB_ISOCHRONOUSTRANSFER) | 327 DECLARE_EXTENSION_FUNCTION("usb.isochronousTransfer", USB_ISOCHRONOUSTRANSFER) |
346 | 328 |
347 UsbIsochronousTransferFunction(); | 329 UsbIsochronousTransferFunction(); |
348 | 330 |
349 protected: | 331 private: |
350 ~UsbIsochronousTransferFunction() override; | 332 ~UsbIsochronousTransferFunction() override; |
351 | 333 |
352 // AsyncApiFunction: | 334 // ExtensionFunction: |
353 bool Prepare() override; | 335 ResponseAction Run() override; |
354 void AsyncWorkStart() override; | |
355 | 336 |
356 private: | 337 DISALLOW_COPY_AND_ASSIGN(UsbIsochronousTransferFunction); |
357 scoped_ptr<extensions::core_api::usb::IsochronousTransfer::Params> | |
358 parameters_; | |
359 }; | 338 }; |
360 | 339 |
361 class UsbResetDeviceFunction : public UsbAsyncApiFunction { | 340 class UsbResetDeviceFunction : public UsbConnectionFunction { |
362 public: | 341 public: |
363 DECLARE_EXTENSION_FUNCTION("usb.resetDevice", USB_RESETDEVICE) | 342 DECLARE_EXTENSION_FUNCTION("usb.resetDevice", USB_RESETDEVICE) |
364 | 343 |
365 UsbResetDeviceFunction(); | 344 UsbResetDeviceFunction(); |
366 | 345 |
367 protected: | 346 private: |
368 ~UsbResetDeviceFunction() override; | 347 ~UsbResetDeviceFunction() override; |
369 | 348 |
370 // AsyncApiFunction: | 349 // ExtensionFunction: |
371 bool Prepare() override; | 350 ResponseAction Run() override; |
372 void AsyncWorkStart() override; | |
373 | 351 |
374 private: | 352 void OnComplete(bool success); |
| 353 |
375 scoped_ptr<extensions::core_api::usb::ResetDevice::Params> parameters_; | 354 scoped_ptr<extensions::core_api::usb::ResetDevice::Params> parameters_; |
| 355 |
| 356 DISALLOW_COPY_AND_ASSIGN(UsbResetDeviceFunction); |
376 }; | 357 }; |
377 } // namespace extensions | 358 } // namespace extensions |
378 | 359 |
379 #endif // EXTENSIONS_BROWSER_API_USB_USB_API_H_ | 360 #endif // EXTENSIONS_BROWSER_API_USB_USB_API_H_ |
OLD | NEW |