Add testing/scripts/OWNERS
[chromium-blink-merge.git] / extensions / browser / api / hid / hid_api.h
blobcf439afc1917ae8650c6816d06bc90141761697d
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_HID_HID_API_H_
6 #define EXTENSIONS_BROWSER_API_HID_HID_API_H_
8 #include <string>
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "extensions/browser/api/api_resource_manager.h"
13 #include "extensions/browser/api/async_api_function.h"
14 #include "extensions/browser/api/hid/hid_connection_resource.h"
15 #include "extensions/browser/api/hid/hid_device_manager.h"
16 #include "extensions/common/api/hid.h"
18 namespace device {
19 class HidService;
20 } // namespace device
22 namespace net {
23 class IOBuffer;
24 } // namespace net
26 namespace extensions {
28 class HidAsyncApiFunction : public AsyncApiFunction {
29 public:
30 HidAsyncApiFunction();
32 bool PrePrepare() override;
33 bool Respond() override;
35 protected:
36 ~HidAsyncApiFunction() override;
38 HidConnectionResource* GetHidConnectionResource(int api_resource_id);
39 void RemoveHidConnectionResource(int api_resource_id);
41 void CompleteWithError(const std::string& error);
43 HidDeviceManager* device_manager_;
44 ApiResourceManager<HidConnectionResource>* connection_manager_;
46 private:
47 DISALLOW_COPY_AND_ASSIGN(HidAsyncApiFunction);
50 class HidGetDevicesFunction : public HidAsyncApiFunction {
51 public:
52 DECLARE_EXTENSION_FUNCTION("hid.getDevices", HID_GETDEVICES);
54 HidGetDevicesFunction();
56 protected:
57 bool Prepare() override;
58 void AsyncWorkStart() override;
60 ~HidGetDevicesFunction() override;
62 scoped_ptr<core_api::hid::GetDevices::Params> parameters_;
64 private:
65 DISALLOW_COPY_AND_ASSIGN(HidGetDevicesFunction);
68 class HidConnectFunction : public HidAsyncApiFunction {
69 public:
70 DECLARE_EXTENSION_FUNCTION("hid.connect", HID_CONNECT);
72 HidConnectFunction();
74 protected:
75 bool Prepare() override;
76 void AsyncWorkStart() override;
78 private:
79 ~HidConnectFunction() override;
81 void OnConnectComplete(scoped_refptr<device::HidConnection> connection);
83 scoped_ptr<core_api::hid::Connect::Params> parameters_;
85 DISALLOW_COPY_AND_ASSIGN(HidConnectFunction);
88 class HidDisconnectFunction : public HidAsyncApiFunction {
89 public:
90 DECLARE_EXTENSION_FUNCTION("hid.disconnect", HID_DISCONNECT);
92 HidDisconnectFunction();
94 protected:
95 bool Prepare() override;
96 void AsyncWorkStart() override;
98 private:
99 ~HidDisconnectFunction() override;
101 scoped_ptr<core_api::hid::Disconnect::Params> parameters_;
103 DISALLOW_COPY_AND_ASSIGN(HidDisconnectFunction);
106 class HidReceiveFunction : public HidAsyncApiFunction {
107 public:
108 DECLARE_EXTENSION_FUNCTION("hid.receive", HID_RECEIVE);
110 HidReceiveFunction();
112 protected:
113 bool Prepare() override;
114 void AsyncWorkStart() override;
116 private:
117 ~HidReceiveFunction() override;
119 void OnFinished(bool success,
120 scoped_refptr<net::IOBuffer> buffer,
121 size_t size);
123 scoped_ptr<core_api::hid::Receive::Params> parameters_;
125 DISALLOW_COPY_AND_ASSIGN(HidReceiveFunction);
128 class HidSendFunction : public HidAsyncApiFunction {
129 public:
130 DECLARE_EXTENSION_FUNCTION("hid.send", HID_SEND);
132 HidSendFunction();
134 protected:
135 bool Prepare() override;
136 void AsyncWorkStart() override;
138 private:
139 ~HidSendFunction() override;
141 void OnFinished(bool success);
143 scoped_ptr<core_api::hid::Send::Params> parameters_;
145 DISALLOW_COPY_AND_ASSIGN(HidSendFunction);
148 class HidReceiveFeatureReportFunction : public HidAsyncApiFunction {
149 public:
150 DECLARE_EXTENSION_FUNCTION("hid.receiveFeatureReport",
151 HID_RECEIVEFEATUREREPORT);
153 HidReceiveFeatureReportFunction();
155 protected:
156 bool Prepare() override;
157 void AsyncWorkStart() override;
159 private:
160 ~HidReceiveFeatureReportFunction() override;
162 void OnFinished(bool success,
163 scoped_refptr<net::IOBuffer> buffer,
164 size_t size);
166 scoped_ptr<core_api::hid::ReceiveFeatureReport::Params> parameters_;
168 DISALLOW_COPY_AND_ASSIGN(HidReceiveFeatureReportFunction);
171 class HidSendFeatureReportFunction : public HidAsyncApiFunction {
172 public:
173 DECLARE_EXTENSION_FUNCTION("hid.sendFeatureReport", HID_SENDFEATUREREPORT);
175 HidSendFeatureReportFunction();
177 protected:
178 bool Prepare() override;
179 void AsyncWorkStart() override;
181 private:
182 ~HidSendFeatureReportFunction() override;
184 void OnFinished(bool success);
186 scoped_ptr<core_api::hid::SendFeatureReport::Params> parameters_;
188 DISALLOW_COPY_AND_ASSIGN(HidSendFeatureReportFunction);
191 } // namespace extensions
193 #endif // EXTENSIONS_BROWSER_API_HID_HID_API_H_