| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/proxy/ppb_udp_socket_private_proxy.h" | 5 #include "ppapi/proxy/ppb_udp_socket_private_proxy.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ppapi/c/private/ppb_udp_socket_private.h" |
| 10 #include "ppapi/proxy/plugin_dispatcher.h" | 11 #include "ppapi/proxy/plugin_dispatcher.h" |
| 11 #include "ppapi/proxy/plugin_globals.h" | 12 #include "ppapi/proxy/plugin_globals.h" |
| 12 #include "ppapi/proxy/plugin_proxy_delegate.h" | 13 #include "ppapi/proxy/plugin_proxy_delegate.h" |
| 13 #include "ppapi/proxy/plugin_resource_tracker.h" | 14 #include "ppapi/proxy/plugin_resource_tracker.h" |
| 14 #include "ppapi/proxy/ppapi_messages.h" | 15 #include "ppapi/proxy/ppapi_messages.h" |
| 15 #include "ppapi/shared_impl/private/udp_socket_private_impl.h" | 16 #include "ppapi/shared_impl/private/udp_socket_private_impl.h" |
| 16 #include "ppapi/shared_impl/resource.h" | 17 #include "ppapi/shared_impl/resource.h" |
| 17 #include "ppapi/thunk/thunk.h" | 18 #include "ppapi/thunk/thunk.h" |
| 18 | 19 |
| 19 namespace ppapi { | 20 namespace ppapi { |
| 20 namespace proxy { | 21 namespace proxy { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 typedef std::map<uint32, UDPSocketPrivateImpl*> IDToSocketMap; | 25 typedef std::map<uint32, UDPSocketPrivateImpl*> IDToSocketMap; |
| 25 IDToSocketMap* g_id_to_socket = NULL; | 26 IDToSocketMap* g_id_to_socket = NULL; |
| 26 | 27 |
| 27 class UDPSocket : public UDPSocketPrivateImpl { | 28 class UDPSocket : public UDPSocketPrivateImpl { |
| 28 public: | 29 public: |
| 29 UDPSocket(const HostResource& resource, uint32 socket_id); | 30 UDPSocket(const HostResource& resource, uint32 socket_id); |
| 30 virtual ~UDPSocket(); | 31 virtual ~UDPSocket(); |
| 31 | 32 |
| 33 virtual void SendBoolSocketFeature(int32_t name, bool value) OVERRIDE; |
| 32 virtual void SendBind(const PP_NetAddress_Private& addr) OVERRIDE; | 34 virtual void SendBind(const PP_NetAddress_Private& addr) OVERRIDE; |
| 33 virtual void SendRecvFrom(int32_t num_bytes) OVERRIDE; | 35 virtual void SendRecvFrom(int32_t num_bytes) OVERRIDE; |
| 34 virtual void SendSendTo(const std::string& data, | 36 virtual void SendSendTo(const std::string& data, |
| 35 const PP_NetAddress_Private& addr) OVERRIDE; | 37 const PP_NetAddress_Private& addr) OVERRIDE; |
| 36 virtual void SendClose() OVERRIDE; | 38 virtual void SendClose() OVERRIDE; |
| 37 | 39 |
| 38 private: | 40 private: |
| 39 void SendToBrowser(IPC::Message* msg); | 41 void SendToBrowser(IPC::Message* msg); |
| 40 | 42 |
| 41 DISALLOW_COPY_AND_ASSIGN(UDPSocket); | 43 DISALLOW_COPY_AND_ASSIGN(UDPSocket); |
| 42 }; | 44 }; |
| 43 | 45 |
| 44 UDPSocket::UDPSocket(const HostResource& resource, uint32 socket_id) | 46 UDPSocket::UDPSocket(const HostResource& resource, uint32 socket_id) |
| 45 : UDPSocketPrivateImpl(resource, socket_id) { | 47 : UDPSocketPrivateImpl(resource, socket_id) { |
| 46 if (!g_id_to_socket) | 48 if (!g_id_to_socket) |
| 47 g_id_to_socket = new IDToSocketMap(); | 49 g_id_to_socket = new IDToSocketMap(); |
| 48 DCHECK(g_id_to_socket->find(socket_id) == g_id_to_socket->end()); | 50 DCHECK(g_id_to_socket->find(socket_id) == g_id_to_socket->end()); |
| 49 (*g_id_to_socket)[socket_id] = this; | 51 (*g_id_to_socket)[socket_id] = this; |
| 50 } | 52 } |
| 51 | 53 |
| 52 UDPSocket::~UDPSocket() { | 54 UDPSocket::~UDPSocket() { |
| 53 Close(); | 55 Close(); |
| 54 } | 56 } |
| 55 | 57 |
| 58 void UDPSocket::SendBoolSocketFeature(int32_t name, bool value) { |
| 59 SendToBrowser(new PpapiHostMsg_PPBUDPSocket_SetBoolSocketFeature( |
| 60 API_ID_PPB_UDPSOCKET_PRIVATE, socket_id_, name, value)); |
| 61 } |
| 62 |
| 56 void UDPSocket::SendBind(const PP_NetAddress_Private& addr) { | 63 void UDPSocket::SendBind(const PP_NetAddress_Private& addr) { |
| 57 SendToBrowser(new PpapiHostMsg_PPBUDPSocket_Bind( | 64 SendToBrowser(new PpapiHostMsg_PPBUDPSocket_Bind( |
| 58 API_ID_PPB_UDPSOCKET_PRIVATE, socket_id_, addr)); | 65 API_ID_PPB_UDPSOCKET_PRIVATE, socket_id_, addr)); |
| 59 } | 66 } |
| 60 | 67 |
| 61 void UDPSocket::SendRecvFrom(int32_t num_bytes) { | 68 void UDPSocket::SendRecvFrom(int32_t num_bytes) { |
| 62 SendToBrowser(new PpapiHostMsg_PPBUDPSocket_RecvFrom(socket_id_, num_bytes)); | 69 SendToBrowser(new PpapiHostMsg_PPBUDPSocket_RecvFrom(socket_id_, num_bytes)); |
| 63 } | 70 } |
| 64 | 71 |
| 65 void UDPSocket::SendSendTo(const std::string& data, | 72 void UDPSocket::SendSendTo(const std::string& data, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 return; | 171 return; |
| 165 } | 172 } |
| 166 IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); | 173 IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); |
| 167 if (iter == g_id_to_socket->end()) | 174 if (iter == g_id_to_socket->end()) |
| 168 return; | 175 return; |
| 169 iter->second->OnSendToCompleted(succeeded, bytes_written); | 176 iter->second->OnSendToCompleted(succeeded, bytes_written); |
| 170 } | 177 } |
| 171 | 178 |
| 172 } // namespace proxy | 179 } // namespace proxy |
| 173 } // namespace ppapi | 180 } // namespace ppapi |
| OLD | NEW |