| 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" |
| 11 #include "content/public/browser/resource_context.h" | 11 #include "content/public/browser/resource_context.h" |
| 12 #include "net/base/address_list.h" | 12 #include "net/base/address_list.h" |
| 13 #include "net/base/completion_callback.h" | 13 #include "net/base/completion_callback.h" |
| 14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 #include "net/base/net_log.h" | 15 #include "net/base/net_log.h" |
| 16 #include "net/base/sys_addrinfo.h" | 16 #include "net/base/sys_addrinfo.h" |
| 17 #include "net/dns/single_request_host_resolver.h" | 17 #include "net/dns/single_request_host_resolver.h" |
| 18 #include "net/http/http_request_info.h" |
| 19 #include "net/url_request/url_request_context.h" |
| 20 #include "net/url_request/url_request_context_getter.h" |
| 18 | 21 |
| 19 using content::BrowserMessageFilter; | 22 using content::BrowserMessageFilter; |
| 20 using content::BrowserThread; | 23 using content::BrowserThread; |
| 21 | 24 |
| 22 namespace content { | 25 namespace content { |
| 23 | 26 |
| 24 class P2PSocketDispatcherHost::DnsRequest { | 27 class P2PSocketDispatcherHost::DnsRequest { |
| 25 public: | 28 public: |
| 26 typedef base::Callback<void(const net::IPAddressNumber&)> DoneCallback; | 29 typedef base::Callback<void(const net::IPAddressNumber&)> DoneCallback; |
| 27 | 30 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 int32 request_id_; | 79 int32 request_id_; |
| 77 net::AddressList addresses_; | 80 net::AddressList addresses_; |
| 78 | 81 |
| 79 std::string host_name_; | 82 std::string host_name_; |
| 80 net::SingleRequestHostResolver resolver_; | 83 net::SingleRequestHostResolver resolver_; |
| 81 | 84 |
| 82 DoneCallback done_callback_; | 85 DoneCallback done_callback_; |
| 83 }; | 86 }; |
| 84 | 87 |
| 85 P2PSocketDispatcherHost::P2PSocketDispatcherHost( | 88 P2PSocketDispatcherHost::P2PSocketDispatcherHost( |
| 86 content::ResourceContext* resource_context) | 89 content::ResourceContext* resource_context, |
| 90 net::URLRequestContextGetter* getter) |
| 87 : resource_context_(resource_context), | 91 : resource_context_(resource_context), |
| 92 context_getter_(getter), |
| 88 monitoring_networks_(false) { | 93 monitoring_networks_(false) { |
| 89 } | 94 } |
| 90 | 95 |
| 91 void P2PSocketDispatcherHost::OnChannelClosing() { | 96 void P2PSocketDispatcherHost::OnChannelClosing() { |
| 92 BrowserMessageFilter::OnChannelClosing(); | 97 BrowserMessageFilter::OnChannelClosing(); |
| 93 | 98 |
| 94 // Since the IPC channel is gone, close pending connections. | 99 // Since the IPC channel is gone, close pending connections. |
| 95 STLDeleteContainerPairSecondPointers(sockets_.begin(), sockets_.end()); | 100 STLDeleteContainerPairSecondPointers(sockets_.begin(), sockets_.end()); |
| 96 sockets_.clear(); | 101 sockets_.clear(); |
| 97 | 102 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 P2PSocketType type, int socket_id, | 186 P2PSocketType type, int socket_id, |
| 182 const net::IPEndPoint& local_address, | 187 const net::IPEndPoint& local_address, |
| 183 const net::IPEndPoint& remote_address) { | 188 const net::IPEndPoint& remote_address) { |
| 184 if (LookupSocket(socket_id)) { | 189 if (LookupSocket(socket_id)) { |
| 185 LOG(ERROR) << "Received P2PHostMsg_CreateSocket for socket " | 190 LOG(ERROR) << "Received P2PHostMsg_CreateSocket for socket " |
| 186 "that already exists."; | 191 "that already exists."; |
| 187 return; | 192 return; |
| 188 } | 193 } |
| 189 | 194 |
| 190 scoped_ptr<P2PSocketHost> socket( | 195 scoped_ptr<P2PSocketHost> socket( |
| 191 P2PSocketHost::Create(this, socket_id, type)); | 196 P2PSocketHost::Create(this, socket_id, type, context_getter_)); |
| 192 | 197 |
| 193 if (!socket) { | 198 if (!socket) { |
| 194 Send(new P2PMsg_OnError(socket_id)); | 199 Send(new P2PMsg_OnError(socket_id)); |
| 195 return; | 200 return; |
| 196 } | 201 } |
| 197 | 202 |
| 198 if (socket->Init(local_address, remote_address)) { | 203 if (socket->Init(local_address, remote_address)) { |
| 199 sockets_[socket_id] = socket.release(); | 204 sockets_[socket_id] = socket.release(); |
| 200 } | 205 } |
| 201 } | 206 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 void P2PSocketDispatcherHost::OnAddressResolved( | 258 void P2PSocketDispatcherHost::OnAddressResolved( |
| 254 DnsRequest* request, | 259 DnsRequest* request, |
| 255 const net::IPAddressNumber& result) { | 260 const net::IPAddressNumber& result) { |
| 256 Send(new P2PMsg_GetHostAddressResult(request->request_id(), result)); | 261 Send(new P2PMsg_GetHostAddressResult(request->request_id(), result)); |
| 257 | 262 |
| 258 dns_requests_.erase(request); | 263 dns_requests_.erase(request); |
| 259 delete request; | 264 delete request; |
| 260 } | 265 } |
| 261 | 266 |
| 262 } // namespace content | 267 } // namespace content |
| OLD | NEW |