Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / extensions / browser / api / sockets_udp / sockets_udp_api.h
bloba43f6dc0cda27f41da3c0190b9bb6f9556f13caf
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_SOCKETS_UDP_SOCKETS_UDP_API_H_
6 #define EXTENSIONS_BROWSER_API_SOCKETS_UDP_SOCKETS_UDP_API_H_
8 #include "extensions/browser/api/socket/socket_api.h"
9 #include "extensions/common/api/sockets_udp.h"
11 namespace extensions {
12 class ResumableUDPSocket;
15 namespace extensions {
16 namespace api {
18 class UDPSocketEventDispatcher;
20 class UDPSocketAsyncApiFunction : public SocketAsyncApiFunction {
21 protected:
22 ~UDPSocketAsyncApiFunction() override;
24 scoped_ptr<SocketResourceManagerInterface> CreateSocketResourceManager()
25 override;
27 ResumableUDPSocket* GetUdpSocket(int socket_id);
30 class UDPSocketExtensionWithDnsLookupFunction
31 : public SocketExtensionWithDnsLookupFunction {
32 protected:
33 ~UDPSocketExtensionWithDnsLookupFunction() override;
35 scoped_ptr<SocketResourceManagerInterface> CreateSocketResourceManager()
36 override;
38 ResumableUDPSocket* GetUdpSocket(int socket_id);
41 class SocketsUdpCreateFunction : public UDPSocketAsyncApiFunction {
42 public:
43 DECLARE_EXTENSION_FUNCTION("sockets.udp.create", SOCKETS_UDP_CREATE)
45 SocketsUdpCreateFunction();
47 protected:
48 ~SocketsUdpCreateFunction() override;
50 // AsyncApiFunction:
51 bool Prepare() override;
52 void Work() override;
54 private:
55 FRIEND_TEST_ALL_PREFIXES(SocketsUdpUnitTest, Create);
56 scoped_ptr<sockets_udp::Create::Params> params_;
59 class SocketsUdpUpdateFunction : public UDPSocketAsyncApiFunction {
60 public:
61 DECLARE_EXTENSION_FUNCTION("sockets.udp.update", SOCKETS_UDP_UPDATE)
63 SocketsUdpUpdateFunction();
65 protected:
66 ~SocketsUdpUpdateFunction() override;
68 // AsyncApiFunction:
69 bool Prepare() override;
70 void Work() override;
72 private:
73 scoped_ptr<sockets_udp::Update::Params> params_;
76 class SocketsUdpSetPausedFunction : public UDPSocketAsyncApiFunction {
77 public:
78 DECLARE_EXTENSION_FUNCTION("sockets.udp.setPaused", SOCKETS_UDP_SETPAUSED)
80 SocketsUdpSetPausedFunction();
82 protected:
83 ~SocketsUdpSetPausedFunction() override;
85 // AsyncApiFunction
86 bool Prepare() override;
87 void Work() override;
89 private:
90 scoped_ptr<sockets_udp::SetPaused::Params> params_;
91 UDPSocketEventDispatcher* socket_event_dispatcher_;
94 class SocketsUdpBindFunction : public UDPSocketAsyncApiFunction {
95 public:
96 DECLARE_EXTENSION_FUNCTION("sockets.udp.bind", SOCKETS_UDP_BIND)
98 SocketsUdpBindFunction();
100 protected:
101 ~SocketsUdpBindFunction() override;
103 // AsyncApiFunction:
104 bool Prepare() override;
105 void AsyncWorkStart() override;
107 private:
108 scoped_ptr<sockets_udp::Bind::Params> params_;
109 UDPSocketEventDispatcher* socket_event_dispatcher_;
112 class SocketsUdpSendFunction : public UDPSocketExtensionWithDnsLookupFunction {
113 public:
114 DECLARE_EXTENSION_FUNCTION("sockets.udp.send", SOCKETS_UDP_SEND)
116 SocketsUdpSendFunction();
118 protected:
119 ~SocketsUdpSendFunction() override;
121 // AsyncApiFunction:
122 bool Prepare() override;
123 void AsyncWorkStart() override;
124 void OnCompleted(int net_result);
125 void SetSendResult(int net_result, int bytes_sent);
127 // SocketExtensionWithDnsLookupFunction:
128 void AfterDnsLookup(int lookup_result) override;
130 private:
131 void StartSendTo();
133 scoped_ptr<sockets_udp::Send::Params> params_;
134 scoped_refptr<net::IOBuffer> io_buffer_;
135 size_t io_buffer_size_;
138 class SocketsUdpCloseFunction : public UDPSocketAsyncApiFunction {
139 public:
140 DECLARE_EXTENSION_FUNCTION("sockets.udp.close", SOCKETS_UDP_CLOSE)
142 SocketsUdpCloseFunction();
144 protected:
145 ~SocketsUdpCloseFunction() override;
147 // AsyncApiFunction:
148 bool Prepare() override;
149 void Work() override;
151 private:
152 scoped_ptr<sockets_udp::Close::Params> params_;
155 class SocketsUdpGetInfoFunction : public UDPSocketAsyncApiFunction {
156 public:
157 DECLARE_EXTENSION_FUNCTION("sockets.udp.getInfo", SOCKETS_UDP_GETINFO)
159 SocketsUdpGetInfoFunction();
161 protected:
162 ~SocketsUdpGetInfoFunction() override;
164 // AsyncApiFunction:
165 bool Prepare() override;
166 void Work() override;
168 private:
169 scoped_ptr<sockets_udp::GetInfo::Params> params_;
172 class SocketsUdpGetSocketsFunction : public UDPSocketAsyncApiFunction {
173 public:
174 DECLARE_EXTENSION_FUNCTION("sockets.udp.getSockets", SOCKETS_UDP_GETSOCKETS)
176 SocketsUdpGetSocketsFunction();
178 protected:
179 ~SocketsUdpGetSocketsFunction() override;
181 // AsyncApiFunction:
182 bool Prepare() override;
183 void Work() override;
186 class SocketsUdpJoinGroupFunction : public UDPSocketAsyncApiFunction {
187 public:
188 DECLARE_EXTENSION_FUNCTION("sockets.udp.joinGroup", SOCKETS_UDP_JOINGROUP)
190 SocketsUdpJoinGroupFunction();
192 protected:
193 ~SocketsUdpJoinGroupFunction() override;
195 // AsyncApiFunction
196 bool Prepare() override;
197 void Work() override;
199 private:
200 scoped_ptr<sockets_udp::JoinGroup::Params> params_;
203 class SocketsUdpLeaveGroupFunction : public UDPSocketAsyncApiFunction {
204 public:
205 DECLARE_EXTENSION_FUNCTION("sockets.udp.leaveGroup", SOCKETS_UDP_LEAVEGROUP)
207 SocketsUdpLeaveGroupFunction();
209 protected:
210 ~SocketsUdpLeaveGroupFunction() override;
212 // AsyncApiFunction
213 bool Prepare() override;
214 void Work() override;
216 private:
217 scoped_ptr<sockets_udp::LeaveGroup::Params> params_;
220 class SocketsUdpSetMulticastTimeToLiveFunction
221 : public UDPSocketAsyncApiFunction {
222 public:
223 DECLARE_EXTENSION_FUNCTION("sockets.udp.setMulticastTimeToLive",
224 SOCKETS_UDP_SETMULTICASTTIMETOLIVE)
226 SocketsUdpSetMulticastTimeToLiveFunction();
228 protected:
229 ~SocketsUdpSetMulticastTimeToLiveFunction() override;
231 // AsyncApiFunction
232 bool Prepare() override;
233 void Work() override;
235 private:
236 scoped_ptr<sockets_udp::SetMulticastTimeToLive::Params> params_;
239 class SocketsUdpSetMulticastLoopbackModeFunction
240 : public UDPSocketAsyncApiFunction {
241 public:
242 DECLARE_EXTENSION_FUNCTION("sockets.udp.setMulticastLoopbackMode",
243 SOCKETS_UDP_SETMULTICASTLOOPBACKMODE)
245 SocketsUdpSetMulticastLoopbackModeFunction();
247 protected:
248 ~SocketsUdpSetMulticastLoopbackModeFunction() override;
250 // AsyncApiFunction
251 bool Prepare() override;
252 void Work() override;
254 private:
255 scoped_ptr<sockets_udp::SetMulticastLoopbackMode::Params> params_;
258 class SocketsUdpGetJoinedGroupsFunction : public UDPSocketAsyncApiFunction {
259 public:
260 DECLARE_EXTENSION_FUNCTION("sockets.udp.getJoinedGroups",
261 SOCKETS_UDP_GETJOINEDGROUPS)
263 SocketsUdpGetJoinedGroupsFunction();
265 protected:
266 ~SocketsUdpGetJoinedGroupsFunction() override;
268 // AsyncApiFunction
269 bool Prepare() override;
270 void Work() override;
272 private:
273 scoped_ptr<sockets_udp::GetJoinedGroups::Params> params_;
276 class SocketsUdpSetBroadcastFunction : public UDPSocketAsyncApiFunction {
277 public:
278 DECLARE_EXTENSION_FUNCTION("sockets.udp.setBroadcast",
279 SOCKETS_UDP_SETBROADCAST)
281 SocketsUdpSetBroadcastFunction();
283 protected:
284 ~SocketsUdpSetBroadcastFunction() override;
286 // AsyncApiFunction
287 bool Prepare() override;
288 void Work() override;
290 private:
291 scoped_ptr<sockets_udp::SetBroadcast::Params> params_;
294 } // namespace api
295 } // namespace extensions
297 #endif // EXTENSIONS_BROWSER_API_SOCKETS_UDP_SOCKETS_UDP_API_H_