Roll leveldb from r73 to r75.
[chromium-blink-merge.git] / ppapi / proxy / udp_socket_resource_base.h
blobb3a66693ed57e4f4d02dd32e24ae1fbfb98890da
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_
8 #include <string>
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"
19 namespace ppapi {
20 namespace proxy {
22 class ResourceMessageReplyParams;
24 class PPAPI_PROXY_EXPORT UDPSocketResourceBase: public PluginResource {
25 public:
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 protected:
34 UDPSocketResourceBase(Connection connection, PP_Instance instance);
35 virtual ~UDPSocketResourceBase();
37 int32_t SetSocketFeatureImpl(PP_UDPSocketFeature_Private name,
38 const PP_Var& value);
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,
44 int32_t num_bytes,
45 PP_Resource* addr,
46 scoped_refptr<TrackedCallback> callback);
47 PP_Bool GetRecvFromAddressImpl(PP_NetAddress_Private* addr);
48 int32_t SendToImpl(const char* buffer,
49 int32_t num_bytes,
50 const PP_NetAddress_Private* addr,
51 scoped_refptr<TrackedCallback> callback);
52 void CloseImpl();
54 private:
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);
67 bool bound_;
68 bool closed_;
70 scoped_refptr<TrackedCallback> bind_callback_;
71 scoped_refptr<TrackedCallback> recvfrom_callback_;
72 scoped_refptr<TrackedCallback> sendto_callback_;
74 char* read_buffer_;
75 int32_t bytes_to_read_;
77 PP_NetAddress_Private recvfrom_addr_;
78 PP_NetAddress_Private bound_addr_;
80 DISALLOW_COPY_AND_ASSIGN(UDPSocketResourceBase);
83 } // namespace proxy
84 } // namespace ppapi
86 #endif // PPAPI_PROXY_UDP_SOCKET_SHARED_H_