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 "chrome/renderer/p2p/socket_dispatcher.h" | 5 #include "chrome/renderer/p2p/socket_dispatcher.h" |
6 | 6 |
7 #include "base/message_loop_proxy.h" | 7 #include "base/message_loop_proxy.h" |
8 #include "content/common/p2p_messages.h" | 8 #include "content/common/p2p_messages.h" |
9 #include "ipc/ipc_message.h" | 9 #include "ipc/ipc_message.h" |
10 #include "ipc/ipc_message_macros.h" | 10 #include "ipc/ipc_message_macros.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 void P2PSocketDispatcher::SendP2PMessage(IPC::Message* msg) { | 43 void P2PSocketDispatcher::SendP2PMessage(IPC::Message* msg) { |
44 msg->set_routing_id(routing_id()); | 44 msg->set_routing_id(routing_id()); |
45 Send(msg); | 45 Send(msg); |
46 } | 46 } |
47 | 47 |
48 base::MessageLoopProxy* P2PSocketDispatcher::message_loop() { | 48 base::MessageLoopProxy* P2PSocketDispatcher::message_loop() { |
49 return message_loop_; | 49 return message_loop_; |
50 } | 50 } |
51 | 51 |
52 void P2PSocketDispatcher::OnSocketCreated( | 52 void P2PSocketDispatcher::OnSocketCreated( |
53 int socket_id, const P2PSocketAddress& address) { | 53 int socket_id, const net::IPEndPoint& address) { |
54 P2PSocketClient* client = GetClient(socket_id); | 54 P2PSocketClient* client = GetClient(socket_id); |
55 if (client) { | 55 if (client) { |
56 client->OnSocketCreated(address); | 56 client->OnSocketCreated(address); |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 void P2PSocketDispatcher::OnError(int socket_id) { | 60 void P2PSocketDispatcher::OnError(int socket_id) { |
61 P2PSocketClient* client = GetClient(socket_id); | 61 P2PSocketClient* client = GetClient(socket_id); |
62 if (client) { | 62 if (client) { |
63 client->OnError(); | 63 client->OnError(); |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 void P2PSocketDispatcher::OnDataReceived( | 67 void P2PSocketDispatcher::OnDataReceived( |
68 int socket_id, const P2PSocketAddress& address, | 68 int socket_id, const net::IPEndPoint& address, |
69 const std::vector<char>& data) { | 69 const std::vector<char>& data) { |
70 P2PSocketClient* client = GetClient(socket_id); | 70 P2PSocketClient* client = GetClient(socket_id); |
71 if (client) { | 71 if (client) { |
72 client->OnDataReceived(address, data); | 72 client->OnDataReceived(address, data); |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 P2PSocketClient* P2PSocketDispatcher::GetClient(int socket_id) { | 76 P2PSocketClient* P2PSocketDispatcher::GetClient(int socket_id) { |
77 P2PSocketClient* client = clients_.Lookup(socket_id); | 77 P2PSocketClient* client = clients_.Lookup(socket_id); |
78 if (client == NULL) { | 78 if (client == NULL) { |
79 // This may happen if the socket was closed, but the browser side | 79 // This may happen if the socket was closed, but the browser side |
80 // hasn't processed the close message by the time it sends the | 80 // hasn't processed the close message by the time it sends the |
81 // message to the renderer. | 81 // message to the renderer. |
82 VLOG(1) << "Received P2P message for socket that doesn't exist."; | 82 VLOG(1) << "Received P2P message for socket that doesn't exist."; |
83 return NULL; | 83 return NULL; |
84 } | 84 } |
85 | 85 |
86 return client; | 86 return client; |
87 } | 87 } |
OLD | NEW |