Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(532)

Side by Side Diff: ppapi/proxy/ppb_udp_socket_private_proxy.cc

Issue 10735056: AllowBroadcast() is exposed to NaCl. (Closed) Base URL: http://git.chromium.org/chromium/src.git@udp_broadcast
Patch Set: Deleted callbacks. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/pp_bool.h"
11 #include "ppapi/c/private/ppb_udp_socket_private.h"
10 #include "ppapi/proxy/plugin_dispatcher.h" 12 #include "ppapi/proxy/plugin_dispatcher.h"
11 #include "ppapi/proxy/plugin_globals.h" 13 #include "ppapi/proxy/plugin_globals.h"
12 #include "ppapi/proxy/plugin_proxy_delegate.h" 14 #include "ppapi/proxy/plugin_proxy_delegate.h"
13 #include "ppapi/proxy/plugin_resource_tracker.h" 15 #include "ppapi/proxy/plugin_resource_tracker.h"
14 #include "ppapi/proxy/ppapi_messages.h" 16 #include "ppapi/proxy/ppapi_messages.h"
15 #include "ppapi/shared_impl/private/udp_socket_private_impl.h" 17 #include "ppapi/shared_impl/private/udp_socket_private_impl.h"
16 #include "ppapi/shared_impl/resource.h" 18 #include "ppapi/shared_impl/resource.h"
17 #include "ppapi/thunk/thunk.h" 19 #include "ppapi/thunk/thunk.h"
18 20
19 namespace ppapi { 21 namespace ppapi {
20 namespace proxy { 22 namespace proxy {
21 23
22 namespace { 24 namespace {
23 25
24 typedef std::map<uint32, UDPSocketPrivateImpl*> IDToSocketMap; 26 typedef std::map<uint32, UDPSocketPrivateImpl*> IDToSocketMap;
25 IDToSocketMap* g_id_to_socket = NULL; 27 IDToSocketMap* g_id_to_socket = NULL;
26 28
27 class UDPSocket : public UDPSocketPrivateImpl { 29 class UDPSocket : public UDPSocketPrivateImpl {
28 public: 30 public:
29 UDPSocket(const HostResource& resource, uint32 socket_id); 31 UDPSocket(const HostResource& resource, uint32 socket_id);
30 virtual ~UDPSocket(); 32 virtual ~UDPSocket();
31 33
34 virtual void SendSetSocketFeature(PP_UDPSocketFeature_Private name,
35 PP_Var value) OVERRIDE;
32 virtual void SendBind(const PP_NetAddress_Private& addr) OVERRIDE; 36 virtual void SendBind(const PP_NetAddress_Private& addr) OVERRIDE;
33 virtual void SendRecvFrom(int32_t num_bytes) OVERRIDE; 37 virtual void SendRecvFrom(int32_t num_bytes) OVERRIDE;
34 virtual void SendSendTo(const std::string& data, 38 virtual void SendSendTo(const std::string& data,
35 const PP_NetAddress_Private& addr) OVERRIDE; 39 const PP_NetAddress_Private& addr) OVERRIDE;
36 virtual void SendClose() OVERRIDE; 40 virtual void SendClose() OVERRIDE;
37 41
38 private: 42 private:
39 void SendToBrowser(IPC::Message* msg); 43 void SendToBrowser(IPC::Message* msg);
40 44
41 DISALLOW_COPY_AND_ASSIGN(UDPSocket); 45 DISALLOW_COPY_AND_ASSIGN(UDPSocket);
42 }; 46 };
43 47
44 UDPSocket::UDPSocket(const HostResource& resource, uint32 socket_id) 48 UDPSocket::UDPSocket(const HostResource& resource, uint32 socket_id)
45 : UDPSocketPrivateImpl(resource, socket_id) { 49 : UDPSocketPrivateImpl(resource, socket_id) {
46 if (!g_id_to_socket) 50 if (!g_id_to_socket)
47 g_id_to_socket = new IDToSocketMap(); 51 g_id_to_socket = new IDToSocketMap();
48 DCHECK(g_id_to_socket->find(socket_id) == g_id_to_socket->end()); 52 DCHECK(g_id_to_socket->find(socket_id) == g_id_to_socket->end());
49 (*g_id_to_socket)[socket_id] = this; 53 (*g_id_to_socket)[socket_id] = this;
50 } 54 }
51 55
52 UDPSocket::~UDPSocket() { 56 UDPSocket::~UDPSocket() {
53 Close(); 57 Close();
54 } 58 }
55 59
60 void UDPSocket::SendSetSocketFeature(PP_UDPSocketFeature_Private name,
61 PP_Var value) {
62 switch (name) {
63 case PP_UDPSOCKETFEATURE_ADDRESS_REUSE:
64 case PP_UDPSOCKETFEATURE_BROADCAST:
65 DCHECK_EQ(PP_VARTYPE_BOOL, value.type);
66 SendToBrowser(new PpapiHostMsg_PPBUDPSocket_SetBoolSocketFeature(
67 API_ID_PPB_UDPSOCKET_PRIVATE, socket_id_,
68 static_cast<int32_t>(name), PP_ToBool(value.value.as_bool)));
69 break;
70 default:
71 NOTREACHED();
72 }
73 }
74
56 void UDPSocket::SendBind(const PP_NetAddress_Private& addr) { 75 void UDPSocket::SendBind(const PP_NetAddress_Private& addr) {
57 SendToBrowser(new PpapiHostMsg_PPBUDPSocket_Bind( 76 SendToBrowser(new PpapiHostMsg_PPBUDPSocket_Bind(
58 API_ID_PPB_UDPSOCKET_PRIVATE, socket_id_, addr)); 77 API_ID_PPB_UDPSOCKET_PRIVATE, socket_id_, addr));
59 } 78 }
60 79
61 void UDPSocket::SendRecvFrom(int32_t num_bytes) { 80 void UDPSocket::SendRecvFrom(int32_t num_bytes) {
62 SendToBrowser(new PpapiHostMsg_PPBUDPSocket_RecvFrom(socket_id_, num_bytes)); 81 SendToBrowser(new PpapiHostMsg_PPBUDPSocket_RecvFrom(socket_id_, num_bytes));
63 } 82 }
64 83
65 void UDPSocket::SendSendTo(const std::string& data, 84 void UDPSocket::SendSendTo(const std::string& data,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 return; 183 return;
165 } 184 }
166 IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); 185 IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id);
167 if (iter == g_id_to_socket->end()) 186 if (iter == g_id_to_socket->end())
168 return; 187 return;
169 iter->second->OnSendToCompleted(succeeded, bytes_written); 188 iter->second->OnSendToCompleted(succeeded, bytes_written);
170 } 189 }
171 190
172 } // namespace proxy 191 } // namespace proxy
173 } // namespace ppapi 192 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698