Update path of checkdeps to buildtools checkout
[chromium-blink-merge.git] / extensions / browser / api / usb / usb_api.h
blob3dd0d2b5d5e6b022b56e3e7eca16b9d86484a318
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 "components/usb_service/usb_device.h"
14 #include "components/usb_service/usb_device_handle.h"
15 #include "extensions/browser/api/api_resource_manager.h"
16 #include "extensions/browser/api/async_api_function.h"
17 #include "extensions/common/api/usb.h"
18 #include "net/base/io_buffer.h"
20 namespace extensions {
22 class UsbDeviceResource;
24 class UsbAsyncApiFunction : public AsyncApiFunction {
25 public:
26 UsbAsyncApiFunction();
28 protected:
29 virtual ~UsbAsyncApiFunction();
31 virtual bool PrePrepare() OVERRIDE;
32 virtual bool Respond() OVERRIDE;
34 scoped_refptr<usb_service::UsbDevice> GetDeviceOrOrCompleteWithError(
35 const extensions::core_api::usb::Device& input_device);
37 scoped_refptr<usb_service::UsbDeviceHandle>
38 GetDeviceHandleOrCompleteWithError(
39 const extensions::core_api::usb::ConnectionHandle&
40 input_device_handle);
42 void RemoveUsbDeviceResource(int api_resource_id);
44 void CompleteWithError(const std::string& error);
46 ApiResourceManager<UsbDeviceResource>* manager_;
49 class UsbAsyncApiTransferFunction : public UsbAsyncApiFunction {
50 protected:
51 UsbAsyncApiTransferFunction();
52 virtual ~UsbAsyncApiTransferFunction();
54 bool ConvertDirectionSafely(const extensions::core_api::usb::Direction& input,
55 usb_service::UsbEndpointDirection* output);
56 bool ConvertRequestTypeSafely(
57 const extensions::core_api::usb::RequestType& input,
58 usb_service::UsbDeviceHandle::TransferRequestType* output);
59 bool ConvertRecipientSafely(
60 const extensions::core_api::usb::Recipient& input,
61 usb_service::UsbDeviceHandle::TransferRecipient* output);
63 void OnCompleted(usb_service::UsbTransferStatus status,
64 scoped_refptr<net::IOBuffer> data,
65 size_t length);
68 class UsbFindDevicesFunction : public UsbAsyncApiFunction {
69 public:
70 DECLARE_EXTENSION_FUNCTION("usb.findDevices", USB_FINDDEVICES)
72 UsbFindDevicesFunction();
74 protected:
75 virtual ~UsbFindDevicesFunction();
77 virtual bool Prepare() OVERRIDE;
78 virtual void AsyncWorkStart() OVERRIDE;
80 private:
81 void OpenDevices(
82 scoped_ptr<std::vector<scoped_refptr<usb_service::UsbDevice> > > devices);
84 std::vector<scoped_refptr<usb_service::UsbDeviceHandle> > device_handles_;
85 scoped_ptr<extensions::core_api::usb::FindDevices::Params> parameters_;
88 class UsbGetDevicesFunction : public UsbAsyncApiFunction {
89 public:
90 DECLARE_EXTENSION_FUNCTION("usb.getDevices", USB_GETDEVICES)
92 UsbGetDevicesFunction();
94 virtual bool Prepare() OVERRIDE;
95 virtual void AsyncWorkStart() OVERRIDE;
97 protected:
98 virtual ~UsbGetDevicesFunction();
100 private:
101 void EnumerationCompletedFileThread(
102 scoped_ptr<std::vector<scoped_refptr<usb_service::UsbDevice> > > devices);
104 scoped_ptr<extensions::core_api::usb::GetDevices::Params> parameters_;
107 class UsbRequestAccessFunction : public UsbAsyncApiFunction {
108 public:
109 DECLARE_EXTENSION_FUNCTION("usb.requestAccess", USB_REQUESTACCESS)
111 UsbRequestAccessFunction();
113 virtual bool Prepare() OVERRIDE;
114 virtual void AsyncWorkStart() OVERRIDE;
116 protected:
117 virtual ~UsbRequestAccessFunction();
119 void OnCompleted(bool success);
121 private:
122 scoped_ptr<extensions::core_api::usb::RequestAccess::Params> parameters_;
125 class UsbOpenDeviceFunction : public UsbAsyncApiFunction {
126 public:
127 DECLARE_EXTENSION_FUNCTION("usb.openDevice", USB_OPENDEVICE)
129 UsbOpenDeviceFunction();
131 virtual bool Prepare() OVERRIDE;
132 virtual void AsyncWorkStart() OVERRIDE;
134 protected:
135 virtual ~UsbOpenDeviceFunction();
137 private:
138 scoped_refptr<usb_service::UsbDeviceHandle> handle_;
139 scoped_ptr<extensions::core_api::usb::OpenDevice::Params> parameters_;
142 class UsbListInterfacesFunction : public UsbAsyncApiFunction {
143 public:
144 DECLARE_EXTENSION_FUNCTION("usb.listInterfaces", USB_LISTINTERFACES)
146 UsbListInterfacesFunction();
148 protected:
149 virtual ~UsbListInterfacesFunction();
151 virtual bool Prepare() OVERRIDE;
152 virtual void AsyncWorkStart() OVERRIDE;
154 private:
155 bool ConvertDirectionSafely(const usb_service::UsbEndpointDirection& input,
156 extensions::core_api::usb::Direction* output);
157 bool ConvertSynchronizationTypeSafely(
158 const usb_service::UsbSynchronizationType& input,
159 extensions::core_api::usb::SynchronizationType* output);
160 bool ConvertTransferTypeSafely(
161 const usb_service::UsbTransferType& input,
162 extensions::core_api::usb::TransferType* output);
163 bool ConvertUsageTypeSafely(const usb_service::UsbUsageType& input,
164 extensions::core_api::usb::UsageType* output);
166 scoped_ptr<base::ListValue> result_;
167 scoped_ptr<extensions::core_api::usb::ListInterfaces::Params> parameters_;
170 class UsbCloseDeviceFunction : public UsbAsyncApiFunction {
171 public:
172 DECLARE_EXTENSION_FUNCTION("usb.closeDevice", USB_CLOSEDEVICE)
174 UsbCloseDeviceFunction();
176 protected:
177 virtual ~UsbCloseDeviceFunction();
179 virtual bool Prepare() OVERRIDE;
180 virtual void AsyncWorkStart() OVERRIDE;
182 private:
183 scoped_ptr<extensions::core_api::usb::CloseDevice::Params> parameters_;
186 class UsbClaimInterfaceFunction : public UsbAsyncApiFunction {
187 public:
188 DECLARE_EXTENSION_FUNCTION("usb.claimInterface", USB_CLAIMINTERFACE)
190 UsbClaimInterfaceFunction();
192 protected:
193 virtual ~UsbClaimInterfaceFunction();
195 virtual bool Prepare() OVERRIDE;
196 virtual void AsyncWorkStart() OVERRIDE;
198 private:
199 scoped_ptr<extensions::core_api::usb::ClaimInterface::Params> parameters_;
202 class UsbReleaseInterfaceFunction : public UsbAsyncApiFunction {
203 public:
204 DECLARE_EXTENSION_FUNCTION("usb.releaseInterface", USB_RELEASEINTERFACE)
206 UsbReleaseInterfaceFunction();
208 protected:
209 virtual ~UsbReleaseInterfaceFunction();
211 virtual bool Prepare() OVERRIDE;
212 virtual void AsyncWorkStart() OVERRIDE;
214 private:
215 scoped_ptr<extensions::core_api::usb::ReleaseInterface::Params> parameters_;
218 class UsbSetInterfaceAlternateSettingFunction : public UsbAsyncApiFunction {
219 public:
220 DECLARE_EXTENSION_FUNCTION("usb.setInterfaceAlternateSetting",
221 USB_SETINTERFACEALTERNATESETTING)
223 UsbSetInterfaceAlternateSettingFunction();
225 private:
226 virtual ~UsbSetInterfaceAlternateSettingFunction();
228 virtual bool Prepare() OVERRIDE;
229 virtual void AsyncWorkStart() OVERRIDE;
231 scoped_ptr<extensions::core_api::usb::SetInterfaceAlternateSetting::Params>
232 parameters_;
235 class UsbControlTransferFunction : public UsbAsyncApiTransferFunction {
236 public:
237 DECLARE_EXTENSION_FUNCTION("usb.controlTransfer", USB_CONTROLTRANSFER)
239 UsbControlTransferFunction();
241 protected:
242 virtual ~UsbControlTransferFunction();
244 virtual bool Prepare() OVERRIDE;
245 virtual void AsyncWorkStart() OVERRIDE;
247 private:
248 scoped_ptr<extensions::core_api::usb::ControlTransfer::Params> parameters_;
251 class UsbBulkTransferFunction : public UsbAsyncApiTransferFunction {
252 public:
253 DECLARE_EXTENSION_FUNCTION("usb.bulkTransfer", USB_BULKTRANSFER)
255 UsbBulkTransferFunction();
257 protected:
258 virtual ~UsbBulkTransferFunction();
260 virtual bool Prepare() OVERRIDE;
261 virtual void AsyncWorkStart() OVERRIDE;
263 private:
264 scoped_ptr<extensions::core_api::usb::BulkTransfer::Params> parameters_;
267 class UsbInterruptTransferFunction : public UsbAsyncApiTransferFunction {
268 public:
269 DECLARE_EXTENSION_FUNCTION("usb.interruptTransfer", USB_INTERRUPTTRANSFER)
271 UsbInterruptTransferFunction();
273 protected:
274 virtual ~UsbInterruptTransferFunction();
276 virtual bool Prepare() OVERRIDE;
277 virtual void AsyncWorkStart() OVERRIDE;
279 private:
280 scoped_ptr<extensions::core_api::usb::InterruptTransfer::Params> parameters_;
283 class UsbIsochronousTransferFunction : public UsbAsyncApiTransferFunction {
284 public:
285 DECLARE_EXTENSION_FUNCTION("usb.isochronousTransfer", USB_ISOCHRONOUSTRANSFER)
287 UsbIsochronousTransferFunction();
289 protected:
290 virtual ~UsbIsochronousTransferFunction();
292 virtual bool Prepare() OVERRIDE;
293 virtual void AsyncWorkStart() OVERRIDE;
295 private:
296 scoped_ptr<extensions::core_api::usb::IsochronousTransfer::Params>
297 parameters_;
300 class UsbResetDeviceFunction : public UsbAsyncApiFunction {
301 public:
302 DECLARE_EXTENSION_FUNCTION("usb.resetDevice", USB_RESETDEVICE)
304 UsbResetDeviceFunction();
306 protected:
307 virtual ~UsbResetDeviceFunction();
309 virtual bool Prepare() OVERRIDE;
310 virtual void AsyncWorkStart() OVERRIDE;
312 private:
313 scoped_ptr<extensions::core_api::usb::ResetDevice::Params> parameters_;
315 } // namespace extensions
317 #endif // EXTENSIONS_BROWSER_API_USB_USB_API_H_