Chromium Code Reviews| 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 SendSetSocketFeature(PP_UDPSocketFeature_Private name, | |
| 34 PP_Var value) OVERRIDE; | |
| 32 virtual void SendBind(const PP_NetAddress_Private& addr) OVERRIDE; | 35 virtual void SendBind(const PP_NetAddress_Private& addr) OVERRIDE; |
| 33 virtual void SendRecvFrom(int32_t num_bytes) OVERRIDE; | 36 virtual void SendRecvFrom(int32_t num_bytes) OVERRIDE; |
| 34 virtual void SendSendTo(const std::string& data, | 37 virtual void SendSendTo(const std::string& data, |
| 35 const PP_NetAddress_Private& addr) OVERRIDE; | 38 const PP_NetAddress_Private& addr) OVERRIDE; |
| 36 virtual void SendClose() OVERRIDE; | 39 virtual void SendClose() OVERRIDE; |
| 37 | 40 |
| 38 private: | 41 private: |
| 39 void SendToBrowser(IPC::Message* msg); | 42 void SendToBrowser(IPC::Message* msg); |
| 40 | 43 |
| 41 DISALLOW_COPY_AND_ASSIGN(UDPSocket); | 44 DISALLOW_COPY_AND_ASSIGN(UDPSocket); |
| 42 }; | 45 }; |
| 43 | 46 |
| 44 UDPSocket::UDPSocket(const HostResource& resource, uint32 socket_id) | 47 UDPSocket::UDPSocket(const HostResource& resource, uint32 socket_id) |
| 45 : UDPSocketPrivateImpl(resource, socket_id) { | 48 : UDPSocketPrivateImpl(resource, socket_id) { |
| 46 if (!g_id_to_socket) | 49 if (!g_id_to_socket) |
| 47 g_id_to_socket = new IDToSocketMap(); | 50 g_id_to_socket = new IDToSocketMap(); |
| 48 DCHECK(g_id_to_socket->find(socket_id) == g_id_to_socket->end()); | 51 DCHECK(g_id_to_socket->find(socket_id) == g_id_to_socket->end()); |
| 49 (*g_id_to_socket)[socket_id] = this; | 52 (*g_id_to_socket)[socket_id] = this; |
| 50 } | 53 } |
| 51 | 54 |
| 52 UDPSocket::~UDPSocket() { | 55 UDPSocket::~UDPSocket() { |
| 53 Close(); | 56 Close(); |
| 54 } | 57 } |
| 55 | 58 |
| 59 void UDPSocket::SendSetSocketFeature(PP_UDPSocketFeature_Private name, | |
| 60 PP_Var value) { | |
| 61 switch (name) { | |
| 62 case PP_UDPSOCKETFEATURE_ADDRESS_REUSE: | |
| 63 case PP_UDPSOCKETFEATURE_BROADCAST: | |
| 64 DCHECK_EQ(PP_VARTYPE_BOOL, value.type); | |
| 65 SendToBrowser(new PpapiHostMsg_PPBUDPSocket_SetBoolSocketFeature( | |
| 66 API_ID_PPB_UDPSOCKET_PRIVATE, socket_id_, | |
| 67 name, (value.value.as_bool == PP_TRUE))); | |
|
brettw
2012/08/20 04:34:45
You can use PP_ToBool. Actually, I'd probably just
ygorshenin1
2012/08/20 12:08:01
Done.
Yes, I considered this way. It's possible t
brettw
2012/08/20 17:55:15
The implementation of in process plugins and the p
ygorshenin1
2012/08/21 12:00:27
As was decided in the discussion, PpapiHostMsg_PPB
| |
| 68 break; | |
| 69 default: | |
| 70 NOTREACHED(); | |
| 71 } | |
| 72 } | |
| 73 | |
| 56 void UDPSocket::SendBind(const PP_NetAddress_Private& addr) { | 74 void UDPSocket::SendBind(const PP_NetAddress_Private& addr) { |
| 57 SendToBrowser(new PpapiHostMsg_PPBUDPSocket_Bind( | 75 SendToBrowser(new PpapiHostMsg_PPBUDPSocket_Bind( |
| 58 API_ID_PPB_UDPSOCKET_PRIVATE, socket_id_, addr)); | 76 API_ID_PPB_UDPSOCKET_PRIVATE, socket_id_, addr)); |
| 59 } | 77 } |
| 60 | 78 |
| 61 void UDPSocket::SendRecvFrom(int32_t num_bytes) { | 79 void UDPSocket::SendRecvFrom(int32_t num_bytes) { |
| 62 SendToBrowser(new PpapiHostMsg_PPBUDPSocket_RecvFrom(socket_id_, num_bytes)); | 80 SendToBrowser(new PpapiHostMsg_PPBUDPSocket_RecvFrom(socket_id_, num_bytes)); |
| 63 } | 81 } |
| 64 | 82 |
| 65 void UDPSocket::SendSendTo(const std::string& data, | 83 void UDPSocket::SendSendTo(const std::string& data, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 if (socket_id == 0) | 123 if (socket_id == 0) |
| 106 return 0; | 124 return 0; |
| 107 | 125 |
| 108 return (new UDPSocket(HostResource::MakeInstanceOnly(instance), | 126 return (new UDPSocket(HostResource::MakeInstanceOnly(instance), |
| 109 socket_id))->GetReference(); | 127 socket_id))->GetReference(); |
| 110 } | 128 } |
| 111 | 129 |
| 112 bool PPB_UDPSocket_Private_Proxy::OnMessageReceived(const IPC::Message& msg) { | 130 bool PPB_UDPSocket_Private_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 113 bool handled = true; | 131 bool handled = true; |
| 114 IPC_BEGIN_MESSAGE_MAP(PPB_UDPSocket_Private_Proxy, msg) | 132 IPC_BEGIN_MESSAGE_MAP(PPB_UDPSocket_Private_Proxy, msg) |
| 133 IPC_MESSAGE_HANDLER(PpapiMsg_PPBUDPSocket_SetSocketFeatureACK, | |
| 134 OnMsgSetSocketFeatureACK) | |
| 115 IPC_MESSAGE_HANDLER(PpapiMsg_PPBUDPSocket_BindACK, | 135 IPC_MESSAGE_HANDLER(PpapiMsg_PPBUDPSocket_BindACK, |
| 116 OnMsgBindACK) | 136 OnMsgBindACK) |
| 117 IPC_MESSAGE_HANDLER(PpapiMsg_PPBUDPSocket_RecvFromACK, | 137 IPC_MESSAGE_HANDLER(PpapiMsg_PPBUDPSocket_RecvFromACK, |
| 118 OnMsgRecvFromACK) | 138 OnMsgRecvFromACK) |
| 119 IPC_MESSAGE_HANDLER(PpapiMsg_PPBUDPSocket_SendToACK, | 139 IPC_MESSAGE_HANDLER(PpapiMsg_PPBUDPSocket_SendToACK, |
| 120 OnMsgSendToACK) | 140 OnMsgSendToACK) |
| 121 IPC_MESSAGE_UNHANDLED(handled = false) | 141 IPC_MESSAGE_UNHANDLED(handled = false) |
| 122 IPC_END_MESSAGE_MAP() | 142 IPC_END_MESSAGE_MAP() |
| 123 return handled; | 143 return handled; |
| 124 } | 144 } |
| 125 | 145 |
| 146 void PPB_UDPSocket_Private_Proxy::OnMsgSetSocketFeatureACK( | |
| 147 uint32 /* plugin_dispatcher_id */, | |
| 148 uint32 socket_id, | |
| 149 bool succeeded) { | |
| 150 if (!g_id_to_socket) { | |
| 151 NOTREACHED(); | |
| 152 return; | |
| 153 } | |
| 154 IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); | |
| 155 if (iter == g_id_to_socket->end()) | |
| 156 return; | |
| 157 iter->second->OnSetSocketFeatureCompleted(succeeded); | |
| 158 } | |
| 159 | |
| 126 void PPB_UDPSocket_Private_Proxy::OnMsgBindACK( | 160 void PPB_UDPSocket_Private_Proxy::OnMsgBindACK( |
| 127 uint32 /* plugin_dispatcher_id */, | 161 uint32 /* plugin_dispatcher_id */, |
| 128 uint32 socket_id, | 162 uint32 socket_id, |
| 129 bool succeeded, | 163 bool succeeded, |
| 130 const PP_NetAddress_Private& bound_addr) { | 164 const PP_NetAddress_Private& bound_addr) { |
| 131 if (!g_id_to_socket) { | 165 if (!g_id_to_socket) { |
| 132 NOTREACHED(); | 166 NOTREACHED(); |
| 133 return; | 167 return; |
| 134 } | 168 } |
| 135 IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); | 169 IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 164 return; | 198 return; |
| 165 } | 199 } |
| 166 IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); | 200 IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); |
| 167 if (iter == g_id_to_socket->end()) | 201 if (iter == g_id_to_socket->end()) |
| 168 return; | 202 return; |
| 169 iter->second->OnSendToCompleted(succeeded, bytes_written); | 203 iter->second->OnSendToCompleted(succeeded, bytes_written); |
| 170 } | 204 } |
| 171 | 205 |
| 172 } // namespace proxy | 206 } // namespace proxy |
| 173 } // namespace ppapi | 207 } // namespace ppapi |
| OLD | NEW |