Add ICU message format support
[chromium-blink-merge.git] / extensions / browser / api / usb / usb_api.h
blobbe56a51a4c5ae04aa6f0a17278ae47435b6e8f97
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
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_BROWSER_API_USB_USB_API_H_
6 #define EXTENSIONS_BROWSER_API_USB_USB_API_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "device/usb/usb_device.h"
14 #include "device/usb/usb_device_filter.h"
15 #include "device/usb/usb_device_handle.h"
16 #include "extensions/browser/api/api_resource_manager.h"
17 #include "extensions/browser/extension_function.h"
18 #include "extensions/common/api/usb.h"
19 #include "net/base/io_buffer.h"
21 namespace extensions {
23 class DevicePermissionEntry;
24 class DevicePermissions;
25 class DevicePermissionsPrompt;
26 class DevicePermissionsManager;
27 class UsbDeviceResource;
29 class UsbPermissionCheckingFunction : public UIThreadExtensionFunction {
30 protected:
31 UsbPermissionCheckingFunction();
32 ~UsbPermissionCheckingFunction() override;
34 bool HasDevicePermission(scoped_refptr<device::UsbDevice> device);
35 void RecordDeviceLastUsed();
37 private:
38 DevicePermissionsManager* device_permissions_manager_;
39 scoped_refptr<DevicePermissionEntry> permission_entry_;
42 class UsbConnectionFunction : public UIThreadExtensionFunction {
43 protected:
44 UsbConnectionFunction();
45 ~UsbConnectionFunction() override;
47 scoped_refptr<device::UsbDeviceHandle> GetDeviceHandle(
48 const extensions::api::usb::ConnectionHandle& handle);
49 void ReleaseDeviceHandle(
50 const extensions::api::usb::ConnectionHandle& handle);
53 class UsbTransferFunction : public UsbConnectionFunction {
54 protected:
55 UsbTransferFunction();
56 ~UsbTransferFunction() override;
58 void OnCompleted(device::UsbTransferStatus status,
59 scoped_refptr<net::IOBuffer> data,
60 size_t length);
63 class UsbFindDevicesFunction : public UIThreadExtensionFunction {
64 public:
65 DECLARE_EXTENSION_FUNCTION("usb.findDevices", USB_FINDDEVICES)
67 UsbFindDevicesFunction();
69 private:
70 ~UsbFindDevicesFunction() override;
72 // ExtensionFunction:
73 ResponseAction Run() override;
75 void OnGetDevicesComplete(
76 const std::vector<scoped_refptr<device::UsbDevice>>& devices);
77 void OnDeviceOpened(scoped_refptr<device::UsbDeviceHandle> device_handle);
78 void OpenComplete();
80 uint16_t vendor_id_;
81 uint16_t product_id_;
82 scoped_ptr<base::ListValue> result_;
83 base::Closure barrier_;
85 DISALLOW_COPY_AND_ASSIGN(UsbFindDevicesFunction);
88 class UsbGetDevicesFunction : public UsbPermissionCheckingFunction {
89 public:
90 DECLARE_EXTENSION_FUNCTION("usb.getDevices", USB_GETDEVICES)
92 UsbGetDevicesFunction();
94 private:
95 ~UsbGetDevicesFunction() override;
97 // ExtensionFunction:
98 ResponseAction Run() override;
100 void OnGetDevicesComplete(
101 const std::vector<scoped_refptr<device::UsbDevice>>& devices);
103 std::vector<device::UsbDeviceFilter> filters_;
105 DISALLOW_COPY_AND_ASSIGN(UsbGetDevicesFunction);
108 class UsbGetUserSelectedDevicesFunction : public UIThreadExtensionFunction {
109 public:
110 DECLARE_EXTENSION_FUNCTION("usb.getUserSelectedDevices",
111 USB_GETUSERSELECTEDDEVICES)
113 UsbGetUserSelectedDevicesFunction();
115 private:
116 ~UsbGetUserSelectedDevicesFunction() override;
118 // ExtensionFunction:
119 ResponseAction Run() override;
121 void OnDevicesChosen(
122 const std::vector<scoped_refptr<device::UsbDevice>>& devices);
124 scoped_ptr<DevicePermissionsPrompt> prompt_;
126 DISALLOW_COPY_AND_ASSIGN(UsbGetUserSelectedDevicesFunction);
129 class UsbRequestAccessFunction : public UIThreadExtensionFunction {
130 public:
131 DECLARE_EXTENSION_FUNCTION("usb.requestAccess", USB_REQUESTACCESS)
133 UsbRequestAccessFunction();
135 private:
136 ~UsbRequestAccessFunction() override;
138 // ExtensionFunction:
139 ResponseAction Run() override;
141 DISALLOW_COPY_AND_ASSIGN(UsbRequestAccessFunction);
144 class UsbOpenDeviceFunction : public UsbPermissionCheckingFunction {
145 public:
146 DECLARE_EXTENSION_FUNCTION("usb.openDevice", USB_OPENDEVICE)
148 UsbOpenDeviceFunction();
150 private:
151 ~UsbOpenDeviceFunction() override;
153 // ExtensionFunction:
154 ResponseAction Run() override;
156 void OnDeviceOpened(scoped_refptr<device::UsbDeviceHandle> device_handle);
158 DISALLOW_COPY_AND_ASSIGN(UsbOpenDeviceFunction);
161 class UsbSetConfigurationFunction : public UsbConnectionFunction {
162 public:
163 DECLARE_EXTENSION_FUNCTION("usb.setConfiguration", USB_SETCONFIGURATION)
165 UsbSetConfigurationFunction();
167 private:
168 ~UsbSetConfigurationFunction() override;
170 // ExtensionFunction:
171 ResponseAction Run() override;
173 void OnComplete(bool success);
175 DISALLOW_COPY_AND_ASSIGN(UsbSetConfigurationFunction);
178 class UsbGetConfigurationFunction : public UsbConnectionFunction {
179 public:
180 DECLARE_EXTENSION_FUNCTION("usb.getConfiguration", USB_GETCONFIGURATION)
182 UsbGetConfigurationFunction();
184 private:
185 ~UsbGetConfigurationFunction() override;
187 // ExtensionFunction:
188 ResponseAction Run() override;
190 DISALLOW_COPY_AND_ASSIGN(UsbGetConfigurationFunction);
193 class UsbListInterfacesFunction : public UsbConnectionFunction {
194 public:
195 DECLARE_EXTENSION_FUNCTION("usb.listInterfaces", USB_LISTINTERFACES)
197 UsbListInterfacesFunction();
199 private:
200 ~UsbListInterfacesFunction() override;
202 // ExtensionFunction:
203 ResponseAction Run() override;
205 DISALLOW_COPY_AND_ASSIGN(UsbListInterfacesFunction);
208 class UsbCloseDeviceFunction : public UsbConnectionFunction {
209 public:
210 DECLARE_EXTENSION_FUNCTION("usb.closeDevice", USB_CLOSEDEVICE)
212 UsbCloseDeviceFunction();
214 private:
215 ~UsbCloseDeviceFunction() override;
217 // ExtensionFunction:
218 ResponseAction Run() override;
220 DISALLOW_COPY_AND_ASSIGN(UsbCloseDeviceFunction);
223 class UsbClaimInterfaceFunction : public UsbConnectionFunction {
224 public:
225 DECLARE_EXTENSION_FUNCTION("usb.claimInterface", USB_CLAIMINTERFACE)
227 UsbClaimInterfaceFunction();
229 protected:
230 ~UsbClaimInterfaceFunction() override;
232 // ExtensionFunction:
233 ResponseAction Run() override;
235 void OnComplete(bool success);
237 DISALLOW_COPY_AND_ASSIGN(UsbClaimInterfaceFunction);
240 class UsbReleaseInterfaceFunction : public UsbConnectionFunction {
241 public:
242 DECLARE_EXTENSION_FUNCTION("usb.releaseInterface", USB_RELEASEINTERFACE)
244 UsbReleaseInterfaceFunction();
246 private:
247 ~UsbReleaseInterfaceFunction() override;
249 // ExtensionFunction:
250 ResponseAction Run() override;
252 DISALLOW_COPY_AND_ASSIGN(UsbReleaseInterfaceFunction);
255 class UsbSetInterfaceAlternateSettingFunction : public UsbConnectionFunction {
256 public:
257 DECLARE_EXTENSION_FUNCTION("usb.setInterfaceAlternateSetting",
258 USB_SETINTERFACEALTERNATESETTING)
260 UsbSetInterfaceAlternateSettingFunction();
262 private:
263 ~UsbSetInterfaceAlternateSettingFunction() override;
265 // ExtensionFunction:
266 ResponseAction Run() override;
268 void OnComplete(bool success);
270 DISALLOW_COPY_AND_ASSIGN(UsbSetInterfaceAlternateSettingFunction);
273 class UsbControlTransferFunction : public UsbTransferFunction {
274 public:
275 DECLARE_EXTENSION_FUNCTION("usb.controlTransfer", USB_CONTROLTRANSFER)
277 UsbControlTransferFunction();
279 private:
280 ~UsbControlTransferFunction() override;
282 // ExtensionFunction:
283 ResponseAction Run() override;
285 DISALLOW_COPY_AND_ASSIGN(UsbControlTransferFunction);
288 class UsbBulkTransferFunction : public UsbTransferFunction {
289 public:
290 DECLARE_EXTENSION_FUNCTION("usb.bulkTransfer", USB_BULKTRANSFER)
292 UsbBulkTransferFunction();
294 private:
295 ~UsbBulkTransferFunction() override;
297 // ExtensionFunction:
298 ResponseAction Run() override;
300 DISALLOW_COPY_AND_ASSIGN(UsbBulkTransferFunction);
303 class UsbInterruptTransferFunction : public UsbTransferFunction {
304 public:
305 DECLARE_EXTENSION_FUNCTION("usb.interruptTransfer", USB_INTERRUPTTRANSFER)
307 UsbInterruptTransferFunction();
309 private:
310 ~UsbInterruptTransferFunction() override;
312 // ExtensionFunction:
313 ResponseAction Run() override;
315 DISALLOW_COPY_AND_ASSIGN(UsbInterruptTransferFunction);
318 class UsbIsochronousTransferFunction : public UsbTransferFunction {
319 public:
320 DECLARE_EXTENSION_FUNCTION("usb.isochronousTransfer", USB_ISOCHRONOUSTRANSFER)
322 UsbIsochronousTransferFunction();
324 private:
325 ~UsbIsochronousTransferFunction() override;
327 // ExtensionFunction:
328 ResponseAction Run() override;
330 DISALLOW_COPY_AND_ASSIGN(UsbIsochronousTransferFunction);
333 class UsbResetDeviceFunction : public UsbConnectionFunction {
334 public:
335 DECLARE_EXTENSION_FUNCTION("usb.resetDevice", USB_RESETDEVICE)
337 UsbResetDeviceFunction();
339 private:
340 ~UsbResetDeviceFunction() override;
342 // ExtensionFunction:
343 ResponseAction Run() override;
345 void OnComplete(bool success);
347 scoped_ptr<extensions::api::usb::ResetDevice::Params> parameters_;
349 DISALLOW_COPY_AND_ASSIGN(UsbResetDeviceFunction);
351 } // namespace extensions
353 #endif // EXTENSIONS_BROWSER_API_USB_USB_API_H_