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 #if defined(OS_CHROMEOS) |
| 78 void OnRequestAccessComplete(scoped_refptr<device::UsbDevice> device, |
| 79 bool success); |
| 80 #endif // OS_CHROMEOS |
| 81 void OnDeviceOpened(scoped_refptr<device::UsbDeviceHandle> device_handle); |
| 82 void OpenComplete(); |
86 | 83 |
87 std::vector<scoped_refptr<device::UsbDeviceHandle> > device_handles_; | 84 uint16_t vendor_id_; |
88 scoped_ptr<extensions::core_api::usb::FindDevices::Params> parameters_; | 85 uint16_t product_id_; |
| 86 int interface_id_; |
| 87 scoped_ptr<base::ListValue> result_; |
| 88 base::Closure barrier_; |
| 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(UsbFindDevicesFunction); |
89 }; | 91 }; |
90 | 92 |
91 class UsbGetDevicesFunction : public UsbAsyncApiFunction { | 93 class UsbGetDevicesFunction : public UsbPermissionCheckingFunction { |
92 public: | 94 public: |
93 DECLARE_EXTENSION_FUNCTION("usb.getDevices", USB_GETDEVICES) | 95 DECLARE_EXTENSION_FUNCTION("usb.getDevices", USB_GETDEVICES) |
94 | 96 |
95 UsbGetDevicesFunction(); | 97 UsbGetDevicesFunction(); |
96 | 98 |
97 // AsyncApiFunction: | 99 private: |
98 bool Prepare() override; | |
99 void AsyncWorkStart() override; | |
100 | |
101 protected: | |
102 ~UsbGetDevicesFunction() override; | 100 ~UsbGetDevicesFunction() override; |
103 | 101 |
104 private: | 102 // ExtensionFunction: |
105 scoped_ptr<extensions::core_api::usb::GetDevices::Params> parameters_; | 103 ResponseAction Run() override; |
| 104 |
| 105 void OnGetDevicesComplete( |
| 106 const std::vector<scoped_refptr<device::UsbDevice>>& devices); |
| 107 |
| 108 std::vector<device::UsbDeviceFilter> filters_; |
| 109 |
| 110 DISALLOW_COPY_AND_ASSIGN(UsbGetDevicesFunction); |
106 }; | 111 }; |
107 | 112 |
108 class UsbGetUserSelectedDevicesFunction | 113 class UsbGetUserSelectedDevicesFunction |
109 : public UIThreadExtensionFunction, | 114 : public UIThreadExtensionFunction, |
110 public DevicePermissionsPrompt::Delegate { | 115 public DevicePermissionsPrompt::Delegate { |
111 public: | 116 public: |
112 DECLARE_EXTENSION_FUNCTION("usb.getUserSelectedDevices", | 117 DECLARE_EXTENSION_FUNCTION("usb.getUserSelectedDevices", |
113 USB_GETUSERSELECTEDDEVICES) | 118 USB_GETUSERSELECTEDDEVICES) |
114 | 119 |
115 UsbGetUserSelectedDevicesFunction(); | 120 UsbGetUserSelectedDevicesFunction(); |
116 | 121 |
117 protected: | 122 private: |
118 ~UsbGetUserSelectedDevicesFunction() override; | 123 ~UsbGetUserSelectedDevicesFunction() override; |
119 | 124 |
120 // ExtensionFunction: | 125 // ExtensionFunction: |
121 ResponseAction Run() override; | 126 ResponseAction Run() override; |
122 | 127 |
123 private: | |
124 void OnUsbDevicesChosen( | 128 void OnUsbDevicesChosen( |
125 const std::vector<scoped_refptr<device::UsbDevice>>& devices) override; | 129 const std::vector<scoped_refptr<device::UsbDevice>>& devices) override; |
126 | 130 |
127 scoped_ptr<DevicePermissionsPrompt> prompt_; | 131 scoped_ptr<DevicePermissionsPrompt> prompt_; |
128 std::vector<uint32> device_ids_; | 132 |
129 std::vector<scoped_refptr<device::UsbDevice>> devices_; | 133 DISALLOW_COPY_AND_ASSIGN(UsbGetUserSelectedDevicesFunction); |
130 std::vector<base::string16> serial_numbers_; | |
131 }; | 134 }; |
132 | 135 |
133 class UsbRequestAccessFunction : public UsbAsyncApiFunction { | 136 class UsbRequestAccessFunction : public UIThreadExtensionFunction { |
134 public: | 137 public: |
135 DECLARE_EXTENSION_FUNCTION("usb.requestAccess", USB_REQUESTACCESS) | 138 DECLARE_EXTENSION_FUNCTION("usb.requestAccess", USB_REQUESTACCESS) |
136 | 139 |
137 UsbRequestAccessFunction(); | 140 UsbRequestAccessFunction(); |
138 | 141 |
139 // AsyncApiFunction: | 142 private: |
140 bool Prepare() override; | |
141 void AsyncWorkStart() override; | |
142 | |
143 protected: | |
144 ~UsbRequestAccessFunction() override; | 143 ~UsbRequestAccessFunction() override; |
145 | 144 |
146 private: | 145 // ExtensionFunction: |
147 scoped_ptr<extensions::core_api::usb::RequestAccess::Params> parameters_; | 146 ResponseAction Run() override; |
| 147 |
| 148 DISALLOW_COPY_AND_ASSIGN(UsbRequestAccessFunction); |
148 }; | 149 }; |
149 | 150 |
150 class UsbOpenDeviceFunction : public UsbAsyncApiFunction { | 151 class UsbOpenDeviceFunction : public UsbPermissionCheckingFunction { |
151 public: | 152 public: |
152 DECLARE_EXTENSION_FUNCTION("usb.openDevice", USB_OPENDEVICE) | 153 DECLARE_EXTENSION_FUNCTION("usb.openDevice", USB_OPENDEVICE) |
153 | 154 |
154 UsbOpenDeviceFunction(); | 155 UsbOpenDeviceFunction(); |
155 | 156 |
156 // AsyncApiFunction: | 157 private: |
157 bool Prepare() override; | |
158 void AsyncWorkStart() override; | |
159 bool Respond() override; | |
160 | |
161 protected: | |
162 ~UsbOpenDeviceFunction() override; | 158 ~UsbOpenDeviceFunction() override; |
163 | 159 |
164 private: | 160 // ExtensionFunction: |
165 void OnRequestAccessComplete(bool success); | 161 ResponseAction Run() override; |
166 | 162 |
167 DevicePermissionsManager* device_permissions_manager_; | 163 void OnRequestAccessComplete(scoped_refptr<device::UsbDevice> device, |
168 scoped_refptr<device::UsbDevice> device_; | 164 bool success); |
169 scoped_ptr<extensions::core_api::usb::OpenDevice::Params> parameters_; | 165 void OnDeviceOpened(scoped_refptr<device::UsbDeviceHandle> device_handle); |
| 166 |
| 167 DISALLOW_COPY_AND_ASSIGN(UsbOpenDeviceFunction); |
170 }; | 168 }; |
171 | 169 |
172 class UsbSetConfigurationFunction : public UsbAsyncApiFunction { | 170 class UsbSetConfigurationFunction : public UsbConnectionFunction { |
173 public: | 171 public: |
174 DECLARE_EXTENSION_FUNCTION("usb.setConfiguration", USB_SETCONFIGURATION) | 172 DECLARE_EXTENSION_FUNCTION("usb.setConfiguration", USB_SETCONFIGURATION) |
175 | 173 |
176 UsbSetConfigurationFunction(); | 174 UsbSetConfigurationFunction(); |
177 | 175 |
178 protected: | 176 private: |
179 ~UsbSetConfigurationFunction() override; | 177 ~UsbSetConfigurationFunction() override; |
180 | 178 |
181 // AsyncApiFunction: | 179 // ExtensionFunction: |
182 bool Prepare() override; | 180 ResponseAction Run() override; |
183 void AsyncWorkStart() override; | |
184 | 181 |
185 private: | 182 void OnComplete(bool success); |
186 scoped_ptr<extensions::core_api::usb::SetConfiguration::Params> parameters_; | 183 |
| 184 DISALLOW_COPY_AND_ASSIGN(UsbSetConfigurationFunction); |
187 }; | 185 }; |
188 | 186 |
189 class UsbGetConfigurationFunction : public UsbAsyncApiFunction { | 187 class UsbGetConfigurationFunction : public UsbConnectionFunction { |
190 public: | 188 public: |
191 DECLARE_EXTENSION_FUNCTION("usb.getConfiguration", USB_GETCONFIGURATION) | 189 DECLARE_EXTENSION_FUNCTION("usb.getConfiguration", USB_GETCONFIGURATION) |
192 | 190 |
193 UsbGetConfigurationFunction(); | 191 UsbGetConfigurationFunction(); |
194 | 192 |
195 protected: | 193 private: |
196 ~UsbGetConfigurationFunction() override; | 194 ~UsbGetConfigurationFunction() override; |
197 | 195 |
198 // AsyncApiFunction: | 196 // ExtensionFunction: |
199 bool Prepare() override; | 197 ResponseAction Run() override; |
200 void AsyncWorkStart() override; | |
201 | 198 |
202 private: | 199 DISALLOW_COPY_AND_ASSIGN(UsbGetConfigurationFunction); |
203 scoped_ptr<extensions::core_api::usb::GetConfiguration::Params> parameters_; | |
204 }; | 200 }; |
205 | 201 |
206 class UsbListInterfacesFunction : public UsbAsyncApiFunction { | 202 class UsbListInterfacesFunction : public UsbConnectionFunction { |
207 public: | 203 public: |
208 DECLARE_EXTENSION_FUNCTION("usb.listInterfaces", USB_LISTINTERFACES) | 204 DECLARE_EXTENSION_FUNCTION("usb.listInterfaces", USB_LISTINTERFACES) |
209 | 205 |
210 UsbListInterfacesFunction(); | 206 UsbListInterfacesFunction(); |
211 | 207 |
212 protected: | 208 private: |
213 ~UsbListInterfacesFunction() override; | 209 ~UsbListInterfacesFunction() override; |
214 | 210 |
215 // AsyncApiFunction: | 211 // ExtensionFunction: |
216 bool Prepare() override; | 212 ResponseAction Run() override; |
217 void AsyncWorkStart() override; | |
218 | 213 |
219 private: | 214 DISALLOW_COPY_AND_ASSIGN(UsbListInterfacesFunction); |
220 scoped_ptr<extensions::core_api::usb::ListInterfaces::Params> parameters_; | |
221 }; | 215 }; |
222 | 216 |
223 class UsbCloseDeviceFunction : public UsbAsyncApiFunction { | 217 class UsbCloseDeviceFunction : public UsbConnectionFunction { |
224 public: | 218 public: |
225 DECLARE_EXTENSION_FUNCTION("usb.closeDevice", USB_CLOSEDEVICE) | 219 DECLARE_EXTENSION_FUNCTION("usb.closeDevice", USB_CLOSEDEVICE) |
226 | 220 |
227 UsbCloseDeviceFunction(); | 221 UsbCloseDeviceFunction(); |
228 | 222 |
229 protected: | 223 private: |
230 ~UsbCloseDeviceFunction() override; | 224 ~UsbCloseDeviceFunction() override; |
231 | 225 |
232 // AsyncApiFunction: | 226 // ExtensionFunction: |
233 bool Prepare() override; | 227 ResponseAction Run() override; |
234 void AsyncWorkStart() override; | |
235 | 228 |
236 private: | 229 DISALLOW_COPY_AND_ASSIGN(UsbCloseDeviceFunction); |
237 scoped_ptr<extensions::core_api::usb::CloseDevice::Params> parameters_; | |
238 }; | 230 }; |
239 | 231 |
240 class UsbClaimInterfaceFunction : public UsbAsyncApiFunction { | 232 class UsbClaimInterfaceFunction : public UsbConnectionFunction { |
241 public: | 233 public: |
242 DECLARE_EXTENSION_FUNCTION("usb.claimInterface", USB_CLAIMINTERFACE) | 234 DECLARE_EXTENSION_FUNCTION("usb.claimInterface", USB_CLAIMINTERFACE) |
243 | 235 |
244 UsbClaimInterfaceFunction(); | 236 UsbClaimInterfaceFunction(); |
245 | 237 |
246 protected: | 238 protected: |
247 ~UsbClaimInterfaceFunction() override; | 239 ~UsbClaimInterfaceFunction() override; |
248 | 240 |
249 // AsyncApiFunction: | 241 // ExtensionFunction: |
250 bool Prepare() override; | 242 ResponseAction Run() override; |
251 void AsyncWorkStart() override; | |
252 | 243 |
253 private: | 244 void OnComplete(bool success); |
254 scoped_ptr<extensions::core_api::usb::ClaimInterface::Params> parameters_; | 245 |
| 246 DISALLOW_COPY_AND_ASSIGN(UsbClaimInterfaceFunction); |
255 }; | 247 }; |
256 | 248 |
257 class UsbReleaseInterfaceFunction : public UsbAsyncApiFunction { | 249 class UsbReleaseInterfaceFunction : public UsbConnectionFunction { |
258 public: | 250 public: |
259 DECLARE_EXTENSION_FUNCTION("usb.releaseInterface", USB_RELEASEINTERFACE) | 251 DECLARE_EXTENSION_FUNCTION("usb.releaseInterface", USB_RELEASEINTERFACE) |
260 | 252 |
261 UsbReleaseInterfaceFunction(); | 253 UsbReleaseInterfaceFunction(); |
262 | 254 |
263 protected: | 255 private: |
264 ~UsbReleaseInterfaceFunction() override; | 256 ~UsbReleaseInterfaceFunction() override; |
265 | 257 |
266 // AsyncApiFunction: | 258 // ExtensionFunction: |
267 bool Prepare() override; | 259 ResponseAction Run() override; |
268 void AsyncWorkStart() override; | |
269 | 260 |
270 private: | 261 DISALLOW_COPY_AND_ASSIGN(UsbReleaseInterfaceFunction); |
271 scoped_ptr<extensions::core_api::usb::ReleaseInterface::Params> parameters_; | |
272 }; | 262 }; |
273 | 263 |
274 class UsbSetInterfaceAlternateSettingFunction : public UsbAsyncApiFunction { | 264 class UsbSetInterfaceAlternateSettingFunction : public UsbConnectionFunction { |
275 public: | 265 public: |
276 DECLARE_EXTENSION_FUNCTION("usb.setInterfaceAlternateSetting", | 266 DECLARE_EXTENSION_FUNCTION("usb.setInterfaceAlternateSetting", |
277 USB_SETINTERFACEALTERNATESETTING) | 267 USB_SETINTERFACEALTERNATESETTING) |
278 | 268 |
279 UsbSetInterfaceAlternateSettingFunction(); | 269 UsbSetInterfaceAlternateSettingFunction(); |
280 | 270 |
281 private: | 271 private: |
282 ~UsbSetInterfaceAlternateSettingFunction() override; | 272 ~UsbSetInterfaceAlternateSettingFunction() override; |
283 | 273 |
284 // AsyncApiFunction: | 274 // ExtensionFunction: |
285 bool Prepare() override; | 275 ResponseAction Run() override; |
286 void AsyncWorkStart() override; | |
287 | 276 |
288 scoped_ptr<extensions::core_api::usb::SetInterfaceAlternateSetting::Params> | 277 void OnComplete(bool success); |
289 parameters_; | 278 |
| 279 DISALLOW_COPY_AND_ASSIGN(UsbSetInterfaceAlternateSettingFunction); |
290 }; | 280 }; |
291 | 281 |
292 class UsbControlTransferFunction : public UsbAsyncApiTransferFunction { | 282 class UsbControlTransferFunction : public UsbTransferFunction { |
293 public: | 283 public: |
294 DECLARE_EXTENSION_FUNCTION("usb.controlTransfer", USB_CONTROLTRANSFER) | 284 DECLARE_EXTENSION_FUNCTION("usb.controlTransfer", USB_CONTROLTRANSFER) |
295 | 285 |
296 UsbControlTransferFunction(); | 286 UsbControlTransferFunction(); |
297 | 287 |
298 protected: | 288 private: |
299 ~UsbControlTransferFunction() override; | 289 ~UsbControlTransferFunction() override; |
300 | 290 |
301 // AsyncApiFunction: | 291 // ExtensionFunction: |
302 bool Prepare() override; | 292 ResponseAction Run() override; |
303 void AsyncWorkStart() override; | |
304 | 293 |
305 private: | 294 DISALLOW_COPY_AND_ASSIGN(UsbControlTransferFunction); |
306 scoped_ptr<extensions::core_api::usb::ControlTransfer::Params> parameters_; | |
307 }; | 295 }; |
308 | 296 |
309 class UsbBulkTransferFunction : public UsbAsyncApiTransferFunction { | 297 class UsbBulkTransferFunction : public UsbTransferFunction { |
310 public: | 298 public: |
311 DECLARE_EXTENSION_FUNCTION("usb.bulkTransfer", USB_BULKTRANSFER) | 299 DECLARE_EXTENSION_FUNCTION("usb.bulkTransfer", USB_BULKTRANSFER) |
312 | 300 |
313 UsbBulkTransferFunction(); | 301 UsbBulkTransferFunction(); |
314 | 302 |
315 protected: | 303 private: |
316 ~UsbBulkTransferFunction() override; | 304 ~UsbBulkTransferFunction() override; |
317 | 305 |
318 // AsyncApiFunction: | 306 // ExtensionFunction: |
319 bool Prepare() override; | 307 ResponseAction Run() override; |
320 void AsyncWorkStart() override; | |
321 | 308 |
322 private: | 309 DISALLOW_COPY_AND_ASSIGN(UsbBulkTransferFunction); |
323 scoped_ptr<extensions::core_api::usb::BulkTransfer::Params> parameters_; | |
324 }; | 310 }; |
325 | 311 |
326 class UsbInterruptTransferFunction : public UsbAsyncApiTransferFunction { | 312 class UsbInterruptTransferFunction : public UsbTransferFunction { |
327 public: | 313 public: |
328 DECLARE_EXTENSION_FUNCTION("usb.interruptTransfer", USB_INTERRUPTTRANSFER) | 314 DECLARE_EXTENSION_FUNCTION("usb.interruptTransfer", USB_INTERRUPTTRANSFER) |
329 | 315 |
330 UsbInterruptTransferFunction(); | 316 UsbInterruptTransferFunction(); |
331 | 317 |
332 protected: | 318 private: |
333 ~UsbInterruptTransferFunction() override; | 319 ~UsbInterruptTransferFunction() override; |
334 | 320 |
335 // AsyncApiFunction: | 321 // ExtensionFunction: |
336 bool Prepare() override; | 322 ResponseAction Run() override; |
337 void AsyncWorkStart() override; | |
338 | 323 |
339 private: | 324 DISALLOW_COPY_AND_ASSIGN(UsbInterruptTransferFunction); |
340 scoped_ptr<extensions::core_api::usb::InterruptTransfer::Params> parameters_; | |
341 }; | 325 }; |
342 | 326 |
343 class UsbIsochronousTransferFunction : public UsbAsyncApiTransferFunction { | 327 class UsbIsochronousTransferFunction : public UsbTransferFunction { |
344 public: | 328 public: |
345 DECLARE_EXTENSION_FUNCTION("usb.isochronousTransfer", USB_ISOCHRONOUSTRANSFER) | 329 DECLARE_EXTENSION_FUNCTION("usb.isochronousTransfer", USB_ISOCHRONOUSTRANSFER) |
346 | 330 |
347 UsbIsochronousTransferFunction(); | 331 UsbIsochronousTransferFunction(); |
348 | 332 |
349 protected: | 333 private: |
350 ~UsbIsochronousTransferFunction() override; | 334 ~UsbIsochronousTransferFunction() override; |
351 | 335 |
352 // AsyncApiFunction: | 336 // ExtensionFunction: |
353 bool Prepare() override; | 337 ResponseAction Run() override; |
354 void AsyncWorkStart() override; | |
355 | 338 |
356 private: | 339 DISALLOW_COPY_AND_ASSIGN(UsbIsochronousTransferFunction); |
357 scoped_ptr<extensions::core_api::usb::IsochronousTransfer::Params> | |
358 parameters_; | |
359 }; | 340 }; |
360 | 341 |
361 class UsbResetDeviceFunction : public UsbAsyncApiFunction { | 342 class UsbResetDeviceFunction : public UsbConnectionFunction { |
362 public: | 343 public: |
363 DECLARE_EXTENSION_FUNCTION("usb.resetDevice", USB_RESETDEVICE) | 344 DECLARE_EXTENSION_FUNCTION("usb.resetDevice", USB_RESETDEVICE) |
364 | 345 |
365 UsbResetDeviceFunction(); | 346 UsbResetDeviceFunction(); |
366 | 347 |
367 protected: | 348 private: |
368 ~UsbResetDeviceFunction() override; | 349 ~UsbResetDeviceFunction() override; |
369 | 350 |
370 // AsyncApiFunction: | 351 // ExtensionFunction: |
371 bool Prepare() override; | 352 ResponseAction Run() override; |
372 void AsyncWorkStart() override; | |
373 | 353 |
374 private: | 354 void OnComplete(bool success); |
| 355 |
375 scoped_ptr<extensions::core_api::usb::ResetDevice::Params> parameters_; | 356 scoped_ptr<extensions::core_api::usb::ResetDevice::Params> parameters_; |
| 357 |
| 358 DISALLOW_COPY_AND_ASSIGN(UsbResetDeviceFunction); |
376 }; | 359 }; |
377 } // namespace extensions | 360 } // namespace extensions |
378 | 361 |
379 #endif // EXTENSIONS_BROWSER_API_USB_USB_API_H_ | 362 #endif // EXTENSIONS_BROWSER_API_USB_USB_API_H_ |
OLD | NEW |