| 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 "content/browser/renderer_host/p2p/socket_dispatcher_host.h" | 5 #include "content/browser/renderer_host/p2p/socket_dispatcher_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "content/browser/renderer_host/p2p/socket_host.h" | 9 #include "content/browser/renderer_host/p2p/socket_host.h" |
| 10 #include "content/common/p2p_messages.h" | 10 #include "content/common/p2p_messages.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 92 |
| 93 DoneCallback done_callback_; | 93 DoneCallback done_callback_; |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 P2PSocketDispatcherHost::P2PSocketDispatcherHost( | 96 P2PSocketDispatcherHost::P2PSocketDispatcherHost( |
| 97 content::ResourceContext* resource_context, | 97 content::ResourceContext* resource_context, |
| 98 net::URLRequestContextGetter* url_context) | 98 net::URLRequestContextGetter* url_context) |
| 99 : BrowserMessageFilter(P2PMsgStart), | 99 : BrowserMessageFilter(P2PMsgStart), |
| 100 resource_context_(resource_context), | 100 resource_context_(resource_context), |
| 101 url_context_(url_context), | 101 url_context_(url_context), |
| 102 monitoring_networks_(false) { | 102 monitoring_networks_(false), |
| 103 dump_incoming_rtp_packet_(false), |
| 104 dump_outgoing_rtp_packet_(false) { |
| 103 } | 105 } |
| 104 | 106 |
| 105 void P2PSocketDispatcherHost::OnChannelClosing() { | 107 void P2PSocketDispatcherHost::OnChannelClosing() { |
| 106 // Since the IPC channel is gone, close pending connections. | 108 // Since the IPC channel is gone, close pending connections. |
| 107 STLDeleteContainerPairSecondPointers(sockets_.begin(), sockets_.end()); | 109 STLDeleteContainerPairSecondPointers(sockets_.begin(), sockets_.end()); |
| 108 sockets_.clear(); | 110 sockets_.clear(); |
| 109 | 111 |
| 110 STLDeleteContainerPointers(dns_requests_.begin(), dns_requests_.end()); | 112 STLDeleteContainerPointers(dns_requests_.begin(), dns_requests_.end()); |
| 111 dns_requests_.clear(); | 113 dns_requests_.clear(); |
| 112 | 114 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 140 return handled; | 142 return handled; |
| 141 } | 143 } |
| 142 | 144 |
| 143 void P2PSocketDispatcherHost::OnIPAddressChanged() { | 145 void P2PSocketDispatcherHost::OnIPAddressChanged() { |
| 144 // Notify the renderer about changes to list of network interfaces. | 146 // Notify the renderer about changes to list of network interfaces. |
| 145 BrowserThread::PostTask( | 147 BrowserThread::PostTask( |
| 146 BrowserThread::FILE, FROM_HERE, base::Bind( | 148 BrowserThread::FILE, FROM_HERE, base::Bind( |
| 147 &P2PSocketDispatcherHost::DoGetNetworkList, this)); | 149 &P2PSocketDispatcherHost::DoGetNetworkList, this)); |
| 148 } | 150 } |
| 149 | 151 |
| 152 void P2PSocketDispatcherHost::StartRtpDump( |
| 153 bool incoming, |
| 154 bool outgoing, |
| 155 const RenderProcessHost::WebRtcRtpPacketCallback& packet_callback) { |
| 156 if (dump_incoming_rtp_packet_ != incoming || |
| 157 dump_outgoing_rtp_packet_ != outgoing) { |
| 158 dump_incoming_rtp_packet_ = incoming; |
| 159 dump_outgoing_rtp_packet_ = outgoing; |
| 160 |
| 161 packet_callback_ = packet_callback; |
| 162 for (SocketsMap::iterator it = sockets_.begin(); it != sockets_.end(); ++it) |
| 163 it->second->StartRtpDump(incoming, outgoing, packet_callback); |
| 164 } |
| 165 } |
| 166 |
| 167 void P2PSocketDispatcherHost::StopRtpDump(bool incoming, bool outgoing) { |
| 168 if (dump_incoming_rtp_packet_ == incoming || |
| 169 dump_outgoing_rtp_packet_ == outgoing) { |
| 170 dump_incoming_rtp_packet_ = !incoming; |
| 171 dump_outgoing_rtp_packet_ = !outgoing; |
| 172 |
| 173 if (!dump_incoming_rtp_packet_ && !dump_outgoing_rtp_packet_) |
| 174 packet_callback_.Reset(); |
| 175 |
| 176 for (SocketsMap::iterator it = sockets_.begin(); it != sockets_.end(); ++it) |
| 177 it->second->StopRtpDump(incoming, outgoing); |
| 178 } |
| 179 } |
| 180 |
| 150 P2PSocketDispatcherHost::~P2PSocketDispatcherHost() { | 181 P2PSocketDispatcherHost::~P2PSocketDispatcherHost() { |
| 151 DCHECK(sockets_.empty()); | 182 DCHECK(sockets_.empty()); |
| 152 DCHECK(dns_requests_.empty()); | 183 DCHECK(dns_requests_.empty()); |
| 153 | 184 |
| 154 if (monitoring_networks_) | 185 if (monitoring_networks_) |
| 155 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 186 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 156 } | 187 } |
| 157 | 188 |
| 158 P2PSocketHost* P2PSocketDispatcherHost::LookupSocket(int socket_id) { | 189 P2PSocketHost* P2PSocketDispatcherHost::LookupSocket(int socket_id) { |
| 159 SocketsMap::iterator it = sockets_.find(socket_id); | 190 SocketsMap::iterator it = sockets_.find(socket_id); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 scoped_ptr<P2PSocketHost> socket(P2PSocketHost::Create( | 234 scoped_ptr<P2PSocketHost> socket(P2PSocketHost::Create( |
| 204 this, socket_id, type, url_context_.get(), &throttler_)); | 235 this, socket_id, type, url_context_.get(), &throttler_)); |
| 205 | 236 |
| 206 if (!socket) { | 237 if (!socket) { |
| 207 Send(new P2PMsg_OnError(socket_id)); | 238 Send(new P2PMsg_OnError(socket_id)); |
| 208 return; | 239 return; |
| 209 } | 240 } |
| 210 | 241 |
| 211 if (socket->Init(local_address, remote_address)) { | 242 if (socket->Init(local_address, remote_address)) { |
| 212 sockets_[socket_id] = socket.release(); | 243 sockets_[socket_id] = socket.release(); |
| 244 |
| 245 if (dump_incoming_rtp_packet_ || dump_outgoing_rtp_packet_) { |
| 246 sockets_[socket_id]->StartRtpDump(dump_incoming_rtp_packet_, |
| 247 dump_outgoing_rtp_packet_, |
| 248 packet_callback_); |
| 249 } |
| 213 } | 250 } |
| 214 } | 251 } |
| 215 | 252 |
| 216 void P2PSocketDispatcherHost::OnAcceptIncomingTcpConnection( | 253 void P2PSocketDispatcherHost::OnAcceptIncomingTcpConnection( |
| 217 int listen_socket_id, const net::IPEndPoint& remote_address, | 254 int listen_socket_id, const net::IPEndPoint& remote_address, |
| 218 int connected_socket_id) { | 255 int connected_socket_id) { |
| 219 P2PSocketHost* socket = LookupSocket(listen_socket_id); | 256 P2PSocketHost* socket = LookupSocket(listen_socket_id); |
| 220 if (!socket) { | 257 if (!socket) { |
| 221 LOG(ERROR) << "Received P2PHostMsg_AcceptIncomingTcpConnection " | 258 LOG(ERROR) << "Received P2PHostMsg_AcceptIncomingTcpConnection " |
| 222 "for invalid socket_id."; | 259 "for invalid socket_id."; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 void P2PSocketDispatcherHost::OnAddressResolved( | 328 void P2PSocketDispatcherHost::OnAddressResolved( |
| 292 DnsRequest* request, | 329 DnsRequest* request, |
| 293 const net::IPAddressList& addresses) { | 330 const net::IPAddressList& addresses) { |
| 294 Send(new P2PMsg_GetHostAddressResult(request->request_id(), addresses)); | 331 Send(new P2PMsg_GetHostAddressResult(request->request_id(), addresses)); |
| 295 | 332 |
| 296 dns_requests_.erase(request); | 333 dns_requests_.erase(request); |
| 297 delete request; | 334 delete request; |
| 298 } | 335 } |
| 299 | 336 |
| 300 } // namespace content | 337 } // namespace content |
| OLD | NEW |