| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> |
| 10 |
| 9 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/memory/ptr_util.h" |
| 10 #include "content/browser/bad_message.h" | 13 #include "content/browser/bad_message.h" |
| 11 #include "content/browser/renderer_host/p2p/socket_host.h" | 14 #include "content/browser/renderer_host/p2p/socket_host.h" |
| 12 #include "content/common/p2p_messages.h" | 15 #include "content/common/p2p_messages.h" |
| 13 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/resource_context.h" | 17 #include "content/public/browser/resource_context.h" |
| 15 #include "net/base/address_list.h" | 18 #include "net/base/address_list.h" |
| 16 #include "net/base/completion_callback.h" | 19 #include "net/base/completion_callback.h" |
| 17 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 18 #include "net/base/network_interfaces.h" | 21 #include "net/base/network_interfaces.h" |
| 19 #include "net/base/sys_addrinfo.h" | 22 #include "net/base/sys_addrinfo.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 url_context_(url_context), | 118 url_context_(url_context), |
| 116 monitoring_networks_(false), | 119 monitoring_networks_(false), |
| 117 dump_incoming_rtp_packet_(false), | 120 dump_incoming_rtp_packet_(false), |
| 118 dump_outgoing_rtp_packet_(false) { | 121 dump_outgoing_rtp_packet_(false) { |
| 119 } | 122 } |
| 120 | 123 |
| 121 void P2PSocketDispatcherHost::OnChannelClosing() { | 124 void P2PSocketDispatcherHost::OnChannelClosing() { |
| 122 // Since the IPC sender is gone, close pending connections. | 125 // Since the IPC sender is gone, close pending connections. |
| 123 sockets_.clear(); | 126 sockets_.clear(); |
| 124 | 127 |
| 125 base::STLDeleteContainerPointers(dns_requests_.begin(), dns_requests_.end()); | |
| 126 dns_requests_.clear(); | 128 dns_requests_.clear(); |
| 127 | 129 |
| 128 if (monitoring_networks_) { | 130 if (monitoring_networks_) { |
| 129 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 131 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 130 monitoring_networks_ = false; | 132 monitoring_networks_ = false; |
| 131 } | 133 } |
| 132 } | 134 } |
| 133 | 135 |
| 134 void P2PSocketDispatcherHost::OnDestruct() const { | 136 void P2PSocketDispatcherHost::OnDestruct() const { |
| 135 BrowserThread::DeleteOnIOThread::Destruct(this); | 137 BrowserThread::DeleteOnIOThread::Destruct(this); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 221 |
| 220 void P2PSocketDispatcherHost::OnStopNetworkNotifications() { | 222 void P2PSocketDispatcherHost::OnStopNetworkNotifications() { |
| 221 if (monitoring_networks_) { | 223 if (monitoring_networks_) { |
| 222 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 224 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 223 monitoring_networks_ = false; | 225 monitoring_networks_ = false; |
| 224 } | 226 } |
| 225 } | 227 } |
| 226 | 228 |
| 227 void P2PSocketDispatcherHost::OnGetHostAddress(const std::string& host_name, | 229 void P2PSocketDispatcherHost::OnGetHostAddress(const std::string& host_name, |
| 228 int32_t request_id) { | 230 int32_t request_id) { |
| 229 DnsRequest* request = new DnsRequest(request_id, | 231 std::unique_ptr<DnsRequest> request = base::MakeUnique<DnsRequest>( |
| 230 resource_context_->GetHostResolver()); | 232 request_id, resource_context_->GetHostResolver()); |
| 231 dns_requests_.insert(request); | 233 DnsRequest* request_ptr = request.get(); |
| 232 request->Resolve(host_name, base::Bind( | 234 dns_requests_.insert(std::move(request)); |
| 233 &P2PSocketDispatcherHost::OnAddressResolved, | 235 request_ptr->Resolve(host_name, |
| 234 base::Unretained(this), request)); | 236 base::Bind(&P2PSocketDispatcherHost::OnAddressResolved, |
| 237 base::Unretained(this), request_ptr)); |
| 235 } | 238 } |
| 236 | 239 |
| 237 void P2PSocketDispatcherHost::OnCreateSocket( | 240 void P2PSocketDispatcherHost::OnCreateSocket( |
| 238 P2PSocketType type, | 241 P2PSocketType type, |
| 239 int socket_id, | 242 int socket_id, |
| 240 const net::IPEndPoint& local_address, | 243 const net::IPEndPoint& local_address, |
| 241 const P2PPortRange& port_range, | 244 const P2PPortRange& port_range, |
| 242 const P2PHostAndIPEndPoint& remote_address) { | 245 const P2PHostAndIPEndPoint& remote_address) { |
| 243 if (port_range.min_port > port_range.max_port || | 246 if (port_range.min_port > port_range.max_port || |
| 244 (port_range.min_port == 0 && port_range.max_port != 0)) { | 247 (port_range.min_port == 0 && port_range.max_port != 0)) { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 return net::IPAddress(); | 389 return net::IPAddress(); |
| 387 | 390 |
| 388 return local_address.address(); | 391 return local_address.address(); |
| 389 } | 392 } |
| 390 | 393 |
| 391 void P2PSocketDispatcherHost::OnAddressResolved( | 394 void P2PSocketDispatcherHost::OnAddressResolved( |
| 392 DnsRequest* request, | 395 DnsRequest* request, |
| 393 const net::IPAddressList& addresses) { | 396 const net::IPAddressList& addresses) { |
| 394 Send(new P2PMsg_GetHostAddressResult(request->request_id(), addresses)); | 397 Send(new P2PMsg_GetHostAddressResult(request->request_id(), addresses)); |
| 395 | 398 |
| 396 dns_requests_.erase(request); | 399 dns_requests_.erase( |
| 397 delete request; | 400 std::find_if(dns_requests_.begin(), dns_requests_.end(), |
| 401 [request](const std::unique_ptr<DnsRequest>& ptr) { |
| 402 return ptr.get() == request; |
| 403 })); |
| 398 } | 404 } |
| 399 | 405 |
| 400 void P2PSocketDispatcherHost::StopRtpDumpOnIOThread(bool incoming, | 406 void P2PSocketDispatcherHost::StopRtpDumpOnIOThread(bool incoming, |
| 401 bool outgoing) { | 407 bool outgoing) { |
| 402 if ((dump_incoming_rtp_packet_ && incoming) || | 408 if ((dump_incoming_rtp_packet_ && incoming) || |
| 403 (dump_outgoing_rtp_packet_ && outgoing)) { | 409 (dump_outgoing_rtp_packet_ && outgoing)) { |
| 404 if (incoming) | 410 if (incoming) |
| 405 dump_incoming_rtp_packet_ = false; | 411 dump_incoming_rtp_packet_ = false; |
| 406 | 412 |
| 407 if (outgoing) | 413 if (outgoing) |
| 408 dump_outgoing_rtp_packet_ = false; | 414 dump_outgoing_rtp_packet_ = false; |
| 409 | 415 |
| 410 if (!dump_incoming_rtp_packet_ && !dump_outgoing_rtp_packet_) | 416 if (!dump_incoming_rtp_packet_ && !dump_outgoing_rtp_packet_) |
| 411 packet_callback_.Reset(); | 417 packet_callback_.Reset(); |
| 412 | 418 |
| 413 for (SocketsMap::iterator it = sockets_.begin(); it != sockets_.end(); ++it) | 419 for (SocketsMap::iterator it = sockets_.begin(); it != sockets_.end(); ++it) |
| 414 it->second->StopRtpDump(incoming, outgoing); | 420 it->second->StopRtpDump(incoming, outgoing); |
| 415 } | 421 } |
| 416 } | 422 } |
| 417 | 423 |
| 418 } // namespace content | 424 } // namespace content |
| OLD | NEW |