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