Delete unused downloads page asset.
[chromium-blink-merge.git] / ppapi / proxy / udp_socket_resource_base.h
blobe5a8aef805f4f1f2415364aa1e7a295fc2010dbc
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_
8 #include <queue>
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/proxy/udp_socket_filter.h"
18 #include "ppapi/shared_impl/tracked_callback.h"
20 namespace ppapi {
21 namespace proxy {
23 class ResourceMessageReplyParams;
25 class PPAPI_PROXY_EXPORT UDPSocketResourceBase : public PluginResource {
26 public:
27 // The maximum number of bytes that each
28 // PpapiPluginMsg_PPBUDPSocket_PushRecvResult message is allowed to carry.
29 static const int32_t kMaxReadSize;
30 // The maximum number of bytes that each PpapiHostMsg_PPBUDPSocket_SendTo
31 // message is allowed to carry.
32 static const int32_t kMaxWriteSize;
34 // The maximum number that we allow for setting
35 // PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE. This number is only for input
36 // argument sanity check, it doesn't mean the browser guarantees to support
37 // such a buffer size.
38 static const int32_t kMaxSendBufferSize;
39 // The maximum number that we allow for setting
40 // PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE. This number is only for input
41 // argument sanity check, it doesn't mean the browser guarantees to support
42 // such a buffer size.
43 static const int32_t kMaxReceiveBufferSize;
45 // The maximum number of received packets that we allow instances of this
46 // class to buffer.
47 static const size_t kPluginReceiveBufferSlots;
48 // The maximum number of buffers that we allow instances of this class to be
49 // sending before we block the plugin.
50 static const size_t kPluginSendBufferSlots;
52 protected:
53 UDPSocketResourceBase(Connection connection,
54 PP_Instance instance,
55 bool private_api);
56 virtual ~UDPSocketResourceBase();
58 int32_t SetOptionImpl(PP_UDPSocket_Option name,
59 const PP_Var& value,
60 bool check_bind_state,
61 scoped_refptr<TrackedCallback> callback);
62 int32_t BindImpl(const PP_NetAddress_Private* addr,
63 scoped_refptr<TrackedCallback> callback);
64 PP_Bool GetBoundAddressImpl(PP_NetAddress_Private* addr);
65 // |addr| could be NULL to indicate that an output value is not needed.
66 int32_t RecvFromImpl(char* buffer,
67 int32_t num_bytes,
68 PP_Resource* addr,
69 scoped_refptr<TrackedCallback> callback);
70 PP_Bool GetRecvFromAddressImpl(PP_NetAddress_Private* addr);
71 int32_t SendToImpl(const char* buffer,
72 int32_t num_bytes,
73 const PP_NetAddress_Private* addr,
74 scoped_refptr<TrackedCallback> callback);
75 void CloseImpl();
76 int32_t JoinGroupImpl(const PP_NetAddress_Private *group,
77 scoped_refptr<TrackedCallback> callback);
78 int32_t LeaveGroupImpl(const PP_NetAddress_Private *group,
79 scoped_refptr<TrackedCallback> callback);
81 private:
82 // IPC message handlers.
83 void OnPluginMsgGeneralReply(scoped_refptr<TrackedCallback> callback,
84 const ResourceMessageReplyParams& params);
85 void OnPluginMsgBindReply(const ResourceMessageReplyParams& params,
86 const PP_NetAddress_Private& bound_addr);
87 void OnPluginMsgSendToReply(const ResourceMessageReplyParams& params,
88 int32_t bytes_written);
90 static void SlotBecameAvailable(PP_Resource resource);
91 static void SlotBecameAvailableWithLock(PP_Resource resource);
93 bool private_api_;
95 // |bind_called_| is true after Bind() is called, while |bound_| is true
96 // after Bind() succeeds. Bind() is an asynchronous method, so the timing
97 // on which of these is set is slightly different.
98 bool bind_called_;
99 bool bound_;
100 bool closed_;
102 scoped_refptr<TrackedCallback> bind_callback_;
103 scoped_refptr<UDPSocketFilter> recv_filter_;
105 PP_NetAddress_Private bound_addr_;
107 std::queue<scoped_refptr<TrackedCallback>> sendto_callbacks_;
109 DISALLOW_COPY_AND_ASSIGN(UDPSocketResourceBase);
112 } // namespace proxy
113 } // namespace ppapi
115 #endif // PPAPI_PROXY_UDP_SOCKET_RESOURCE_BASE_H_