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
{
18 class UDPSocketEventDispatcher
;
20 class UDPSocketAsyncApiFunction
: public SocketAsyncApiFunction
{
22 ~UDPSocketAsyncApiFunction() override
;
24 scoped_ptr
<SocketResourceManagerInterface
> CreateSocketResourceManager()
27 ResumableUDPSocket
* GetUdpSocket(int socket_id
);
30 class UDPSocketExtensionWithDnsLookupFunction
31 : public SocketExtensionWithDnsLookupFunction
{
33 ~UDPSocketExtensionWithDnsLookupFunction() override
;
35 scoped_ptr
<SocketResourceManagerInterface
> CreateSocketResourceManager()
38 ResumableUDPSocket
* GetUdpSocket(int socket_id
);
41 class SocketsUdpCreateFunction
: public UDPSocketAsyncApiFunction
{
43 DECLARE_EXTENSION_FUNCTION("sockets.udp.create", SOCKETS_UDP_CREATE
)
45 SocketsUdpCreateFunction();
48 ~SocketsUdpCreateFunction() override
;
51 bool Prepare() override
;
55 FRIEND_TEST_ALL_PREFIXES(SocketsUdpUnitTest
, Create
);
56 scoped_ptr
<sockets_udp::Create::Params
> params_
;
59 class SocketsUdpUpdateFunction
: public UDPSocketAsyncApiFunction
{
61 DECLARE_EXTENSION_FUNCTION("sockets.udp.update", SOCKETS_UDP_UPDATE
)
63 SocketsUdpUpdateFunction();
66 ~SocketsUdpUpdateFunction() override
;
69 bool Prepare() override
;
73 scoped_ptr
<sockets_udp::Update::Params
> params_
;
76 class SocketsUdpSetPausedFunction
: public UDPSocketAsyncApiFunction
{
78 DECLARE_EXTENSION_FUNCTION("sockets.udp.setPaused", SOCKETS_UDP_SETPAUSED
)
80 SocketsUdpSetPausedFunction();
83 ~SocketsUdpSetPausedFunction() override
;
86 bool Prepare() override
;
90 scoped_ptr
<sockets_udp::SetPaused::Params
> params_
;
91 UDPSocketEventDispatcher
* socket_event_dispatcher_
;
94 class SocketsUdpBindFunction
: public UDPSocketAsyncApiFunction
{
96 DECLARE_EXTENSION_FUNCTION("sockets.udp.bind", SOCKETS_UDP_BIND
)
98 SocketsUdpBindFunction();
101 ~SocketsUdpBindFunction() override
;
104 bool Prepare() override
;
105 void AsyncWorkStart() override
;
108 scoped_ptr
<sockets_udp::Bind::Params
> params_
;
109 UDPSocketEventDispatcher
* socket_event_dispatcher_
;
112 class SocketsUdpSendFunction
: public UDPSocketExtensionWithDnsLookupFunction
{
114 DECLARE_EXTENSION_FUNCTION("sockets.udp.send", SOCKETS_UDP_SEND
)
116 SocketsUdpSendFunction();
119 ~SocketsUdpSendFunction() override
;
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
;
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
{
140 DECLARE_EXTENSION_FUNCTION("sockets.udp.close", SOCKETS_UDP_CLOSE
)
142 SocketsUdpCloseFunction();
145 ~SocketsUdpCloseFunction() override
;
148 bool Prepare() override
;
149 void Work() override
;
152 scoped_ptr
<sockets_udp::Close::Params
> params_
;
155 class SocketsUdpGetInfoFunction
: public UDPSocketAsyncApiFunction
{
157 DECLARE_EXTENSION_FUNCTION("sockets.udp.getInfo", SOCKETS_UDP_GETINFO
)
159 SocketsUdpGetInfoFunction();
162 ~SocketsUdpGetInfoFunction() override
;
165 bool Prepare() override
;
166 void Work() override
;
169 scoped_ptr
<sockets_udp::GetInfo::Params
> params_
;
172 class SocketsUdpGetSocketsFunction
: public UDPSocketAsyncApiFunction
{
174 DECLARE_EXTENSION_FUNCTION("sockets.udp.getSockets", SOCKETS_UDP_GETSOCKETS
)
176 SocketsUdpGetSocketsFunction();
179 ~SocketsUdpGetSocketsFunction() override
;
182 bool Prepare() override
;
183 void Work() override
;
186 class SocketsUdpJoinGroupFunction
: public UDPSocketAsyncApiFunction
{
188 DECLARE_EXTENSION_FUNCTION("sockets.udp.joinGroup", SOCKETS_UDP_JOINGROUP
)
190 SocketsUdpJoinGroupFunction();
193 ~SocketsUdpJoinGroupFunction() override
;
196 bool Prepare() override
;
197 void Work() override
;
200 scoped_ptr
<sockets_udp::JoinGroup::Params
> params_
;
203 class SocketsUdpLeaveGroupFunction
: public UDPSocketAsyncApiFunction
{
205 DECLARE_EXTENSION_FUNCTION("sockets.udp.leaveGroup", SOCKETS_UDP_LEAVEGROUP
)
207 SocketsUdpLeaveGroupFunction();
210 ~SocketsUdpLeaveGroupFunction() override
;
213 bool Prepare() override
;
214 void Work() override
;
217 scoped_ptr
<sockets_udp::LeaveGroup::Params
> params_
;
220 class SocketsUdpSetMulticastTimeToLiveFunction
221 : public UDPSocketAsyncApiFunction
{
223 DECLARE_EXTENSION_FUNCTION("sockets.udp.setMulticastTimeToLive",
224 SOCKETS_UDP_SETMULTICASTTIMETOLIVE
)
226 SocketsUdpSetMulticastTimeToLiveFunction();
229 ~SocketsUdpSetMulticastTimeToLiveFunction() override
;
232 bool Prepare() override
;
233 void Work() override
;
236 scoped_ptr
<sockets_udp::SetMulticastTimeToLive::Params
> params_
;
239 class SocketsUdpSetMulticastLoopbackModeFunction
240 : public UDPSocketAsyncApiFunction
{
242 DECLARE_EXTENSION_FUNCTION("sockets.udp.setMulticastLoopbackMode",
243 SOCKETS_UDP_SETMULTICASTLOOPBACKMODE
)
245 SocketsUdpSetMulticastLoopbackModeFunction();
248 ~SocketsUdpSetMulticastLoopbackModeFunction() override
;
251 bool Prepare() override
;
252 void Work() override
;
255 scoped_ptr
<sockets_udp::SetMulticastLoopbackMode::Params
> params_
;
258 class SocketsUdpGetJoinedGroupsFunction
: public UDPSocketAsyncApiFunction
{
260 DECLARE_EXTENSION_FUNCTION("sockets.udp.getJoinedGroups",
261 SOCKETS_UDP_GETJOINEDGROUPS
)
263 SocketsUdpGetJoinedGroupsFunction();
266 ~SocketsUdpGetJoinedGroupsFunction() override
;
269 bool Prepare() override
;
270 void Work() override
;
273 scoped_ptr
<sockets_udp::GetJoinedGroups::Params
> params_
;
276 class SocketsUdpSetBroadcastFunction
: public UDPSocketAsyncApiFunction
{
278 DECLARE_EXTENSION_FUNCTION("sockets.udp.setBroadcast",
279 SOCKETS_UDP_SETBROADCAST
)
281 SocketsUdpSetBroadcastFunction();
284 ~SocketsUdpSetBroadcastFunction() override
;
287 bool Prepare() override
;
288 void Work() override
;
291 scoped_ptr
<sockets_udp::SetBroadcast::Params
> params_
;
295 } // namespace extensions
297 #endif // EXTENSIONS_BROWSER_API_SOCKETS_UDP_SOCKETS_UDP_API_H_