OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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_controller.h" | 5 #include "net/http/http_stream_factory_impl_job_controller.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 DCHECK(!main_job_); | 96 DCHECK(!main_job_); |
97 DCHECK(!alternative_job_); | 97 DCHECK(!alternative_job_); |
98 | 98 |
99 is_preconnect_ = true; | 99 is_preconnect_ = true; |
100 HostPortPair destination(HostPortPair::FromURL(request_info.url)); | 100 HostPortPair destination(HostPortPair::FromURL(request_info.url)); |
101 GURL origin_url = ApplyHostMappingRules(request_info.url, &destination); | 101 GURL origin_url = ApplyHostMappingRules(request_info.url, &destination); |
102 | 102 |
103 const AlternativeService alternative_service = GetAlternativeServiceFor( | 103 const AlternativeService alternative_service = GetAlternativeServiceFor( |
104 request_info, nullptr, HttpStreamRequest::HTTP_STREAM); | 104 request_info, nullptr, HttpStreamRequest::HTTP_STREAM); |
105 | 105 |
106 if (alternative_service.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { | 106 if (alternative_service.protocol != kProtoUnknown) { |
107 if (session_->params().quic_disable_preconnect_if_0rtt && | 107 if (session_->params().quic_disable_preconnect_if_0rtt && |
108 alternative_service.protocol == QUIC && | 108 alternative_service.protocol == kProtoQUIC && |
109 session_->quic_stream_factory()->ZeroRTTEnabledFor(QuicServerId( | 109 session_->quic_stream_factory()->ZeroRTTEnabledFor(QuicServerId( |
110 alternative_service.host_port_pair(), request_info.privacy_mode))) { | 110 alternative_service.host_port_pair(), request_info.privacy_mode))) { |
111 MaybeNotifyFactoryOfCompletion(); | 111 MaybeNotifyFactoryOfCompletion(); |
112 return; | 112 return; |
113 } | 113 } |
114 destination = alternative_service.host_port_pair(); | 114 destination = alternative_service.host_port_pair(); |
115 ignore_result(ApplyHostMappingRules(request_info.url, &destination)); | 115 ignore_result(ApplyHostMappingRules(request_info.url, &destination)); |
116 } | 116 } |
117 | 117 |
118 // Due to how the socket pools handle priorities and idle sockets, only IDLE | 118 // Due to how the socket pools handle priorities and idle sockets, only IDLE |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 | 637 |
638 main_job_.reset(job_factory_->CreateJob( | 638 main_job_.reset(job_factory_->CreateJob( |
639 this, MAIN, session_, request_info, priority, server_ssl_config, | 639 this, MAIN, session_, request_info, priority, server_ssl_config, |
640 proxy_ssl_config, destination, origin_url, net_log.net_log())); | 640 proxy_ssl_config, destination, origin_url, net_log.net_log())); |
641 AttachJob(main_job_.get()); | 641 AttachJob(main_job_.get()); |
642 | 642 |
643 // Create an alternative job if alternative service is set up for this domain. | 643 // Create an alternative job if alternative service is set up for this domain. |
644 const AlternativeService alternative_service = | 644 const AlternativeService alternative_service = |
645 GetAlternativeServiceFor(request_info, delegate, stream_type); | 645 GetAlternativeServiceFor(request_info, delegate, stream_type); |
646 | 646 |
647 if (alternative_service.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { | 647 if (alternative_service.protocol != kProtoUnknown) { |
648 // Never share connection with other jobs for FTP requests. | 648 // Never share connection with other jobs for FTP requests. |
649 DVLOG(1) << "Selected alternative service (host: " | 649 DVLOG(1) << "Selected alternative service (host: " |
650 << alternative_service.host_port_pair().host() | 650 << alternative_service.host_port_pair().host() |
651 << " port: " << alternative_service.host_port_pair().port() << ")"; | 651 << " port: " << alternative_service.host_port_pair().port() << ")"; |
652 | 652 |
653 DCHECK(!request_info.url.SchemeIs(url::kFtpScheme)); | 653 DCHECK(!request_info.url.SchemeIs(url::kFtpScheme)); |
654 HostPortPair alternative_destination(alternative_service.host_port_pair()); | 654 HostPortPair alternative_destination(alternative_service.host_port_pair()); |
655 ignore_result( | 655 ignore_result( |
656 ApplyHostMappingRules(request_info.url, &alternative_destination)); | 656 ApplyHostMappingRules(request_info.url, &alternative_destination)); |
657 | 657 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 if (!request_ || (job_bound_ && bound_job_ != job)) { | 780 if (!request_ || (job_bound_ && bound_job_ != job)) { |
781 // If |request_| is gone then it must have been successfully served by | 781 // If |request_| is gone then it must have been successfully served by |
782 // |main_job_|. | 782 // |main_job_|. |
783 // If |request_| is bound to a different job, then it is being | 783 // If |request_| is bound to a different job, then it is being |
784 // successfully serverd by the main job. | 784 // successfully serverd by the main job. |
785 ReportBrokenAlternativeService(); | 785 ReportBrokenAlternativeService(); |
786 } | 786 } |
787 } | 787 } |
788 | 788 |
789 void HttpStreamFactoryImpl::JobController::ReportBrokenAlternativeService() { | 789 void HttpStreamFactoryImpl::JobController::ReportBrokenAlternativeService() { |
790 DCHECK(failed_alternative_service_.protocol != | 790 DCHECK(failed_alternative_service_.protocol != kProtoUnknown || |
791 UNINITIALIZED_ALTERNATE_PROTOCOL || | |
792 failed_alternative_proxy_server_.is_valid()); | 791 failed_alternative_proxy_server_.is_valid()); |
793 | 792 |
794 if (failed_alternative_proxy_server_.is_valid()) { | 793 if (failed_alternative_proxy_server_.is_valid()) { |
795 ProxyDelegate* proxy_delegate = session_->params().proxy_delegate; | 794 ProxyDelegate* proxy_delegate = session_->params().proxy_delegate; |
796 if (proxy_delegate) | 795 if (proxy_delegate) |
797 proxy_delegate->OnAlternativeProxyBroken( | 796 proxy_delegate->OnAlternativeProxyBroken( |
798 failed_alternative_proxy_server_); | 797 failed_alternative_proxy_server_); |
799 } else { | 798 } else { |
800 HistogramBrokenAlternateProtocolLocation( | 799 HistogramBrokenAlternateProtocolLocation( |
801 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_ALT); | 800 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_ALT); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 } | 841 } |
843 | 842 |
844 AlternativeService | 843 AlternativeService |
845 HttpStreamFactoryImpl::JobController::GetAlternativeServiceFor( | 844 HttpStreamFactoryImpl::JobController::GetAlternativeServiceFor( |
846 const HttpRequestInfo& request_info, | 845 const HttpRequestInfo& request_info, |
847 HttpStreamRequest::Delegate* delegate, | 846 HttpStreamRequest::Delegate* delegate, |
848 HttpStreamRequest::StreamType stream_type) { | 847 HttpStreamRequest::StreamType stream_type) { |
849 AlternativeService alternative_service = | 848 AlternativeService alternative_service = |
850 GetAlternativeServiceForInternal(request_info, delegate, stream_type); | 849 GetAlternativeServiceForInternal(request_info, delegate, stream_type); |
851 AlternativeServiceType type; | 850 AlternativeServiceType type; |
852 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { | 851 if (alternative_service.protocol == kProtoUnknown) { |
853 type = NO_ALTERNATIVE_SERVICE; | 852 type = NO_ALTERNATIVE_SERVICE; |
854 } else if (alternative_service.protocol == QUIC) { | 853 } else if (alternative_service.protocol == kProtoQUIC) { |
855 if (request_info.url.host() == alternative_service.host) { | 854 if (request_info.url.host() == alternative_service.host) { |
856 type = QUIC_SAME_DESTINATION; | 855 type = QUIC_SAME_DESTINATION; |
857 } else { | 856 } else { |
858 type = QUIC_DIFFERENT_DESTINATION; | 857 type = QUIC_DIFFERENT_DESTINATION; |
859 } | 858 } |
860 } else { | 859 } else { |
861 if (request_info.url.host() == alternative_service.host) { | 860 if (request_info.url.host() == alternative_service.host) { |
862 type = NOT_QUIC_SAME_DESTINATION; | 861 type = NOT_QUIC_SAME_DESTINATION; |
863 } else { | 862 } else { |
864 type = NOT_QUIC_DIFFERENT_DESTINATION; | 863 type = NOT_QUIC_DIFFERENT_DESTINATION; |
(...skipping 24 matching lines...) Expand all Loading... |
889 | 888 |
890 bool quic_advertised = false; | 889 bool quic_advertised = false; |
891 bool quic_all_broken = true; | 890 bool quic_all_broken = true; |
892 | 891 |
893 // First Alt-Svc that is not marked as broken. | 892 // First Alt-Svc that is not marked as broken. |
894 AlternativeService first_alternative_service; | 893 AlternativeService first_alternative_service; |
895 | 894 |
896 for (const AlternativeService& alternative_service : | 895 for (const AlternativeService& alternative_service : |
897 alternative_service_vector) { | 896 alternative_service_vector) { |
898 DCHECK(IsAlternateProtocolValid(alternative_service.protocol)); | 897 DCHECK(IsAlternateProtocolValid(alternative_service.protocol)); |
899 if (!quic_advertised && alternative_service.protocol == QUIC) | 898 if (!quic_advertised && alternative_service.protocol == kProtoQUIC) |
900 quic_advertised = true; | 899 quic_advertised = true; |
901 if (http_server_properties.IsAlternativeServiceBroken( | 900 if (http_server_properties.IsAlternativeServiceBroken( |
902 alternative_service)) { | 901 alternative_service)) { |
903 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN, false); | 902 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN, false); |
904 continue; | 903 continue; |
905 } | 904 } |
906 | 905 |
907 | 906 |
908 // Some shared unix systems may have user home directories (like | 907 // Some shared unix systems may have user home directories (like |
909 // http://foo.com/~mike) which allow users to emit headers. This is a bad | 908 // http://foo.com/~mike) which allow users to emit headers. This is a bad |
910 // idea already, but with Alternate-Protocol, it provides the ability for a | 909 // idea already, but with Alternate-Protocol, it provides the ability for a |
911 // single user on a multi-user system to hijack the alternate protocol. | 910 // single user on a multi-user system to hijack the alternate protocol. |
912 // These systems also enforce ports <1024 as restricted ports. So don't | 911 // These systems also enforce ports <1024 as restricted ports. So don't |
913 // allow protocol upgrades to user-controllable ports. | 912 // allow protocol upgrades to user-controllable ports. |
914 const int kUnrestrictedPort = 1024; | 913 const int kUnrestrictedPort = 1024; |
915 if (!session_->params().enable_user_alternate_protocol_ports && | 914 if (!session_->params().enable_user_alternate_protocol_ports && |
916 (alternative_service.port >= kUnrestrictedPort && | 915 (alternative_service.port >= kUnrestrictedPort && |
917 origin.port() < kUnrestrictedPort)) | 916 origin.port() < kUnrestrictedPort)) |
918 continue; | 917 continue; |
919 | 918 |
920 if (alternative_service.protocol == NPN_HTTP_2) { | 919 if (alternative_service.protocol == kProtoHTTP2) { |
921 if (origin.host() != alternative_service.host && | 920 if (origin.host() != alternative_service.host && |
922 !session_->params() | 921 !session_->params() |
923 .enable_http2_alternative_service_with_different_host) { | 922 .enable_http2_alternative_service_with_different_host) { |
924 continue; | 923 continue; |
925 } | 924 } |
926 | 925 |
927 // Cache this entry if we don't have a non-broken Alt-Svc yet. | 926 // Cache this entry if we don't have a non-broken Alt-Svc yet. |
928 if (first_alternative_service.protocol == | 927 if (first_alternative_service.protocol == kProtoUnknown) |
929 UNINITIALIZED_ALTERNATE_PROTOCOL) | |
930 first_alternative_service = alternative_service; | 928 first_alternative_service = alternative_service; |
931 continue; | 929 continue; |
932 } | 930 } |
933 | 931 |
934 DCHECK_EQ(QUIC, alternative_service.protocol); | 932 DCHECK_EQ(kProtoQUIC, alternative_service.protocol); |
935 if (origin.host() != alternative_service.host && | 933 if (origin.host() != alternative_service.host && |
936 !session_->params() | 934 !session_->params() |
937 .enable_quic_alternative_service_with_different_host) { | 935 .enable_quic_alternative_service_with_different_host) { |
938 continue; | 936 continue; |
939 } | 937 } |
940 | 938 |
941 quic_all_broken = false; | 939 quic_all_broken = false; |
942 if (!session_->params().enable_quic) | 940 if (!session_->params().enable_quic) |
943 continue; | 941 continue; |
944 | 942 |
(...skipping 18 matching lines...) Expand all Loading... |
963 | 961 |
964 HostPortPair destination(alternative_service.host_port_pair()); | 962 HostPortPair destination(alternative_service.host_port_pair()); |
965 ignore_result(ApplyHostMappingRules(original_url, &destination)); | 963 ignore_result(ApplyHostMappingRules(original_url, &destination)); |
966 | 964 |
967 if (session_->quic_stream_factory()->CanUseExistingSession(server_id, | 965 if (session_->quic_stream_factory()->CanUseExistingSession(server_id, |
968 destination)) { | 966 destination)) { |
969 return alternative_service; | 967 return alternative_service; |
970 } | 968 } |
971 | 969 |
972 // Cache this entry if we don't have a non-broken Alt-Svc yet. | 970 // Cache this entry if we don't have a non-broken Alt-Svc yet. |
973 if (first_alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) | 971 if (first_alternative_service.protocol == kProtoUnknown) |
974 first_alternative_service = alternative_service; | 972 first_alternative_service = alternative_service; |
975 } | 973 } |
976 | 974 |
977 // Ask delegate to mark QUIC as broken for the origin. | 975 // Ask delegate to mark QUIC as broken for the origin. |
978 if (quic_advertised && quic_all_broken && delegate != nullptr) | 976 if (quic_advertised && quic_all_broken && delegate != nullptr) |
979 delegate->OnQuicBroken(); | 977 delegate->OnQuicBroken(); |
980 | 978 |
981 return first_alternative_service; | 979 return first_alternative_service; |
982 } | 980 } |
983 | 981 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 } | 1071 } |
1074 | 1072 |
1075 void HttpStreamFactoryImpl::JobController::StartAlternativeProxyServerJob() { | 1073 void HttpStreamFactoryImpl::JobController::StartAlternativeProxyServerJob() { |
1076 if (!alternative_job_ || !request_) | 1074 if (!alternative_job_ || !request_) |
1077 return; | 1075 return; |
1078 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); | 1076 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); |
1079 alternative_job_->Start(request_->stream_type()); | 1077 alternative_job_->Start(request_->stream_type()); |
1080 } | 1078 } |
1081 | 1079 |
1082 } // namespace net | 1080 } // namespace net |
OLD | NEW |