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/hid/hid_connection_resource.h"
14 #include "extensions/browser/api/hid/hid_device_manager.h"
15 #include "extensions/browser/extension_function.h"
16 #include "extensions/common/api/hid.h"
27 namespace extensions
{
29 class HidGetDevicesFunction
: public UIThreadExtensionFunction
{
31 DECLARE_EXTENSION_FUNCTION("hid.getDevices", HID_GETDEVICES
);
33 HidGetDevicesFunction();
36 ~HidGetDevicesFunction() override
;
39 ResponseAction
Run() override
;
41 void OnEnumerationComplete(scoped_ptr
<base::ListValue
> devices
);
43 DISALLOW_COPY_AND_ASSIGN(HidGetDevicesFunction
);
46 class HidConnectFunction
: public UIThreadExtensionFunction
{
48 DECLARE_EXTENSION_FUNCTION("hid.connect", HID_CONNECT
);
53 ~HidConnectFunction() override
;
56 ResponseAction
Run() override
;
58 void OnConnectComplete(scoped_refptr
<device::HidConnection
> connection
);
60 ApiResourceManager
<HidConnectionResource
>* connection_manager_
;
62 DISALLOW_COPY_AND_ASSIGN(HidConnectFunction
);
65 class HidDisconnectFunction
: public UIThreadExtensionFunction
{
67 DECLARE_EXTENSION_FUNCTION("hid.disconnect", HID_DISCONNECT
);
69 HidDisconnectFunction();
72 ~HidDisconnectFunction() override
;
75 ResponseAction
Run() override
;
77 DISALLOW_COPY_AND_ASSIGN(HidDisconnectFunction
);
80 // Base class for extension functions that start some asynchronous work after
81 // looking up a HidConnection.
82 class HidConnectionIoFunction
: public UIThreadExtensionFunction
{
84 HidConnectionIoFunction();
87 ~HidConnectionIoFunction() override
;
89 virtual bool ValidateParameters() = 0;
90 virtual void StartWork(device::HidConnection
* connection
) = 0;
92 void set_connection_id(int connection_id
) { connection_id_
= connection_id
; }
96 ResponseAction
Run() override
;
101 class HidReceiveFunction
: public HidConnectionIoFunction
{
103 DECLARE_EXTENSION_FUNCTION("hid.receive", HID_RECEIVE
);
105 HidReceiveFunction();
108 ~HidReceiveFunction() override
;
110 // HidConnectionIoFunction:
111 bool ValidateParameters() override
;
112 void StartWork(device::HidConnection
* connection
) override
;
114 void OnFinished(bool success
,
115 scoped_refptr
<net::IOBuffer
> buffer
,
118 scoped_ptr
<core_api::hid::Receive::Params
> parameters_
;
120 DISALLOW_COPY_AND_ASSIGN(HidReceiveFunction
);
123 class HidSendFunction
: public HidConnectionIoFunction
{
125 DECLARE_EXTENSION_FUNCTION("hid.send", HID_SEND
);
130 ~HidSendFunction() override
;
132 // HidConnectionIoFunction:
133 bool ValidateParameters() override
;
134 void StartWork(device::HidConnection
* connection
) override
;
136 void OnFinished(bool success
);
138 scoped_ptr
<core_api::hid::Send::Params
> parameters_
;
140 DISALLOW_COPY_AND_ASSIGN(HidSendFunction
);
143 class HidReceiveFeatureReportFunction
: public HidConnectionIoFunction
{
145 DECLARE_EXTENSION_FUNCTION("hid.receiveFeatureReport",
146 HID_RECEIVEFEATUREREPORT
);
148 HidReceiveFeatureReportFunction();
151 ~HidReceiveFeatureReportFunction() override
;
153 // HidConnectionIoFunction:
154 bool ValidateParameters() override
;
155 void StartWork(device::HidConnection
* connection
) override
;
157 void OnFinished(bool success
,
158 scoped_refptr
<net::IOBuffer
> buffer
,
161 scoped_ptr
<core_api::hid::ReceiveFeatureReport::Params
> parameters_
;
163 DISALLOW_COPY_AND_ASSIGN(HidReceiveFeatureReportFunction
);
166 class HidSendFeatureReportFunction
: public HidConnectionIoFunction
{
168 DECLARE_EXTENSION_FUNCTION("hid.sendFeatureReport", HID_SENDFEATUREREPORT
);
170 HidSendFeatureReportFunction();
173 ~HidSendFeatureReportFunction() override
;
175 // HidConnectionIoFunction:
176 bool ValidateParameters() override
;
177 void StartWork(device::HidConnection
* connection
) override
;
179 void OnFinished(bool success
);
181 scoped_ptr
<core_api::hid::SendFeatureReport::Params
> parameters_
;
183 DISALLOW_COPY_AND_ASSIGN(HidSendFeatureReportFunction
);
186 } // namespace extensions
188 #endif // EXTENSIONS_BROWSER_API_HID_HID_API_H_