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_
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"
26 namespace extensions
{
28 class HidAsyncApiFunction
: public AsyncApiFunction
{
30 HidAsyncApiFunction();
32 bool PrePrepare() override
;
33 bool Respond() override
;
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_
;
47 DISALLOW_COPY_AND_ASSIGN(HidAsyncApiFunction
);
50 class HidGetDevicesFunction
: public HidAsyncApiFunction
{
52 DECLARE_EXTENSION_FUNCTION("hid.getDevices", HID_GETDEVICES
);
54 HidGetDevicesFunction();
57 bool Prepare() override
;
58 void AsyncWorkStart() override
;
60 ~HidGetDevicesFunction() override
;
62 scoped_ptr
<core_api::hid::GetDevices::Params
> parameters_
;
65 DISALLOW_COPY_AND_ASSIGN(HidGetDevicesFunction
);
68 class HidConnectFunction
: public HidAsyncApiFunction
{
70 DECLARE_EXTENSION_FUNCTION("hid.connect", HID_CONNECT
);
75 bool Prepare() override
;
76 void AsyncWorkStart() override
;
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
{
90 DECLARE_EXTENSION_FUNCTION("hid.disconnect", HID_DISCONNECT
);
92 HidDisconnectFunction();
95 bool Prepare() override
;
96 void AsyncWorkStart() override
;
99 ~HidDisconnectFunction() override
;
101 scoped_ptr
<core_api::hid::Disconnect::Params
> parameters_
;
103 DISALLOW_COPY_AND_ASSIGN(HidDisconnectFunction
);
106 class HidReceiveFunction
: public HidAsyncApiFunction
{
108 DECLARE_EXTENSION_FUNCTION("hid.receive", HID_RECEIVE
);
110 HidReceiveFunction();
113 bool Prepare() override
;
114 void AsyncWorkStart() override
;
117 ~HidReceiveFunction() override
;
119 void OnFinished(bool success
,
120 scoped_refptr
<net::IOBuffer
> buffer
,
123 scoped_ptr
<core_api::hid::Receive::Params
> parameters_
;
125 DISALLOW_COPY_AND_ASSIGN(HidReceiveFunction
);
128 class HidSendFunction
: public HidAsyncApiFunction
{
130 DECLARE_EXTENSION_FUNCTION("hid.send", HID_SEND
);
135 bool Prepare() override
;
136 void AsyncWorkStart() override
;
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
{
150 DECLARE_EXTENSION_FUNCTION("hid.receiveFeatureReport",
151 HID_RECEIVEFEATUREREPORT
);
153 HidReceiveFeatureReportFunction();
156 bool Prepare() override
;
157 void AsyncWorkStart() override
;
160 ~HidReceiveFeatureReportFunction() override
;
162 void OnFinished(bool success
,
163 scoped_refptr
<net::IOBuffer
> buffer
,
166 scoped_ptr
<core_api::hid::ReceiveFeatureReport::Params
> parameters_
;
168 DISALLOW_COPY_AND_ASSIGN(HidReceiveFeatureReportFunction
);
171 class HidSendFeatureReportFunction
: public HidAsyncApiFunction
{
173 DECLARE_EXTENSION_FUNCTION("hid.sendFeatureReport", HID_SENDFEATUREREPORT
);
175 HidSendFeatureReportFunction();
178 bool Prepare() override
;
179 void AsyncWorkStart() override
;
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_