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