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_SHARED_H_
6 #define PPAPI_PROXY_UDP_SOCKET_SHARED_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "ppapi/c/private/ppb_net_address_private.h"
14 #include "ppapi/c/private/ppb_udp_socket_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
;
34 UDPSocketResourceBase(Connection connection
, PP_Instance instance
);
35 virtual ~UDPSocketResourceBase();
37 int32_t SetSocketFeatureImpl(PP_UDPSocketFeature_Private name
,
39 int32_t BindImpl(const PP_NetAddress_Private
* addr
,
40 scoped_refptr
<TrackedCallback
> callback
);
41 PP_Bool
GetBoundAddressImpl(PP_NetAddress_Private
* addr
);
42 // |addr| could be NULL to indicate that an output value is not needed.
43 int32_t RecvFromImpl(char* buffer
,
46 scoped_refptr
<TrackedCallback
> callback
);
47 PP_Bool
GetRecvFromAddressImpl(PP_NetAddress_Private
* addr
);
48 int32_t SendToImpl(const char* buffer
,
50 const PP_NetAddress_Private
* addr
,
51 scoped_refptr
<TrackedCallback
> callback
);
55 void PostAbortIfNecessary(scoped_refptr
<TrackedCallback
>* callback
);
57 // IPC message handlers.
58 void OnPluginMsgBindReply(const ResourceMessageReplyParams
& params
,
59 const PP_NetAddress_Private
& bound_addr
);
60 void OnPluginMsgRecvFromReply(PP_Resource
* output_addr
,
61 const ResourceMessageReplyParams
& params
,
62 const std::string
& data
,
63 const PP_NetAddress_Private
& addr
);
64 void OnPluginMsgSendToReply(const ResourceMessageReplyParams
& params
,
65 int32_t bytes_written
);
70 scoped_refptr
<TrackedCallback
> bind_callback_
;
71 scoped_refptr
<TrackedCallback
> recvfrom_callback_
;
72 scoped_refptr
<TrackedCallback
> sendto_callback_
;
75 int32_t bytes_to_read_
;
77 PP_NetAddress_Private recvfrom_addr_
;
78 PP_NetAddress_Private bound_addr_
;
80 DISALLOW_COPY_AND_ASSIGN(UDPSocketResourceBase
);
86 #endif // PPAPI_PROXY_UDP_SOCKET_SHARED_H_