Enable Enterprise enrollment on desktop builds.
[chromium-blink-merge.git] / chrome / browser / extensions / api / serial / serial_api.h
blobe384eb6ad901d4cdca492c27b3f586b95317615a
1 // Copyright 2012 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 CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_API_H_
8 #include <string>
10 #include "base/memory/ref_counted.h"
11 #include "chrome/common/extensions/api/serial.h"
12 #include "extensions/browser/api/api_resource_manager.h"
13 #include "extensions/browser/api/async_api_function.h"
15 namespace extensions {
17 class SerialConnection;
19 namespace api {
21 class SerialEventDispatcher;
23 class SerialAsyncApiFunction : public AsyncApiFunction {
24 public:
25 SerialAsyncApiFunction();
27 protected:
28 virtual ~SerialAsyncApiFunction();
30 // AsyncApiFunction:
31 virtual bool PrePrepare() OVERRIDE;
32 virtual bool Respond() OVERRIDE;
34 SerialConnection* GetSerialConnection(int api_resource_id);
35 void RemoveSerialConnection(int api_resource_id);
37 ApiResourceManager<SerialConnection>* manager_;
40 class SerialGetDevicesFunction : public SerialAsyncApiFunction {
41 public:
42 DECLARE_EXTENSION_FUNCTION("serial.getDevices", SERIAL_GETDEVICES)
44 SerialGetDevicesFunction();
46 protected:
47 virtual ~SerialGetDevicesFunction() {}
49 // AsyncApiFunction:
50 virtual bool Prepare() OVERRIDE;
51 virtual void Work() OVERRIDE;
54 class SerialConnectFunction : public SerialAsyncApiFunction {
55 public:
56 DECLARE_EXTENSION_FUNCTION("serial.connect", SERIAL_CONNECT)
58 SerialConnectFunction();
60 protected:
61 virtual ~SerialConnectFunction();
63 // AsyncApiFunction:
64 virtual bool Prepare() OVERRIDE;
65 virtual void AsyncWorkStart() OVERRIDE;
67 virtual SerialConnection* CreateSerialConnection(
68 const std::string& port,
69 const std::string& extension_id) const;
71 private:
72 void OnConnected(bool success);
73 void FinishConnect();
75 scoped_ptr<serial::Connect::Params> params_;
77 // SerialEventDispatcher is owned by a BrowserContext.
78 SerialEventDispatcher* serial_event_dispatcher_;
80 // This connection is created within SerialConnectFunction.
81 // From there it is either destroyed in OnConnected (upon failure)
82 // or its ownership is transferred to the
83 // ApiResourceManager<SerialConnection>.
84 SerialConnection* connection_;
87 class SerialUpdateFunction : public SerialAsyncApiFunction {
88 public:
89 DECLARE_EXTENSION_FUNCTION("serial.update", SERIAL_UPDATE);
91 SerialUpdateFunction();
93 protected:
94 virtual ~SerialUpdateFunction();
96 // AsyncApiFunction:
97 virtual bool Prepare() OVERRIDE;
98 virtual void Work() OVERRIDE;
100 private:
101 scoped_ptr<serial::Update::Params> params_;
104 class SerialDisconnectFunction : public SerialAsyncApiFunction {
105 public:
106 DECLARE_EXTENSION_FUNCTION("serial.disconnect", SERIAL_DISCONNECT)
108 SerialDisconnectFunction();
110 protected:
111 virtual ~SerialDisconnectFunction();
113 // AsyncApiFunction:
114 virtual bool Prepare() OVERRIDE;
115 virtual void Work() OVERRIDE;
117 private:
118 scoped_ptr<serial::Disconnect::Params> params_;
121 class SerialSetPausedFunction : public SerialAsyncApiFunction {
122 public:
123 DECLARE_EXTENSION_FUNCTION("serial.setPaused", SERIAL_SETPAUSED)
125 SerialSetPausedFunction();
127 protected:
128 virtual ~SerialSetPausedFunction();
130 // AsyncApiFunction:
131 virtual bool Prepare() OVERRIDE;
132 virtual void Work() OVERRIDE;
134 private:
135 scoped_ptr<serial::SetPaused::Params> params_;
136 SerialEventDispatcher* serial_event_dispatcher_;
139 class SerialGetInfoFunction : public SerialAsyncApiFunction {
140 public:
141 DECLARE_EXTENSION_FUNCTION("serial.getInfo", SERIAL_GETINFO)
143 SerialGetInfoFunction();
145 protected:
146 virtual ~SerialGetInfoFunction();
148 // AsyncApiFunction:
149 virtual bool Prepare() OVERRIDE;
150 virtual void Work() OVERRIDE;
152 private:
153 scoped_ptr<serial::GetInfo::Params> params_;
156 class SerialGetConnectionsFunction : public SerialAsyncApiFunction {
157 public:
158 DECLARE_EXTENSION_FUNCTION("serial.getConnections", SERIAL_GETCONNECTIONS);
160 SerialGetConnectionsFunction();
162 protected:
163 virtual ~SerialGetConnectionsFunction();
165 // AsyncApiFunction:
166 virtual bool Prepare() OVERRIDE;
167 virtual void Work() OVERRIDE;
170 class SerialSendFunction : public SerialAsyncApiFunction {
171 public:
172 DECLARE_EXTENSION_FUNCTION("serial.send", SERIAL_SEND)
174 SerialSendFunction();
176 protected:
177 virtual ~SerialSendFunction();
179 // AsyncApiFunction:
180 virtual bool Prepare() OVERRIDE;
181 virtual void AsyncWorkStart() OVERRIDE;
183 private:
184 void OnSendComplete(int bytes_sent, serial::SendError error);
186 scoped_ptr<serial::Send::Params> params_;
189 class SerialFlushFunction : public SerialAsyncApiFunction {
190 public:
191 DECLARE_EXTENSION_FUNCTION("serial.flush", SERIAL_FLUSH)
193 SerialFlushFunction();
195 protected:
196 virtual ~SerialFlushFunction();
198 // AsyncApiFunction:
199 virtual bool Prepare() OVERRIDE;
200 virtual void Work() OVERRIDE;
202 private:
203 scoped_ptr<serial::Flush::Params> params_;
206 class SerialGetControlSignalsFunction : public SerialAsyncApiFunction {
207 public:
208 DECLARE_EXTENSION_FUNCTION("serial.getControlSignals",
209 SERIAL_GETCONTROLSIGNALS)
211 SerialGetControlSignalsFunction();
213 protected:
214 virtual ~SerialGetControlSignalsFunction();
216 // AsyncApiFunction:
217 virtual bool Prepare() OVERRIDE;
218 virtual void Work() OVERRIDE;
220 private:
221 scoped_ptr<serial::GetControlSignals::Params> params_;
224 class SerialSetControlSignalsFunction : public SerialAsyncApiFunction {
225 public:
226 DECLARE_EXTENSION_FUNCTION("serial.setControlSignals",
227 SERIAL_SETCONTROLSIGNALS)
229 SerialSetControlSignalsFunction();
231 protected:
232 virtual ~SerialSetControlSignalsFunction();
234 // AsyncApiFunction:
235 virtual bool Prepare() OVERRIDE;
236 virtual void Work() OVERRIDE;
238 private:
239 scoped_ptr<serial::SetControlSignals::Params> params_;
242 } // namespace api
244 } // namespace extensions
246 #endif // CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_API_H_