Reland the ULONG -> SIZE_T change from 317177
[chromium-blink-merge.git] / extensions / browser / api / hid / hid_api.h
blobafa1cfa12386093c1ab10763e29877f04e4a9f09
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 HidService;
21 } // namespace device
23 namespace net {
24 class IOBuffer;
25 } // namespace net
27 namespace extensions {
29 class HidGetDevicesFunction : public UIThreadExtensionFunction {
30 public:
31 DECLARE_EXTENSION_FUNCTION("hid.getDevices", HID_GETDEVICES);
33 HidGetDevicesFunction();
35 private:
36 ~HidGetDevicesFunction() override;
38 // ExtensionFunction:
39 ResponseAction Run() override;
41 void OnEnumerationComplete(scoped_ptr<base::ListValue> devices);
43 DISALLOW_COPY_AND_ASSIGN(HidGetDevicesFunction);
46 class HidConnectFunction : public UIThreadExtensionFunction {
47 public:
48 DECLARE_EXTENSION_FUNCTION("hid.connect", HID_CONNECT);
50 HidConnectFunction();
52 private:
53 ~HidConnectFunction() override;
55 // ExtensionFunction:
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 {
66 public:
67 DECLARE_EXTENSION_FUNCTION("hid.disconnect", HID_DISCONNECT);
69 HidDisconnectFunction();
71 private:
72 ~HidDisconnectFunction() override;
74 // ExtensionFunction:
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 {
83 public:
84 HidConnectionIoFunction();
86 protected:
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; }
94 private:
95 // ExtensionFunction:
96 ResponseAction Run() override;
98 int connection_id_;
101 class HidReceiveFunction : public HidConnectionIoFunction {
102 public:
103 DECLARE_EXTENSION_FUNCTION("hid.receive", HID_RECEIVE);
105 HidReceiveFunction();
107 private:
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,
116 size_t size);
118 scoped_ptr<core_api::hid::Receive::Params> parameters_;
120 DISALLOW_COPY_AND_ASSIGN(HidReceiveFunction);
123 class HidSendFunction : public HidConnectionIoFunction {
124 public:
125 DECLARE_EXTENSION_FUNCTION("hid.send", HID_SEND);
127 HidSendFunction();
129 private:
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 {
144 public:
145 DECLARE_EXTENSION_FUNCTION("hid.receiveFeatureReport",
146 HID_RECEIVEFEATUREREPORT);
148 HidReceiveFeatureReportFunction();
150 private:
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,
159 size_t size);
161 scoped_ptr<core_api::hid::ReceiveFeatureReport::Params> parameters_;
163 DISALLOW_COPY_AND_ASSIGN(HidReceiveFeatureReportFunction);
166 class HidSendFeatureReportFunction : public HidConnectionIoFunction {
167 public:
168 DECLARE_EXTENSION_FUNCTION("hid.sendFeatureReport", HID_SENDFEATUREREPORT);
170 HidSendFeatureReportFunction();
172 private:
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_