OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_UDP_SOCKET_PRIVATE_HOST_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_UDP_SOCKET_PRIVATE_HOST_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" |
| 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" |
| 16 #include "content/common/content_export.h" |
| 17 #include "net/base/completion_callback.h" |
| 18 #include "net/base/ip_endpoint.h" |
| 19 #include "ppapi/c/pp_stdint.h" |
| 20 #include "ppapi/host/resource_host.h" |
| 21 |
| 22 struct PP_NetAddress_Private; |
| 23 |
| 24 namespace net { |
| 25 class IOBuffer; |
| 26 class IOBufferWithSize; |
| 27 class UDPServerSocket; |
| 28 } |
| 29 |
| 30 namespace ppapi { |
| 31 namespace host { |
| 32 struct ReplyMessageContext; |
| 33 } |
| 34 } |
| 35 |
| 36 namespace content { |
| 37 |
| 38 class BrowserPpapiHostImpl; |
| 39 struct SocketPermissionRequest; |
| 40 |
| 41 class CONTENT_EXPORT PepperUDPSocketPrivateHost |
| 42 : public ppapi::host::ResourceHost { |
| 43 public: |
| 44 PepperUDPSocketPrivateHost(BrowserPpapiHostImpl* host, |
| 45 PP_Instance instance, |
| 46 PP_Resource resource); |
| 47 virtual ~PepperUDPSocketPrivateHost(); |
| 48 |
| 49 // ppapi::host::ResourceHost implementation. |
| 50 virtual int32_t OnResourceMessageReceived( |
| 51 const IPC::Message& msg, |
| 52 ppapi::host::HostMessageContext* context) OVERRIDE; |
| 53 |
| 54 private: |
| 55 typedef base::Callback<void(bool allowed)> RequestCallback; |
| 56 |
| 57 int32_t OnMsgSetBoolSocketFeature( |
| 58 const ppapi::host::HostMessageContext* context, |
| 59 int32_t name, |
| 60 bool value); |
| 61 int32_t OnMsgBind(const ppapi::host::HostMessageContext* context, |
| 62 const PP_NetAddress_Private& addr); |
| 63 int32_t OnMsgRecvFrom(const ppapi::host::HostMessageContext* context, |
| 64 int32_t num_bytes); |
| 65 int32_t OnMsgSendTo(const ppapi::host::HostMessageContext* context, |
| 66 const std::string& data, |
| 67 const PP_NetAddress_Private& addr); |
| 68 int32_t OnMsgClose(const ppapi::host::HostMessageContext* context); |
| 69 |
| 70 void DoBind(const PP_NetAddress_Private& addr, bool allowed); |
| 71 void DoSendTo(const PP_NetAddress_Private& addr, bool allowed); |
| 72 void Close(); |
| 73 |
| 74 void OnBindCompleted(int result); |
| 75 void OnRecvFromCompleted(int result); |
| 76 void OnSendToCompleted(int result); |
| 77 |
| 78 void SendBindReply(bool succeeded, |
| 79 const PP_NetAddress_Private& addr); |
| 80 void SendRecvFromReply(bool succeeded, |
| 81 const std::string& data, |
| 82 const PP_NetAddress_Private& addr); |
| 83 void SendSendToReply(bool succeeded, int32_t bytes_written); |
| 84 |
| 85 void SendBindError(); |
| 86 void SendRecvFromError(); |
| 87 void SendSendToError(); |
| 88 |
| 89 void CheckSocketPermissionsAndReply(const SocketPermissionRequest& params, |
| 90 const RequestCallback& callback); |
| 91 |
| 92 bool closed() { return closed_; } |
| 93 |
| 94 bool allow_address_reuse_; |
| 95 bool allow_broadcast_; |
| 96 |
| 97 scoped_ptr<net::UDPServerSocket> socket_; |
| 98 bool closed_; |
| 99 |
| 100 scoped_refptr<net::IOBuffer> recvfrom_buffer_; |
| 101 scoped_refptr<net::IOBufferWithSize> sendto_buffer_; |
| 102 |
| 103 net::IPEndPoint recvfrom_address_; |
| 104 net::IPEndPoint bound_address_; |
| 105 |
| 106 scoped_ptr<ppapi::host::ReplyMessageContext> bind_context_; |
| 107 scoped_ptr<ppapi::host::ReplyMessageContext> recv_from_context_; |
| 108 scoped_ptr<ppapi::host::ReplyMessageContext> send_to_context_; |
| 109 |
| 110 BrowserPpapiHostImpl* host_; |
| 111 |
| 112 base::WeakPtrFactory<PepperUDPSocketPrivateHost> weak_factory_; |
| 113 |
| 114 DISALLOW_COPY_AND_ASSIGN(PepperUDPSocketPrivateHost); |
| 115 }; |
| 116 |
| 117 } // namespace content |
| 118 |
| 119 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_UDP_SOCKET_PRIVATE_HOST_H
_ |
OLD | NEW |