OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/renderer_host/p2p_sockets_host.h" | 5 #include "content/browser/renderer_host/p2p_sockets_host.h" |
6 | 6 |
7 #include "content/browser/renderer_host/p2p_socket_host.h" | 7 #include "content/browser/renderer_host/p2p_socket_host.h" |
8 #include "content/common/p2p_messages.h" | 8 #include "content/common/p2p_messages.h" |
9 | 9 |
10 P2PSocketsHost::P2PSocketsHost() { | 10 P2PSocketsHost::P2PSocketsHost() { |
(...skipping 23 matching lines...) Expand all Loading... |
34 IPC_MESSAGE_HANDLER(P2PHostMsg_CreateSocket, OnCreateSocket) | 34 IPC_MESSAGE_HANDLER(P2PHostMsg_CreateSocket, OnCreateSocket) |
35 IPC_MESSAGE_HANDLER(P2PHostMsg_Send, OnSend) | 35 IPC_MESSAGE_HANDLER(P2PHostMsg_Send, OnSend) |
36 IPC_MESSAGE_HANDLER(P2PHostMsg_DestroySocket, OnDestroySocket) | 36 IPC_MESSAGE_HANDLER(P2PHostMsg_DestroySocket, OnDestroySocket) |
37 IPC_MESSAGE_UNHANDLED(handled = false) | 37 IPC_MESSAGE_UNHANDLED(handled = false) |
38 IPC_END_MESSAGE_MAP_EX() | 38 IPC_END_MESSAGE_MAP_EX() |
39 return handled; | 39 return handled; |
40 } | 40 } |
41 | 41 |
42 void P2PSocketsHost::OnCreateSocket( | 42 void P2PSocketsHost::OnCreateSocket( |
43 const IPC::Message& msg, P2PSocketType type, int socket_id, | 43 const IPC::Message& msg, P2PSocketType type, int socket_id, |
44 const P2PSocketAddress& remote_address) { | 44 const net::IPEndPoint& remote_address) { |
45 if (sockets_.Lookup(socket_id)) { | 45 if (sockets_.Lookup(socket_id)) { |
46 LOG(ERROR) << "Received P2PHostMsg_CreateSocket for socket " | 46 LOG(ERROR) << "Received P2PHostMsg_CreateSocket for socket " |
47 "that already exists."; | 47 "that already exists."; |
48 return; | 48 return; |
49 } | 49 } |
50 | 50 |
51 if (type != P2P_SOCKET_UDP) { | 51 if (type != P2P_SOCKET_UDP) { |
52 Send(new P2PMsg_OnError(msg.routing_id(), socket_id)); | 52 Send(new P2PMsg_OnError(msg.routing_id(), socket_id)); |
53 return; | 53 return; |
54 } | 54 } |
55 | 55 |
56 scoped_ptr<P2PSocketHost> socket( | 56 scoped_ptr<P2PSocketHost> socket( |
57 P2PSocketHost::Create(this, msg.routing_id(), socket_id, type)); | 57 P2PSocketHost::Create(this, msg.routing_id(), socket_id, type)); |
58 | 58 |
59 if (!socket.get()) { | 59 if (!socket.get()) { |
60 Send(new P2PMsg_OnError(msg.routing_id(), socket_id)); | 60 Send(new P2PMsg_OnError(msg.routing_id(), socket_id)); |
61 return; | 61 return; |
62 } | 62 } |
63 | 63 |
64 if (socket->Init()) { | 64 if (socket->Init()) { |
65 sockets_.AddWithID(socket.release(), socket_id); | 65 sockets_.AddWithID(socket.release(), socket_id); |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 void P2PSocketsHost::OnSend(const IPC::Message& msg, int socket_id, | 69 void P2PSocketsHost::OnSend(const IPC::Message& msg, int socket_id, |
70 const P2PSocketAddress& socket_address, | 70 const net::IPEndPoint& socket_address, |
71 const std::vector<char>& data) { | 71 const std::vector<char>& data) { |
72 P2PSocketHost* socket = sockets_.Lookup(socket_id); | 72 P2PSocketHost* socket = sockets_.Lookup(socket_id); |
73 if (!socket) { | 73 if (!socket) { |
74 LOG(ERROR) << "Received P2PHostMsg_Send for invalid socket_id."; | 74 LOG(ERROR) << "Received P2PHostMsg_Send for invalid socket_id."; |
75 return; | 75 return; |
76 } | 76 } |
77 socket->Send(socket_address, data); | 77 socket->Send(socket_address, data); |
78 } | 78 } |
79 | 79 |
80 void P2PSocketsHost::OnDestroySocket(const IPC::Message& msg, int socket_id) { | 80 void P2PSocketsHost::OnDestroySocket(const IPC::Message& msg, int socket_id) { |
81 sockets_.Remove(socket_id); | 81 sockets_.Remove(socket_id); |
82 } | 82 } |
OLD | NEW |