Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / extensions / browser / api / usb / usb_api.h
blobc06c5577d6ed87f476338272c9ec39408010414e
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::core_api::usb::ConnectionHandle& handle);
49 void ReleaseDeviceHandle(
50 const extensions::core_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 OnRequestAccessComplete(scoped_refptr<device::UsbDevice> device,
78 bool success);
79 void OnDeviceOpened(scoped_refptr<device::UsbDeviceHandle> device_handle);
80 void OpenComplete();
82 uint16_t vendor_id_;
83 uint16_t product_id_;
84 int interface_id_;
85 scoped_ptr<base::ListValue> result_;
86 base::Closure barrier_;
88 DISALLOW_COPY_AND_ASSIGN(UsbFindDevicesFunction);
91 class UsbGetDevicesFunction : public UsbPermissionCheckingFunction {
92 public:
93 DECLARE_EXTENSION_FUNCTION("usb.getDevices", USB_GETDEVICES)
95 UsbGetDevicesFunction();
97 private:
98 ~UsbGetDevicesFunction() override;
100 // ExtensionFunction:
101 ResponseAction Run() override;
103 void OnGetDevicesComplete(
104 const std::vector<scoped_refptr<device::UsbDevice>>& devices);
106 std::vector<device::UsbDeviceFilter> filters_;
108 DISALLOW_COPY_AND_ASSIGN(UsbGetDevicesFunction);
111 class UsbGetUserSelectedDevicesFunction : public UIThreadExtensionFunction {
112 public:
113 DECLARE_EXTENSION_FUNCTION("usb.getUserSelectedDevices",
114 USB_GETUSERSELECTEDDEVICES)
116 UsbGetUserSelectedDevicesFunction();
118 private:
119 ~UsbGetUserSelectedDevicesFunction() override;
121 // ExtensionFunction:
122 ResponseAction Run() override;
124 void OnDevicesChosen(
125 const std::vector<scoped_refptr<device::UsbDevice>>& devices);
127 scoped_ptr<DevicePermissionsPrompt> prompt_;
129 DISALLOW_COPY_AND_ASSIGN(UsbGetUserSelectedDevicesFunction);
132 class UsbRequestAccessFunction : public UIThreadExtensionFunction {
133 public:
134 DECLARE_EXTENSION_FUNCTION("usb.requestAccess", USB_REQUESTACCESS)
136 UsbRequestAccessFunction();
138 private:
139 ~UsbRequestAccessFunction() override;
141 // ExtensionFunction:
142 ResponseAction Run() override;
144 DISALLOW_COPY_AND_ASSIGN(UsbRequestAccessFunction);
147 class UsbOpenDeviceFunction : public UsbPermissionCheckingFunction {
148 public:
149 DECLARE_EXTENSION_FUNCTION("usb.openDevice", USB_OPENDEVICE)
151 UsbOpenDeviceFunction();
153 private:
154 ~UsbOpenDeviceFunction() override;
156 // ExtensionFunction:
157 ResponseAction Run() override;
159 void OnRequestAccessComplete(scoped_refptr<device::UsbDevice> device,
160 bool success);
161 void OnDeviceOpened(scoped_refptr<device::UsbDeviceHandle> device_handle);
163 DISALLOW_COPY_AND_ASSIGN(UsbOpenDeviceFunction);
166 class UsbSetConfigurationFunction : public UsbConnectionFunction {
167 public:
168 DECLARE_EXTENSION_FUNCTION("usb.setConfiguration", USB_SETCONFIGURATION)
170 UsbSetConfigurationFunction();
172 private:
173 ~UsbSetConfigurationFunction() override;
175 // ExtensionFunction:
176 ResponseAction Run() override;
178 void OnComplete(bool success);
180 DISALLOW_COPY_AND_ASSIGN(UsbSetConfigurationFunction);
183 class UsbGetConfigurationFunction : public UsbConnectionFunction {
184 public:
185 DECLARE_EXTENSION_FUNCTION("usb.getConfiguration", USB_GETCONFIGURATION)
187 UsbGetConfigurationFunction();
189 private:
190 ~UsbGetConfigurationFunction() override;
192 // ExtensionFunction:
193 ResponseAction Run() override;
195 DISALLOW_COPY_AND_ASSIGN(UsbGetConfigurationFunction);
198 class UsbListInterfacesFunction : public UsbConnectionFunction {
199 public:
200 DECLARE_EXTENSION_FUNCTION("usb.listInterfaces", USB_LISTINTERFACES)
202 UsbListInterfacesFunction();
204 private:
205 ~UsbListInterfacesFunction() override;
207 // ExtensionFunction:
208 ResponseAction Run() override;
210 DISALLOW_COPY_AND_ASSIGN(UsbListInterfacesFunction);
213 class UsbCloseDeviceFunction : public UsbConnectionFunction {
214 public:
215 DECLARE_EXTENSION_FUNCTION("usb.closeDevice", USB_CLOSEDEVICE)
217 UsbCloseDeviceFunction();
219 private:
220 ~UsbCloseDeviceFunction() override;
222 // ExtensionFunction:
223 ResponseAction Run() override;
225 DISALLOW_COPY_AND_ASSIGN(UsbCloseDeviceFunction);
228 class UsbClaimInterfaceFunction : public UsbConnectionFunction {
229 public:
230 DECLARE_EXTENSION_FUNCTION("usb.claimInterface", USB_CLAIMINTERFACE)
232 UsbClaimInterfaceFunction();
234 protected:
235 ~UsbClaimInterfaceFunction() override;
237 // ExtensionFunction:
238 ResponseAction Run() override;
240 void OnComplete(bool success);
242 DISALLOW_COPY_AND_ASSIGN(UsbClaimInterfaceFunction);
245 class UsbReleaseInterfaceFunction : public UsbConnectionFunction {
246 public:
247 DECLARE_EXTENSION_FUNCTION("usb.releaseInterface", USB_RELEASEINTERFACE)
249 UsbReleaseInterfaceFunction();
251 private:
252 ~UsbReleaseInterfaceFunction() override;
254 // ExtensionFunction:
255 ResponseAction Run() override;
257 DISALLOW_COPY_AND_ASSIGN(UsbReleaseInterfaceFunction);
260 class UsbSetInterfaceAlternateSettingFunction : public UsbConnectionFunction {
261 public:
262 DECLARE_EXTENSION_FUNCTION("usb.setInterfaceAlternateSetting",
263 USB_SETINTERFACEALTERNATESETTING)
265 UsbSetInterfaceAlternateSettingFunction();
267 private:
268 ~UsbSetInterfaceAlternateSettingFunction() override;
270 // ExtensionFunction:
271 ResponseAction Run() override;
273 void OnComplete(bool success);
275 DISALLOW_COPY_AND_ASSIGN(UsbSetInterfaceAlternateSettingFunction);
278 class UsbControlTransferFunction : public UsbTransferFunction {
279 public:
280 DECLARE_EXTENSION_FUNCTION("usb.controlTransfer", USB_CONTROLTRANSFER)
282 UsbControlTransferFunction();
284 private:
285 ~UsbControlTransferFunction() override;
287 // ExtensionFunction:
288 ResponseAction Run() override;
290 DISALLOW_COPY_AND_ASSIGN(UsbControlTransferFunction);
293 class UsbBulkTransferFunction : public UsbTransferFunction {
294 public:
295 DECLARE_EXTENSION_FUNCTION("usb.bulkTransfer", USB_BULKTRANSFER)
297 UsbBulkTransferFunction();
299 private:
300 ~UsbBulkTransferFunction() override;
302 // ExtensionFunction:
303 ResponseAction Run() override;
305 DISALLOW_COPY_AND_ASSIGN(UsbBulkTransferFunction);
308 class UsbInterruptTransferFunction : public UsbTransferFunction {
309 public:
310 DECLARE_EXTENSION_FUNCTION("usb.interruptTransfer", USB_INTERRUPTTRANSFER)
312 UsbInterruptTransferFunction();
314 private:
315 ~UsbInterruptTransferFunction() override;
317 // ExtensionFunction:
318 ResponseAction Run() override;
320 DISALLOW_COPY_AND_ASSIGN(UsbInterruptTransferFunction);
323 class UsbIsochronousTransferFunction : public UsbTransferFunction {
324 public:
325 DECLARE_EXTENSION_FUNCTION("usb.isochronousTransfer", USB_ISOCHRONOUSTRANSFER)
327 UsbIsochronousTransferFunction();
329 private:
330 ~UsbIsochronousTransferFunction() override;
332 // ExtensionFunction:
333 ResponseAction Run() override;
335 DISALLOW_COPY_AND_ASSIGN(UsbIsochronousTransferFunction);
338 class UsbResetDeviceFunction : public UsbConnectionFunction {
339 public:
340 DECLARE_EXTENSION_FUNCTION("usb.resetDevice", USB_RESETDEVICE)
342 UsbResetDeviceFunction();
344 private:
345 ~UsbResetDeviceFunction() override;
347 // ExtensionFunction:
348 ResponseAction Run() override;
350 void OnComplete(bool success);
352 scoped_ptr<extensions::core_api::usb::ResetDevice::Params> parameters_;
354 DISALLOW_COPY_AND_ASSIGN(UsbResetDeviceFunction);
356 } // namespace extensions
358 #endif // EXTENSIONS_BROWSER_API_USB_USB_API_H_