Chromium Code Reviews| 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
| 13 #include "net/base/load_flags.h" | 13 #include "net/base/load_flags.h" |
| 14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 #include "net/http/http_network_session.h" | 15 #include "net/http/http_network_session.h" |
| 16 #include "net/http/http_transaction_factory.h" | |
| 16 #include "net/socket/client_socket_handle.h" | 17 #include "net/socket/client_socket_handle.h" |
| 17 #include "net/socket/client_socket_pool_manager.h" | 18 #include "net/socket/client_socket_pool_manager.h" |
| 18 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
| 19 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
| 20 | 21 |
| 21 namespace jingle_glue { | 22 namespace jingle_glue { |
| 22 | 23 |
| 23 ProxyResolvingClientSocket::ProxyResolvingClientSocket( | 24 ProxyResolvingClientSocket::ProxyResolvingClientSocket( |
| 24 net::ClientSocketFactory* socket_factory, | 25 net::ClientSocketFactory* socket_factory, |
| 25 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, | 26 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 52 DCHECK(proxy_url_.is_valid()); | 53 DCHECK(proxy_url_.is_valid()); |
| 53 | 54 |
| 54 net::HttpNetworkSession::Params session_params; | 55 net::HttpNetworkSession::Params session_params; |
| 55 session_params.client_socket_factory = socket_factory; | 56 session_params.client_socket_factory = socket_factory; |
| 56 session_params.host_resolver = request_context->host_resolver(); | 57 session_params.host_resolver = request_context->host_resolver(); |
| 57 session_params.cert_verifier = request_context->cert_verifier(); | 58 session_params.cert_verifier = request_context->cert_verifier(); |
| 58 session_params.transport_security_state = | 59 session_params.transport_security_state = |
| 59 request_context->transport_security_state(); | 60 request_context->transport_security_state(); |
| 60 // TODO(rkn): This is NULL because ServerBoundCertService is not thread safe. | 61 // TODO(rkn): This is NULL because ServerBoundCertService is not thread safe. |
| 61 session_params.server_bound_cert_service = NULL; | 62 session_params.server_bound_cert_service = NULL; |
| 62 session_params.proxy_service = request_context->proxy_service(); | 63 session_params.proxy_service = request_context->proxy_service(); |
|
Ryan Sleevi
2014/08/23 02:47:12
If you're using the main URLRequestContext, by dup
| |
| 63 session_params.ssl_config_service = request_context->ssl_config_service(); | 64 session_params.ssl_config_service = request_context->ssl_config_service(); |
| 64 session_params.http_auth_handler_factory = | 65 session_params.http_auth_handler_factory = |
| 65 request_context->http_auth_handler_factory(); | 66 request_context->http_auth_handler_factory(); |
| 66 session_params.network_delegate = request_context->network_delegate(); | 67 session_params.network_delegate = request_context->network_delegate(); |
|
Ryan Sleevi
2014/08/23 02:47:12
Just to confirm: This means that extensions can an
| |
| 67 session_params.http_server_properties = | 68 session_params.http_server_properties = |
| 68 request_context->http_server_properties(); | 69 request_context->http_server_properties(); |
| 69 session_params.net_log = request_context->net_log(); | 70 session_params.net_log = request_context->net_log(); |
| 70 | 71 |
| 71 const net::HttpNetworkSession::Params* reference_params = | 72 const net::HttpNetworkSession::Params* reference_params = |
| 72 request_context->GetNetworkSessionParams(); | 73 request_context->GetNetworkSessionParams(); |
| 73 if (reference_params) { | 74 if (reference_params) { |
| 74 // TODO(mmenke): Just copying specific parameters seems highly regression | 75 // TODO(mmenke): Just copying specific parameters seems highly regression |
| 75 // prone. Should have a better way to do this. | 76 // prone. Should have a better way to do this. |
| 76 session_params.host_mapping_rules = reference_params->host_mapping_rules; | 77 session_params.host_mapping_rules = reference_params->host_mapping_rules; |
| 77 session_params.ignore_certificate_errors = | 78 session_params.ignore_certificate_errors = |
| 78 reference_params->ignore_certificate_errors; | 79 reference_params->ignore_certificate_errors; |
| 79 session_params.testing_fixed_http_port = | 80 session_params.testing_fixed_http_port = |
| 80 reference_params->testing_fixed_http_port; | 81 reference_params->testing_fixed_http_port; |
| 81 session_params.testing_fixed_https_port = | 82 session_params.testing_fixed_https_port = |
| 82 reference_params->testing_fixed_https_port; | 83 reference_params->testing_fixed_https_port; |
| 83 session_params.next_protos = reference_params->next_protos; | 84 session_params.next_protos = reference_params->next_protos; |
| 84 session_params.trusted_spdy_proxy = reference_params->trusted_spdy_proxy; | 85 session_params.trusted_spdy_proxy = reference_params->trusted_spdy_proxy; |
| 85 session_params.force_spdy_over_ssl = reference_params->force_spdy_over_ssl; | 86 session_params.force_spdy_over_ssl = reference_params->force_spdy_over_ssl; |
| 86 session_params.force_spdy_always = reference_params->force_spdy_always; | 87 session_params.force_spdy_always = reference_params->force_spdy_always; |
| 87 session_params.forced_spdy_exclusions = | 88 session_params.forced_spdy_exclusions = |
| 88 reference_params->forced_spdy_exclusions; | 89 reference_params->forced_spdy_exclusions; |
| 89 session_params.use_alternate_protocols = | 90 session_params.use_alternate_protocols = |
| 90 reference_params->use_alternate_protocols; | 91 reference_params->use_alternate_protocols; |
| 91 } | 92 } |
| 92 | 93 |
| 93 network_session_ = new net::HttpNetworkSession(session_params); | 94 network_session_ = new net::HttpNetworkSession(session_params); |
| 95 | |
| 96 net::HttpAuthCache* existing_cache = | |
| 97 request_context->http_transaction_factory() | |
| 98 ->GetSession()->http_auth_cache(); | |
| 99 network_session_->http_auth_cache()->UpdateAllFrom(*existing_cache); | |
|
Ryan Sleevi
2014/08/23 02:47:12
Create your own HttpAuthCache.
Confirm that you r
| |
| 94 } | 100 } |
| 95 | 101 |
| 96 ProxyResolvingClientSocket::~ProxyResolvingClientSocket() { | 102 ProxyResolvingClientSocket::~ProxyResolvingClientSocket() { |
| 97 Disconnect(); | 103 Disconnect(); |
| 98 } | 104 } |
| 99 | 105 |
| 100 int ProxyResolvingClientSocket::Read(net::IOBuffer* buf, int buf_len, | 106 int ProxyResolvingClientSocket::Read(net::IOBuffer* buf, int buf_len, |
| 101 const net::CompletionCallback& callback) { | 107 const net::CompletionCallback& callback) { |
| 102 if (transport_.get() && transport_->socket()) | 108 if (transport_.get() && transport_->socket()) |
| 103 return transport_->socket()->Read(buf, buf_len, callback); | 109 return transport_->socket()->Read(buf, buf_len, callback); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 proxy_url_, | 146 proxy_url_, |
| 141 net::LOAD_NORMAL, | 147 net::LOAD_NORMAL, |
| 142 &proxy_info_, | 148 &proxy_info_, |
| 143 proxy_resolve_callback_, | 149 proxy_resolve_callback_, |
| 144 &pac_request_, | 150 &pac_request_, |
| 145 NULL, | 151 NULL, |
| 146 bound_net_log_); | 152 bound_net_log_); |
| 147 if (status != net::ERR_IO_PENDING) { | 153 if (status != net::ERR_IO_PENDING) { |
| 148 // We defer execution of ProcessProxyResolveDone instead of calling it | 154 // We defer execution of ProcessProxyResolveDone instead of calling it |
| 149 // directly here for simplicity. From the caller's point of view, | 155 // directly here for simplicity. From the caller's point of view, |
| 150 // the connect always happens asynchronously. | 156 // the connect always happens asynchronously. |
|
Ryan Sleevi
2014/08/23 02:47:12
We should fix this at some point.
This is seen as
| |
| 151 base::MessageLoop* message_loop = base::MessageLoop::current(); | 157 base::MessageLoop* message_loop = base::MessageLoop::current(); |
| 152 CHECK(message_loop); | 158 CHECK(message_loop); |
| 153 message_loop->PostTask( | 159 message_loop->PostTask( |
| 154 FROM_HERE, | 160 FROM_HERE, |
| 155 base::Bind(&ProxyResolvingClientSocket::ProcessProxyResolveDone, | 161 base::Bind(&ProxyResolvingClientSocket::ProcessProxyResolveDone, |
| 156 weak_factory_.GetWeakPtr(), status)); | 162 weak_factory_.GetWeakPtr(), status)); |
| 157 } | 163 } |
| 158 user_connect_callback_ = callback; | 164 user_connect_callback_ = callback; |
| 159 return net::ERR_IO_PENDING; | 165 return net::ERR_IO_PENDING; |
| 160 } | 166 } |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 | 299 |
| 294 // We either have new proxy info or there was an error in falling back. | 300 // We either have new proxy info or there was an error in falling back. |
| 295 // In both cases we want to post ProcessProxyResolveDone (in the error case | 301 // In both cases we want to post ProcessProxyResolveDone (in the error case |
| 296 // we might still want to fall back a direct connection). | 302 // we might still want to fall back a direct connection). |
| 297 if (rv != net::ERR_IO_PENDING) { | 303 if (rv != net::ERR_IO_PENDING) { |
| 298 base::MessageLoop* message_loop = base::MessageLoop::current(); | 304 base::MessageLoop* message_loop = base::MessageLoop::current(); |
| 299 CHECK(message_loop); | 305 CHECK(message_loop); |
| 300 message_loop->PostTask( | 306 message_loop->PostTask( |
| 301 FROM_HERE, | 307 FROM_HERE, |
| 302 base::Bind(&ProxyResolvingClientSocket::ProcessProxyResolveDone, | 308 base::Bind(&ProxyResolvingClientSocket::ProcessProxyResolveDone, |
| 303 weak_factory_.GetWeakPtr(), rv)); | 309 weak_factory_.GetWeakPtr(), rv)); |
|
Ryan Sleevi
2014/08/23 02:47:12
Ditto that this is a bit of an anti-pattern.
| |
| 304 // Since we potentially have another try to go (trying the direct connect) | 310 // Since we potentially have another try to go (trying the direct connect) |
| 305 // set the return code code to ERR_IO_PENDING. | 311 // set the return code code to ERR_IO_PENDING. |
| 306 rv = net::ERR_IO_PENDING; | 312 rv = net::ERR_IO_PENDING; |
| 307 } | 313 } |
| 308 return rv; | 314 return rv; |
| 309 } | 315 } |
| 310 | 316 |
| 311 void ProxyResolvingClientSocket::ReportSuccessfulProxyConnection() { | 317 void ProxyResolvingClientSocket::ReportSuccessfulProxyConnection() { |
| 312 network_session_->proxy_service()->ReportSuccess(proxy_info_); | 318 network_session_->proxy_service()->ReportSuccess(proxy_info_); |
| 313 } | 319 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 return false; | 405 return false; |
| 400 } | 406 } |
| 401 | 407 |
| 402 void ProxyResolvingClientSocket::CloseTransportSocket() { | 408 void ProxyResolvingClientSocket::CloseTransportSocket() { |
| 403 if (transport_.get() && transport_->socket()) | 409 if (transport_.get() && transport_->socket()) |
| 404 transport_->socket()->Disconnect(); | 410 transport_->socket()->Disconnect(); |
| 405 transport_.reset(); | 411 transport_.reset(); |
| 406 } | 412 } |
| 407 | 413 |
| 408 } // namespace jingle_glue | 414 } // namespace jingle_glue |
| OLD | NEW |