Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/notifier/base/proxy_resolving_client_socket.h" | 5 #include "jingle/notifier/base/proxy_resolving_client_socket.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
|
csilv
2011/12/14 20:10:19
#include base/bind_helpers.h
James Hawkins
2011/12/14 20:59:05
Done.
| |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
| 12 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
| 13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 #include "net/http/http_network_session.h" | 14 #include "net/http/http_network_session.h" |
| 15 #include "net/socket/client_socket_handle.h" | 15 #include "net/socket/client_socket_handle.h" |
| 16 #include "net/socket/client_socket_pool_manager.h" | 16 #include "net/socket/client_socket_pool_manager.h" |
| 17 #include "net/url_request/url_request_context.h" | 17 #include "net/url_request/url_request_context.h" |
| 18 #include "net/url_request/url_request_context_getter.h" | 18 #include "net/url_request/url_request_context_getter.h" |
| 19 | 19 |
| 20 namespace notifier { | 20 namespace notifier { |
| 21 | 21 |
| 22 ProxyResolvingClientSocket::ProxyResolvingClientSocket( | 22 ProxyResolvingClientSocket::ProxyResolvingClientSocket( |
| 23 net::ClientSocketFactory* socket_factory, | 23 net::ClientSocketFactory* socket_factory, |
| 24 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, | 24 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, |
| 25 const net::SSLConfig& ssl_config, | 25 const net::SSLConfig& ssl_config, |
| 26 const net::HostPortPair& dest_host_port_pair) | 26 const net::HostPortPair& dest_host_port_pair) |
| 27 : proxy_resolve_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this), | 27 : ALLOW_THIS_IN_INITIALIZER_LIST(proxy_resolve_callback_( |
| 28 &ProxyResolvingClientSocket::ProcessProxyResolveDone), | 28 base::Bind(&ProxyResolvingClientSocket::ProcessProxyResolveDone, |
| 29 connect_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this), | 29 base::Unretained(this)))), |
| 30 &ProxyResolvingClientSocket::ProcessConnectDone), | 30 ALLOW_THIS_IN_INITIALIZER_LIST(connect_callback_( |
| 31 base::Bind(&ProxyResolvingClientSocket::ProcessConnectDone, | |
| 32 base::Unretained(this)))), | |
| 31 ssl_config_(ssl_config), | 33 ssl_config_(ssl_config), |
| 32 pac_request_(NULL), | 34 pac_request_(NULL), |
| 33 dest_host_port_pair_(dest_host_port_pair), | 35 dest_host_port_pair_(dest_host_port_pair), |
| 34 tried_direct_connect_fallback_(false), | 36 tried_direct_connect_fallback_(false), |
| 35 bound_net_log_( | 37 bound_net_log_( |
| 36 net::BoundNetLog::Make( | 38 net::BoundNetLog::Make( |
| 37 request_context_getter->GetURLRequestContext()->net_log(), | 39 request_context_getter->GetURLRequestContext()->net_log(), |
| 38 net::NetLog::SOURCE_SOCKET)), | 40 net::NetLog::SOURCE_SOCKET)), |
| 39 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 41 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 40 DCHECK(request_context_getter); | 42 DCHECK(request_context_getter); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 const net::CompletionCallback& callback) { | 104 const net::CompletionCallback& callback) { |
| 103 DCHECK(user_connect_callback_.is_null()); | 105 DCHECK(user_connect_callback_.is_null()); |
| 104 | 106 |
| 105 tried_direct_connect_fallback_ = false; | 107 tried_direct_connect_fallback_ = false; |
| 106 | 108 |
| 107 // First we try and resolve the proxy. | 109 // First we try and resolve the proxy. |
| 108 GURL url("http://" + dest_host_port_pair_.ToString()); | 110 GURL url("http://" + dest_host_port_pair_.ToString()); |
| 109 int status = network_session_->proxy_service()->ResolveProxy( | 111 int status = network_session_->proxy_service()->ResolveProxy( |
| 110 url, | 112 url, |
| 111 &proxy_info_, | 113 &proxy_info_, |
| 112 &proxy_resolve_callback_, | 114 proxy_resolve_callback_, |
| 113 &pac_request_, | 115 &pac_request_, |
| 114 bound_net_log_); | 116 bound_net_log_); |
| 115 if (status != net::ERR_IO_PENDING) { | 117 if (status != net::ERR_IO_PENDING) { |
| 116 // We defer execution of ProcessProxyResolveDone instead of calling it | 118 // We defer execution of ProcessProxyResolveDone instead of calling it |
| 117 // directly here for simplicity. From the caller's point of view, | 119 // directly here for simplicity. From the caller's point of view, |
| 118 // the connect always happens asynchronously. | 120 // the connect always happens asynchronously. |
| 119 MessageLoop* message_loop = MessageLoop::current(); | 121 MessageLoop* message_loop = MessageLoop::current(); |
| 120 CHECK(message_loop); | 122 CHECK(message_loop); |
| 121 message_loop->PostTask( | 123 message_loop->PostTask( |
| 122 FROM_HERE, | 124 FROM_HERE, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 } else { | 164 } else { |
| 163 CloseTransportSocket(); | 165 CloseTransportSocket(); |
| 164 RunUserConnectCallback(status); | 166 RunUserConnectCallback(status); |
| 165 return; | 167 return; |
| 166 } | 168 } |
| 167 } | 169 } |
| 168 | 170 |
| 169 transport_.reset(new net::ClientSocketHandle); | 171 transport_.reset(new net::ClientSocketHandle); |
| 170 // Now that we have resolved the proxy, we need to connect. | 172 // Now that we have resolved the proxy, we need to connect. |
| 171 status = net::InitSocketHandleForRawConnect( | 173 status = net::InitSocketHandleForRawConnect( |
| 172 dest_host_port_pair_, | 174 dest_host_port_pair_, network_session_.get(), proxy_info_, ssl_config_, |
| 173 network_session_.get(), | 175 ssl_config_, bound_net_log_, transport_.get(), connect_callback_); |
| 174 proxy_info_, | |
| 175 ssl_config_, | |
| 176 ssl_config_, | |
| 177 bound_net_log_, | |
| 178 transport_.get(), | |
| 179 &connect_callback_); | |
| 180 if (status != net::ERR_IO_PENDING) { | 176 if (status != net::ERR_IO_PENDING) { |
| 181 // Since this method is always called asynchronously. it is OK to call | 177 // Since this method is always called asynchronously. it is OK to call |
| 182 // ProcessConnectDone synchronously. | 178 // ProcessConnectDone synchronously. |
| 183 ProcessConnectDone(status); | 179 ProcessConnectDone(status); |
| 184 } | 180 } |
| 185 } | 181 } |
| 186 | 182 |
| 187 void ProxyResolvingClientSocket::ProcessConnectDone(int status) { | 183 void ProxyResolvingClientSocket::ProcessConnectDone(int status) { |
| 188 if (status != net::OK) { | 184 if (status != net::OK) { |
| 189 // If the connection fails, try another proxy. | 185 // If the connection fails, try another proxy. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 return error; | 243 return error; |
| 248 } | 244 } |
| 249 | 245 |
| 250 if (proxy_info_.is_https() && ssl_config_.send_client_cert) { | 246 if (proxy_info_.is_https() && ssl_config_.send_client_cert) { |
| 251 network_session_->ssl_client_auth_cache()->Remove( | 247 network_session_->ssl_client_auth_cache()->Remove( |
| 252 proxy_info_.proxy_server().host_port_pair().ToString()); | 248 proxy_info_.proxy_server().host_port_pair().ToString()); |
| 253 } | 249 } |
| 254 | 250 |
| 255 GURL url("http://" + dest_host_port_pair_.ToString()); | 251 GURL url("http://" + dest_host_port_pair_.ToString()); |
| 256 int rv = network_session_->proxy_service()->ReconsiderProxyAfterError( | 252 int rv = network_session_->proxy_service()->ReconsiderProxyAfterError( |
| 257 url, &proxy_info_, &proxy_resolve_callback_, &pac_request_, | 253 url, &proxy_info_, proxy_resolve_callback_, &pac_request_, |
| 258 bound_net_log_); | 254 bound_net_log_); |
| 259 if (rv == net::OK || rv == net::ERR_IO_PENDING) { | 255 if (rv == net::OK || rv == net::ERR_IO_PENDING) { |
| 260 CloseTransportSocket(); | 256 CloseTransportSocket(); |
| 261 } else { | 257 } else { |
| 262 // If ReconsiderProxyAfterError() failed synchronously, it means | 258 // If ReconsiderProxyAfterError() failed synchronously, it means |
| 263 // there was nothing left to fall-back to, so fail the transaction | 259 // there was nothing left to fall-back to, so fail the transaction |
| 264 // with the last connection error we got. | 260 // with the last connection error we got. |
| 265 rv = error; | 261 rv = error; |
| 266 } | 262 } |
| 267 | 263 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 370 return base::TimeDelta::FromMicroseconds(-1); | 366 return base::TimeDelta::FromMicroseconds(-1); |
| 371 } | 367 } |
| 372 | 368 |
| 373 void ProxyResolvingClientSocket::CloseTransportSocket() { | 369 void ProxyResolvingClientSocket::CloseTransportSocket() { |
| 374 if (transport_.get() && transport_->socket()) | 370 if (transport_.get() && transport_->socket()) |
| 375 transport_->socket()->Disconnect(); | 371 transport_->socket()->Disconnect(); |
| 376 transport_.reset(); | 372 transport_.reset(); |
| 377 } | 373 } |
| 378 | 374 |
| 379 } // namespace notifier | 375 } // namespace notifier |
| OLD | NEW |