1 // Copyright 2013 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 PPAPI_PROXY_UDP_SOCKET_RESOURCE_BASE_H_
6 #define PPAPI_PROXY_UDP_SOCKET_RESOURCE_BASE_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "ppapi/c/ppb_udp_socket.h"
14 #include "ppapi/c/private/ppb_net_address_private.h"
15 #include "ppapi/proxy/plugin_resource.h"
16 #include "ppapi/proxy/ppapi_proxy_export.h"
17 #include "ppapi/shared_impl/tracked_callback.h"
22 class ResourceMessageReplyParams
;
24 class PPAPI_PROXY_EXPORT UDPSocketResourceBase
: public PluginResource
{
26 // The maximum number of bytes that each PpapiHostMsg_PPBUDPSocket_RecvFrom
27 // message is allowed to request.
28 static const int32_t kMaxReadSize
;
29 // The maximum number of bytes that each PpapiHostMsg_PPBUDPSocket_SendTo
30 // message is allowed to carry.
31 static const int32_t kMaxWriteSize
;
33 // The maximum number that we allow for setting
34 // PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE. This number is only for input
35 // argument sanity check, it doesn't mean the browser guarantees to support
36 // such a buffer size.
37 static const int32_t kMaxSendBufferSize
;
38 // The maximum number that we allow for setting
39 // PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE. This number is only for input
40 // argument sanity check, it doesn't mean the browser guarantees to support
41 // such a buffer size.
42 static const int32_t kMaxReceiveBufferSize
;
45 UDPSocketResourceBase(Connection connection
,
48 virtual ~UDPSocketResourceBase();
50 int32_t SetOptionImpl(PP_UDPSocket_Option name
,
52 scoped_refptr
<TrackedCallback
> callback
);
53 int32_t BindImpl(const PP_NetAddress_Private
* addr
,
54 scoped_refptr
<TrackedCallback
> callback
);
55 PP_Bool
GetBoundAddressImpl(PP_NetAddress_Private
* addr
);
56 // |addr| could be NULL to indicate that an output value is not needed.
57 int32_t RecvFromImpl(char* buffer
,
60 scoped_refptr
<TrackedCallback
> callback
);
61 PP_Bool
GetRecvFromAddressImpl(PP_NetAddress_Private
* addr
);
62 int32_t SendToImpl(const char* buffer
,
64 const PP_NetAddress_Private
* addr
,
65 scoped_refptr
<TrackedCallback
> callback
);
69 void PostAbortIfNecessary(scoped_refptr
<TrackedCallback
>* callback
);
71 // IPC message handlers.
72 void OnPluginMsgSetOptionReply(scoped_refptr
<TrackedCallback
> callback
,
73 const ResourceMessageReplyParams
& params
);
74 void OnPluginMsgBindReply(const ResourceMessageReplyParams
& params
,
75 const PP_NetAddress_Private
& bound_addr
);
76 void OnPluginMsgRecvFromReply(PP_Resource
* output_addr
,
77 const ResourceMessageReplyParams
& params
,
78 const std::string
& data
,
79 const PP_NetAddress_Private
& addr
);
80 void OnPluginMsgSendToReply(const ResourceMessageReplyParams
& params
,
81 int32_t bytes_written
);
83 void RunCallback(scoped_refptr
<TrackedCallback
> callback
, int32_t pp_result
);
89 scoped_refptr
<TrackedCallback
> bind_callback_
;
90 scoped_refptr
<TrackedCallback
> recvfrom_callback_
;
91 scoped_refptr
<TrackedCallback
> sendto_callback_
;
94 int32_t bytes_to_read_
;
96 PP_NetAddress_Private recvfrom_addr_
;
97 PP_NetAddress_Private bound_addr_
;
99 DISALLOW_COPY_AND_ASSIGN(UDPSocketResourceBase
);
105 #endif // PPAPI_PROXY_UDP_SOCKET_RESOURCE_BASE_H_