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 "jingle/glue/proxy_resolving_client_socket.h" | 5 #include "jingle/glue/proxy_resolving_client_socket.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 connect_callback_( | 37 connect_callback_( |
38 base::Bind(&ProxyResolvingClientSocket::ProcessConnectDone, | 38 base::Bind(&ProxyResolvingClientSocket::ProcessConnectDone, |
39 base::Unretained(this))), | 39 base::Unretained(this))), |
40 ssl_config_(ssl_config), | 40 ssl_config_(ssl_config), |
41 pac_request_(NULL), | 41 pac_request_(NULL), |
42 dest_host_port_pair_(dest_host_port_pair), | 42 dest_host_port_pair_(dest_host_port_pair), |
43 // Assume that we intend to do TLS on this socket; all | 43 // Assume that we intend to do TLS on this socket; all |
44 // current use cases do. | 44 // current use cases do. |
45 proxy_url_("https://" + dest_host_port_pair_.ToString()), | 45 proxy_url_("https://" + dest_host_port_pair_.ToString()), |
46 tried_direct_connect_fallback_(false), | 46 tried_direct_connect_fallback_(false), |
47 bound_net_log_(net::BoundNetLog::Make( | 47 net_log_(net::NetLogWithSource::Make( |
48 request_context_getter->GetURLRequestContext()->net_log(), | 48 request_context_getter->GetURLRequestContext()->net_log(), |
49 net::NetLogSourceType::SOCKET)), | 49 net::NetLogSourceType::SOCKET)), |
50 weak_factory_(this) { | 50 weak_factory_(this) { |
51 DCHECK(request_context_getter.get()); | 51 DCHECK(request_context_getter.get()); |
52 net::URLRequestContext* request_context = | 52 net::URLRequestContext* request_context = |
53 request_context_getter->GetURLRequestContext(); | 53 request_context_getter->GetURLRequestContext(); |
54 DCHECK(request_context); | 54 DCHECK(request_context); |
55 DCHECK(!dest_host_port_pair_.host().empty()); | 55 DCHECK(!dest_host_port_pair_.host().empty()); |
56 DCHECK_GT(dest_host_port_pair_.port(), 0); | 56 DCHECK_GT(dest_host_port_pair_.port(), 0); |
57 DCHECK(proxy_url_.is_valid()); | 57 DCHECK(proxy_url_.is_valid()); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 tried_direct_connect_fallback_ = false; | 140 tried_direct_connect_fallback_ = false; |
141 | 141 |
142 // First we try and resolve the proxy. | 142 // First we try and resolve the proxy. |
143 int status = network_session_->proxy_service()->ResolveProxy( | 143 int status = network_session_->proxy_service()->ResolveProxy( |
144 proxy_url_, | 144 proxy_url_, |
145 std::string(), | 145 std::string(), |
146 &proxy_info_, | 146 &proxy_info_, |
147 proxy_resolve_callback_, | 147 proxy_resolve_callback_, |
148 &pac_request_, | 148 &pac_request_, |
149 NULL, | 149 NULL, |
150 bound_net_log_); | 150 net_log_); |
151 if (status != net::ERR_IO_PENDING) { | 151 if (status != net::ERR_IO_PENDING) { |
152 // We defer execution of ProcessProxyResolveDone instead of calling it | 152 // We defer execution of ProcessProxyResolveDone instead of calling it |
153 // directly here for simplicity. From the caller's point of view, | 153 // directly here for simplicity. From the caller's point of view, |
154 // the connect always happens asynchronously. | 154 // the connect always happens asynchronously. |
155 base::ThreadTaskRunnerHandle::Get()->PostTask( | 155 base::ThreadTaskRunnerHandle::Get()->PostTask( |
156 FROM_HERE, | 156 FROM_HERE, |
157 base::Bind(&ProxyResolvingClientSocket::ProcessProxyResolveDone, | 157 base::Bind(&ProxyResolvingClientSocket::ProcessProxyResolveDone, |
158 weak_factory_.GetWeakPtr(), status)); | 158 weak_factory_.GetWeakPtr(), status)); |
159 } | 159 } |
160 user_connect_callback_ = callback; | 160 user_connect_callback_ = callback; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 CloseTransportSocket(); | 197 CloseTransportSocket(); |
198 RunUserConnectCallback(status); | 198 RunUserConnectCallback(status); |
199 return; | 199 return; |
200 } | 200 } |
201 } | 201 } |
202 | 202 |
203 transport_.reset(new net::ClientSocketHandle); | 203 transport_.reset(new net::ClientSocketHandle); |
204 // Now that we have resolved the proxy, we need to connect. | 204 // Now that we have resolved the proxy, we need to connect. |
205 status = net::InitSocketHandleForRawConnect( | 205 status = net::InitSocketHandleForRawConnect( |
206 dest_host_port_pair_, network_session_.get(), proxy_info_, ssl_config_, | 206 dest_host_port_pair_, network_session_.get(), proxy_info_, ssl_config_, |
207 ssl_config_, net::PRIVACY_MODE_DISABLED, bound_net_log_, transport_.get(), | 207 ssl_config_, net::PRIVACY_MODE_DISABLED, net_log_, transport_.get(), |
208 connect_callback_); | 208 connect_callback_); |
209 if (status != net::ERR_IO_PENDING) { | 209 if (status != net::ERR_IO_PENDING) { |
210 // Since this method is always called asynchronously. it is OK to call | 210 // Since this method is always called asynchronously. it is OK to call |
211 // ProcessConnectDone synchronously. | 211 // ProcessConnectDone synchronously. |
212 ProcessConnectDone(status); | 212 ProcessConnectDone(status); |
213 } | 213 } |
214 } | 214 } |
215 | 215 |
216 void ProxyResolvingClientSocket::ProcessConnectDone(int status) { | 216 void ProxyResolvingClientSocket::ProcessConnectDone(int status) { |
217 if (status != net::OK) { | 217 if (status != net::OK) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 return error; | 285 return error; |
286 } | 286 } |
287 | 287 |
288 if (proxy_info_.is_https() && ssl_config_.send_client_cert) { | 288 if (proxy_info_.is_https() && ssl_config_.send_client_cert) { |
289 network_session_->ssl_client_auth_cache()->Remove( | 289 network_session_->ssl_client_auth_cache()->Remove( |
290 proxy_info_.proxy_server().host_port_pair()); | 290 proxy_info_.proxy_server().host_port_pair()); |
291 } | 291 } |
292 | 292 |
293 int rv = network_session_->proxy_service()->ReconsiderProxyAfterError( | 293 int rv = network_session_->proxy_service()->ReconsiderProxyAfterError( |
294 proxy_url_, std::string(), error, &proxy_info_, proxy_resolve_callback_, | 294 proxy_url_, std::string(), error, &proxy_info_, proxy_resolve_callback_, |
295 &pac_request_, NULL, bound_net_log_); | 295 &pac_request_, NULL, net_log_); |
296 if (rv == net::OK || rv == net::ERR_IO_PENDING) { | 296 if (rv == net::OK || rv == net::ERR_IO_PENDING) { |
297 CloseTransportSocket(); | 297 CloseTransportSocket(); |
298 } else { | 298 } else { |
299 // If ReconsiderProxyAfterError() failed synchronously, it means | 299 // If ReconsiderProxyAfterError() failed synchronously, it means |
300 // there was nothing left to fall-back to, so fail the transaction | 300 // there was nothing left to fall-back to, so fail the transaction |
301 // with the last connection error we got. | 301 // with the last connection error we got. |
302 rv = error; | 302 rv = error; |
303 } | 303 } |
304 | 304 |
305 // We either have new proxy info or there was an error in falling back. | 305 // We either have new proxy info or there was an error in falling back. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 } | 363 } |
364 | 364 |
365 int ProxyResolvingClientSocket::GetLocalAddress( | 365 int ProxyResolvingClientSocket::GetLocalAddress( |
366 net::IPEndPoint* address) const { | 366 net::IPEndPoint* address) const { |
367 if (transport_.get() && transport_->socket()) | 367 if (transport_.get() && transport_->socket()) |
368 return transport_->socket()->GetLocalAddress(address); | 368 return transport_->socket()->GetLocalAddress(address); |
369 NOTREACHED(); | 369 NOTREACHED(); |
370 return net::ERR_SOCKET_NOT_CONNECTED; | 370 return net::ERR_SOCKET_NOT_CONNECTED; |
371 } | 371 } |
372 | 372 |
373 const net::BoundNetLog& ProxyResolvingClientSocket::NetLog() const { | 373 const net::NetLogWithSource& ProxyResolvingClientSocket::NetLog() const { |
374 if (transport_.get() && transport_->socket()) | 374 if (transport_.get() && transport_->socket()) |
375 return transport_->socket()->NetLog(); | 375 return transport_->socket()->NetLog(); |
376 NOTREACHED(); | 376 NOTREACHED(); |
377 return bound_net_log_; | 377 return net_log_; |
378 } | 378 } |
379 | 379 |
380 void ProxyResolvingClientSocket::SetSubresourceSpeculation() { | 380 void ProxyResolvingClientSocket::SetSubresourceSpeculation() { |
381 if (transport_.get() && transport_->socket()) | 381 if (transport_.get() && transport_->socket()) |
382 transport_->socket()->SetSubresourceSpeculation(); | 382 transport_->socket()->SetSubresourceSpeculation(); |
383 else | 383 else |
384 NOTREACHED(); | 384 NOTREACHED(); |
385 } | 385 } |
386 | 386 |
387 void ProxyResolvingClientSocket::SetOmniboxSpeculation() { | 387 void ProxyResolvingClientSocket::SetOmniboxSpeculation() { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 return 0; | 423 return 0; |
424 } | 424 } |
425 | 425 |
426 void ProxyResolvingClientSocket::CloseTransportSocket() { | 426 void ProxyResolvingClientSocket::CloseTransportSocket() { |
427 if (transport_.get() && transport_->socket()) | 427 if (transport_.get() && transport_->socket()) |
428 transport_->socket()->Disconnect(); | 428 transport_->socket()->Disconnect(); |
429 transport_.reset(); | 429 transport_.reset(); |
430 } | 430 } |
431 | 431 |
432 } // namespace jingle_glue | 432 } // namespace jingle_glue |
OLD | NEW |