Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / extensions / browser / api / hid / hid_api.h
blobe93d4d84279ba0239ddbf6ee995b5f2adee12bb6
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/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"
18 namespace device {
19 class HidConnection;
20 class HidDeviceInfo;
21 class HidService;
22 } // namespace device
24 namespace net {
25 class IOBuffer;
26 } // namespace net
28 namespace extensions {
30 class DevicePermissionsPrompt;
32 class HidGetDevicesFunction : public UIThreadExtensionFunction {
33 public:
34 DECLARE_EXTENSION_FUNCTION("hid.getDevices", HID_GETDEVICES);
36 HidGetDevicesFunction();
38 private:
39 ~HidGetDevicesFunction() override;
41 // ExtensionFunction:
42 ResponseAction Run() override;
44 void OnEnumerationComplete(scoped_ptr<base::ListValue> devices);
46 DISALLOW_COPY_AND_ASSIGN(HidGetDevicesFunction);
49 class HidGetUserSelectedDevicesFunction : public UIThreadExtensionFunction {
50 public:
51 DECLARE_EXTENSION_FUNCTION("hid.getUserSelectedDevices",
52 HID_GETUSERSELECTEDDEVICES)
54 HidGetUserSelectedDevicesFunction();
56 private:
57 ~HidGetUserSelectedDevicesFunction() override;
59 // ExtensionFunction:
60 ResponseAction Run() override;
62 void OnDevicesChosen(
63 const std::vector<scoped_refptr<device::HidDeviceInfo>>& devices);
65 HidDeviceManager* device_manager_;
66 scoped_ptr<DevicePermissionsPrompt> prompt_;
68 DISALLOW_COPY_AND_ASSIGN(HidGetUserSelectedDevicesFunction);
71 class HidConnectFunction : public UIThreadExtensionFunction {
72 public:
73 DECLARE_EXTENSION_FUNCTION("hid.connect", HID_CONNECT);
75 HidConnectFunction();
77 private:
78 ~HidConnectFunction() override;
80 // ExtensionFunction:
81 ResponseAction Run() override;
83 void OnConnectComplete(scoped_refptr<device::HidConnection> connection);
85 ApiResourceManager<HidConnectionResource>* connection_manager_;
87 DISALLOW_COPY_AND_ASSIGN(HidConnectFunction);
90 class HidDisconnectFunction : public UIThreadExtensionFunction {
91 public:
92 DECLARE_EXTENSION_FUNCTION("hid.disconnect", HID_DISCONNECT);
94 HidDisconnectFunction();
96 private:
97 ~HidDisconnectFunction() override;
99 // ExtensionFunction:
100 ResponseAction Run() override;
102 DISALLOW_COPY_AND_ASSIGN(HidDisconnectFunction);
105 // Base class for extension functions that start some asynchronous work after
106 // looking up a HidConnection.
107 class HidConnectionIoFunction : public UIThreadExtensionFunction {
108 public:
109 HidConnectionIoFunction();
111 protected:
112 ~HidConnectionIoFunction() override;
114 virtual bool ValidateParameters() = 0;
115 virtual void StartWork(device::HidConnection* connection) = 0;
117 void set_connection_id(int connection_id) { connection_id_ = connection_id; }
119 private:
120 // ExtensionFunction:
121 ResponseAction Run() override;
123 int connection_id_;
126 class HidReceiveFunction : public HidConnectionIoFunction {
127 public:
128 DECLARE_EXTENSION_FUNCTION("hid.receive", HID_RECEIVE);
130 HidReceiveFunction();
132 private:
133 ~HidReceiveFunction() override;
135 // HidConnectionIoFunction:
136 bool ValidateParameters() override;
137 void StartWork(device::HidConnection* connection) override;
139 void OnFinished(bool success,
140 scoped_refptr<net::IOBuffer> buffer,
141 size_t size);
143 scoped_ptr<api::hid::Receive::Params> parameters_;
145 DISALLOW_COPY_AND_ASSIGN(HidReceiveFunction);
148 class HidSendFunction : public HidConnectionIoFunction {
149 public:
150 DECLARE_EXTENSION_FUNCTION("hid.send", HID_SEND);
152 HidSendFunction();
154 private:
155 ~HidSendFunction() override;
157 // HidConnectionIoFunction:
158 bool ValidateParameters() override;
159 void StartWork(device::HidConnection* connection) override;
161 void OnFinished(bool success);
163 scoped_ptr<api::hid::Send::Params> parameters_;
165 DISALLOW_COPY_AND_ASSIGN(HidSendFunction);
168 class HidReceiveFeatureReportFunction : public HidConnectionIoFunction {
169 public:
170 DECLARE_EXTENSION_FUNCTION("hid.receiveFeatureReport",
171 HID_RECEIVEFEATUREREPORT);
173 HidReceiveFeatureReportFunction();
175 private:
176 ~HidReceiveFeatureReportFunction() override;
178 // HidConnectionIoFunction:
179 bool ValidateParameters() override;
180 void StartWork(device::HidConnection* connection) override;
182 void OnFinished(bool success,
183 scoped_refptr<net::IOBuffer> buffer,
184 size_t size);
186 scoped_ptr<api::hid::ReceiveFeatureReport::Params> parameters_;
188 DISALLOW_COPY_AND_ASSIGN(HidReceiveFeatureReportFunction);
191 class HidSendFeatureReportFunction : public HidConnectionIoFunction {
192 public:
193 DECLARE_EXTENSION_FUNCTION("hid.sendFeatureReport", HID_SENDFEATUREREPORT);
195 HidSendFeatureReportFunction();
197 private:
198 ~HidSendFeatureReportFunction() override;
200 // HidConnectionIoFunction:
201 bool ValidateParameters() override;
202 void StartWork(device::HidConnection* connection) override;
204 void OnFinished(bool success);
206 scoped_ptr<api::hid::SendFeatureReport::Params> parameters_;
208 DISALLOW_COPY_AND_ASSIGN(HidSendFeatureReportFunction);
211 } // namespace extensions
213 #endif // EXTENSIONS_BROWSER_API_HID_HID_API_H_