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 "net/http/http_stream_factory_impl_job.h" | 5 #include "net/http/http_stream_factory_impl_job.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 return | 434 return |
435 spdy_session_pool->FindAvailableSession(spdy_session_key, net_log) ? | 435 spdy_session_pool->FindAvailableSession(spdy_session_key, net_log) ? |
436 ERR_SPDY_SESSION_ALREADY_EXISTS : OK; | 436 ERR_SPDY_SESSION_ALREADY_EXISTS : OK; |
437 } | 437 } |
438 | 438 |
439 void HttpStreamFactoryImpl::Job::OnIOComplete(int result) { | 439 void HttpStreamFactoryImpl::Job::OnIOComplete(int result) { |
440 RunLoop(result); | 440 RunLoop(result); |
441 } | 441 } |
442 | 442 |
443 int HttpStreamFactoryImpl::Job::RunLoop(int result) { | 443 int HttpStreamFactoryImpl::Job::RunLoop(int result) { |
444 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455884 is fixed. | |
445 tracked_objects::ScopedTracker tracking_profile( | |
446 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
447 "455884 HttpStreamFactoryImpl::Job::RunLoop")); | |
448 result = DoLoop(result); | 444 result = DoLoop(result); |
449 | 445 |
450 if (result == ERR_IO_PENDING) | 446 if (result == ERR_IO_PENDING) |
451 return result; | 447 return result; |
452 | 448 |
453 // If there was an error, we should have already resumed the |waiting_job_|, | 449 // If there was an error, we should have already resumed the |waiting_job_|, |
454 // if there was one. | 450 // if there was one. |
455 DCHECK(result == OK || waiting_job_ == NULL); | 451 DCHECK(result == OK || waiting_job_ == NULL); |
456 | 452 |
457 if (IsPreconnecting()) { | 453 if (IsPreconnecting()) { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 | 610 |
615 int HttpStreamFactoryImpl::Job::StartInternal() { | 611 int HttpStreamFactoryImpl::Job::StartInternal() { |
616 CHECK_EQ(STATE_NONE, next_state_); | 612 CHECK_EQ(STATE_NONE, next_state_); |
617 next_state_ = STATE_START; | 613 next_state_ = STATE_START; |
618 int rv = RunLoop(OK); | 614 int rv = RunLoop(OK); |
619 DCHECK_EQ(ERR_IO_PENDING, rv); | 615 DCHECK_EQ(ERR_IO_PENDING, rv); |
620 return rv; | 616 return rv; |
621 } | 617 } |
622 | 618 |
623 int HttpStreamFactoryImpl::Job::DoStart() { | 619 int HttpStreamFactoryImpl::Job::DoStart() { |
624 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455884 is fixed. | |
625 tracked_objects::ScopedTracker tracking_profile( | |
626 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
627 "455884 HttpStreamFactoryImpl::Job::DoStart")); | |
628 origin_ = HostPortPair::FromURL(request_info_.url); | 620 origin_ = HostPortPair::FromURL(request_info_.url); |
629 origin_url_ = stream_factory_->ApplyHostMappingRules( | 621 origin_url_ = stream_factory_->ApplyHostMappingRules( |
630 request_info_.url, &origin_); | 622 request_info_.url, &origin_); |
631 | 623 |
632 net_log_.BeginEvent(NetLog::TYPE_HTTP_STREAM_JOB, | 624 net_log_.BeginEvent(NetLog::TYPE_HTTP_STREAM_JOB, |
633 base::Bind(&NetLogHttpStreamJobCallback, | 625 base::Bind(&NetLogHttpStreamJobCallback, |
634 &request_info_.url, &origin_url_, | 626 &request_info_.url, &origin_url_, |
635 priority_)); | 627 priority_)); |
636 | 628 |
637 // Don't connect to restricted ports. | 629 // Don't connect to restricted ports. |
(...skipping 10 matching lines...) Expand all Loading... |
648 waiting_job_ = NULL; | 640 waiting_job_ = NULL; |
649 } | 641 } |
650 return ERR_UNSAFE_PORT; | 642 return ERR_UNSAFE_PORT; |
651 } | 643 } |
652 | 644 |
653 next_state_ = STATE_RESOLVE_PROXY; | 645 next_state_ = STATE_RESOLVE_PROXY; |
654 return OK; | 646 return OK; |
655 } | 647 } |
656 | 648 |
657 int HttpStreamFactoryImpl::Job::DoResolveProxy() { | 649 int HttpStreamFactoryImpl::Job::DoResolveProxy() { |
658 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455884 is fixed. | |
659 tracked_objects::ScopedTracker tracking_profile( | |
660 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
661 "455884 HttpStreamFactoryImpl::Job::DoResolveProxy")); | |
662 DCHECK(!pac_request_); | 650 DCHECK(!pac_request_); |
663 DCHECK(session_); | 651 DCHECK(session_); |
664 | 652 |
665 next_state_ = STATE_RESOLVE_PROXY_COMPLETE; | 653 next_state_ = STATE_RESOLVE_PROXY_COMPLETE; |
666 | 654 |
667 if (request_info_.load_flags & LOAD_BYPASS_PROXY) { | 655 if (request_info_.load_flags & LOAD_BYPASS_PROXY) { |
668 proxy_info_.UseDirect(); | 656 proxy_info_.UseDirect(); |
669 return OK; | 657 return OK; |
670 } | 658 } |
671 | 659 |
672 return session_->proxy_service()->ResolveProxy( | 660 return session_->proxy_service()->ResolveProxy( |
673 request_info_.url, request_info_.load_flags, &proxy_info_, io_callback_, | 661 request_info_.url, request_info_.load_flags, &proxy_info_, io_callback_, |
674 &pac_request_, session_->network_delegate(), net_log_); | 662 &pac_request_, session_->network_delegate(), net_log_); |
675 } | 663 } |
676 | 664 |
677 int HttpStreamFactoryImpl::Job::DoResolveProxyComplete(int result) { | 665 int HttpStreamFactoryImpl::Job::DoResolveProxyComplete(int result) { |
678 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455884 is fixed. | |
679 tracked_objects::ScopedTracker tracking_profile( | |
680 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
681 "455884 HttpStreamFactoryImpl::Job::DoResolveProxyComplete")); | |
682 pac_request_ = NULL; | 666 pac_request_ = NULL; |
683 | 667 |
684 if (result == OK) { | 668 if (result == OK) { |
685 // Remove unsupported proxies from the list. | 669 // Remove unsupported proxies from the list. |
686 int supported_proxies = | 670 int supported_proxies = |
687 ProxyServer::SCHEME_DIRECT | ProxyServer::SCHEME_HTTP | | 671 ProxyServer::SCHEME_DIRECT | ProxyServer::SCHEME_HTTP | |
688 ProxyServer::SCHEME_HTTPS | ProxyServer::SCHEME_SOCKS4 | | 672 ProxyServer::SCHEME_HTTPS | ProxyServer::SCHEME_SOCKS4 | |
689 ProxyServer::SCHEME_SOCKS5; | 673 ProxyServer::SCHEME_SOCKS5; |
690 | 674 |
691 if (session_->params().enable_quic_for_proxies) | 675 if (session_->params().enable_quic_for_proxies) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 } | 729 } |
746 | 730 |
747 int HttpStreamFactoryImpl::Job::DoWaitForJobComplete(int result) { | 731 int HttpStreamFactoryImpl::Job::DoWaitForJobComplete(int result) { |
748 DCHECK(!blocking_job_); | 732 DCHECK(!blocking_job_); |
749 DCHECK_EQ(OK, result); | 733 DCHECK_EQ(OK, result); |
750 next_state_ = STATE_INIT_CONNECTION; | 734 next_state_ = STATE_INIT_CONNECTION; |
751 return OK; | 735 return OK; |
752 } | 736 } |
753 | 737 |
754 int HttpStreamFactoryImpl::Job::DoInitConnection() { | 738 int HttpStreamFactoryImpl::Job::DoInitConnection() { |
755 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455884 is fixed. | 739 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462812 is fixed. |
756 tracked_objects::ScopedTracker tracking_profile( | 740 tracked_objects::ScopedTracker tracking_profile( |
757 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 741 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
758 "455884 HttpStreamFactoryImpl::Job::DoInitConnection")); | 742 "462812 HttpStreamFactoryImpl::Job::DoInitConnection")); |
759 DCHECK(!blocking_job_); | 743 DCHECK(!blocking_job_); |
760 DCHECK(!connection_->is_initialized()); | 744 DCHECK(!connection_->is_initialized()); |
761 DCHECK(proxy_info_.proxy_server().is_valid()); | 745 DCHECK(proxy_info_.proxy_server().is_valid()); |
762 next_state_ = STATE_INIT_CONNECTION_COMPLETE; | 746 next_state_ = STATE_INIT_CONNECTION_COMPLETE; |
763 | 747 |
764 using_ssl_ = request_info_.url.SchemeIs("https") || | 748 using_ssl_ = request_info_.url.SchemeIs("https") || |
765 request_info_.url.SchemeIs("wss") || ShouldForceSpdySSL(); | 749 request_info_.url.SchemeIs("wss") || ShouldForceSpdySSL(); |
766 using_spdy_ = false; | 750 using_spdy_ = false; |
767 | 751 |
768 if (ShouldForceQuic()) | 752 if (ShouldForceQuic()) |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 | 880 |
897 return InitSocketHandleForHttpRequest( | 881 return InitSocketHandleForHttpRequest( |
898 origin_url_, request_info_.extra_headers, request_info_.load_flags, | 882 origin_url_, request_info_.extra_headers, request_info_.load_flags, |
899 priority_, session_, proxy_info_, ShouldForceSpdySSL(), | 883 priority_, session_, proxy_info_, ShouldForceSpdySSL(), |
900 want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, | 884 want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, |
901 request_info_.privacy_mode, net_log_, | 885 request_info_.privacy_mode, net_log_, |
902 connection_.get(), resolution_callback, io_callback_); | 886 connection_.get(), resolution_callback, io_callback_); |
903 } | 887 } |
904 | 888 |
905 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { | 889 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { |
906 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455884 is fixed. | |
907 tracked_objects::ScopedTracker tracking_profile( | |
908 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
909 "455884 HttpStreamFactoryImpl::Job::DoInitConnectionComplete")); | |
910 if (IsPreconnecting()) { | 890 if (IsPreconnecting()) { |
911 if (using_quic_) | 891 if (using_quic_) |
912 return result; | 892 return result; |
913 DCHECK_EQ(OK, result); | 893 DCHECK_EQ(OK, result); |
914 return OK; | 894 return OK; |
915 } | 895 } |
916 | 896 |
917 if (result == ERR_SPDY_SESSION_ALREADY_EXISTS) { | 897 if (result == ERR_SPDY_SESSION_ALREADY_EXISTS) { |
918 // We found a SPDY connection after resolving the host. This is | 898 // We found a SPDY connection after resolving the host. This is |
919 // probably an IP pooled connection. | 899 // probably an IP pooled connection. |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 // TODO(willchan): Delete this code, because eventually, the | 1066 // TODO(willchan): Delete this code, because eventually, the |
1087 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it | 1067 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it |
1088 // will know when SpdySessions become available. | 1068 // will know when SpdySessions become available. |
1089 | 1069 |
1090 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); | 1070 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); |
1091 stream_.reset(new SpdyHttpStream(session, use_relative_url)); | 1071 stream_.reset(new SpdyHttpStream(session, use_relative_url)); |
1092 return OK; | 1072 return OK; |
1093 } | 1073 } |
1094 | 1074 |
1095 int HttpStreamFactoryImpl::Job::DoCreateStream() { | 1075 int HttpStreamFactoryImpl::Job::DoCreateStream() { |
1096 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455884 is fixed. | 1076 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462811 is fixed. |
1097 tracked_objects::ScopedTracker tracking_profile( | 1077 tracked_objects::ScopedTracker tracking_profile( |
1098 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1078 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
1099 "455884 HttpStreamFactoryImpl::Job::DoCreateStream")); | 1079 "462811 HttpStreamFactoryImpl::Job::DoCreateStream")); |
1100 DCHECK(connection_->socket() || existing_spdy_session_.get() || using_quic_); | 1080 DCHECK(connection_->socket() || existing_spdy_session_.get() || using_quic_); |
1101 | 1081 |
1102 next_state_ = STATE_CREATE_STREAM_COMPLETE; | 1082 next_state_ = STATE_CREATE_STREAM_COMPLETE; |
1103 | 1083 |
1104 // We only set the socket motivation if we're the first to use | 1084 // We only set the socket motivation if we're the first to use |
1105 // this socket. Is there a race for two SPDY requests? We really | 1085 // this socket. Is there a race for two SPDY requests? We really |
1106 // need to plumb this through to the connect level. | 1086 // need to plumb this through to the connect level. |
1107 if (connection_->socket() && !connection_->is_reused()) | 1087 if (connection_->socket() && !connection_->is_reused()) |
1108 SetSocketMotivation(); | 1088 SetSocketMotivation(); |
1109 | 1089 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 | 1163 |
1184 // Create a SpdyHttpStream attached to the session; | 1164 // Create a SpdyHttpStream attached to the session; |
1185 // OnNewSpdySessionReadyCallback is not called until an event loop | 1165 // OnNewSpdySessionReadyCallback is not called until an event loop |
1186 // iteration later, so if the SpdySession is closed between then, allow | 1166 // iteration later, so if the SpdySession is closed between then, allow |
1187 // reuse state from the underlying socket, sampled by SpdyHttpStream, | 1167 // reuse state from the underlying socket, sampled by SpdyHttpStream, |
1188 // bubble up to the request. | 1168 // bubble up to the request. |
1189 return SetSpdyHttpStream(new_spdy_session_, spdy_session_direct_); | 1169 return SetSpdyHttpStream(new_spdy_session_, spdy_session_direct_); |
1190 } | 1170 } |
1191 | 1171 |
1192 int HttpStreamFactoryImpl::Job::DoCreateStreamComplete(int result) { | 1172 int HttpStreamFactoryImpl::Job::DoCreateStreamComplete(int result) { |
1193 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455884 is fixed. | |
1194 tracked_objects::ScopedTracker tracking_profile( | |
1195 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
1196 "455884 HttpStreamFactoryImpl::Job::DoCreateStreamComplete")); | |
1197 if (result < 0) | 1173 if (result < 0) |
1198 return result; | 1174 return result; |
1199 | 1175 |
1200 session_->proxy_service()->ReportSuccess(proxy_info_, | 1176 session_->proxy_service()->ReportSuccess(proxy_info_, |
1201 session_->network_delegate()); | 1177 session_->network_delegate()); |
1202 next_state_ = STATE_NONE; | 1178 next_state_ = STATE_NONE; |
1203 return OK; | 1179 return OK; |
1204 } | 1180 } |
1205 | 1181 |
1206 int HttpStreamFactoryImpl::Job::DoRestartTunnelAuth() { | 1182 int HttpStreamFactoryImpl::Job::DoRestartTunnelAuth() { |
1207 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455884 is fixed. | |
1208 tracked_objects::ScopedTracker tracking_profile( | |
1209 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
1210 "455884 HttpStreamFactoryImpl::Job::DoRestartTunnelAuth")); | |
1211 next_state_ = STATE_RESTART_TUNNEL_AUTH_COMPLETE; | 1183 next_state_ = STATE_RESTART_TUNNEL_AUTH_COMPLETE; |
1212 ProxyClientSocket* proxy_socket = | 1184 ProxyClientSocket* proxy_socket = |
1213 static_cast<ProxyClientSocket*>(connection_->socket()); | 1185 static_cast<ProxyClientSocket*>(connection_->socket()); |
1214 return proxy_socket->RestartWithAuth(io_callback_); | 1186 return proxy_socket->RestartWithAuth(io_callback_); |
1215 } | 1187 } |
1216 | 1188 |
1217 int HttpStreamFactoryImpl::Job::DoRestartTunnelAuthComplete(int result) { | 1189 int HttpStreamFactoryImpl::Job::DoRestartTunnelAuthComplete(int result) { |
1218 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455884 is fixed. | |
1219 tracked_objects::ScopedTracker tracking_profile( | |
1220 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
1221 "455884 HttpStreamFactoryImpl::Job::DoRestartTunnelAuthComplete")); | |
1222 if (result == ERR_PROXY_AUTH_REQUESTED) | 1190 if (result == ERR_PROXY_AUTH_REQUESTED) |
1223 return result; | 1191 return result; |
1224 | 1192 |
1225 if (result == OK) { | 1193 if (result == OK) { |
1226 // Now that we've got the HttpProxyClientSocket connected. We have | 1194 // Now that we've got the HttpProxyClientSocket connected. We have |
1227 // to release it as an idle socket into the pool and start the connection | 1195 // to release it as an idle socket into the pool and start the connection |
1228 // process from the beginning. Trying to pass it in with the | 1196 // process from the beginning. Trying to pass it in with the |
1229 // SSLSocketParams might cause a deadlock since params are dispatched | 1197 // SSLSocketParams might cause a deadlock since params are dispatched |
1230 // interchangeably. This request won't necessarily get this http proxy | 1198 // interchangeably. This request won't necessarily get this http proxy |
1231 // socket, but there will be forward progress. | 1199 // socket, but there will be forward progress. |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1534 | 1502 |
1535 if (job_status_ == STATUS_SUCCEEDED && other_job_status_ == STATUS_BROKEN) { | 1503 if (job_status_ == STATUS_SUCCEEDED && other_job_status_ == STATUS_BROKEN) { |
1536 HistogramBrokenAlternateProtocolLocation( | 1504 HistogramBrokenAlternateProtocolLocation( |
1537 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_MAIN); | 1505 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_MAIN); |
1538 session_->http_server_properties()->SetBrokenAlternateProtocol( | 1506 session_->http_server_properties()->SetBrokenAlternateProtocol( |
1539 HostPortPair::FromURL(request_info_.url)); | 1507 HostPortPair::FromURL(request_info_.url)); |
1540 } | 1508 } |
1541 } | 1509 } |
1542 | 1510 |
1543 } // namespace net | 1511 } // namespace net |
OLD | NEW |