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 != kProtoUnknown) { | 106 if (alternative_service.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { |
107 if (session_->params().quic_disable_preconnect_if_0rtt && | 107 if (session_->params().quic_disable_preconnect_if_0rtt && |
108 alternative_service.protocol == kProtoQUIC && | 108 alternative_service.protocol == QUIC && |
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 != kProtoUnknown) { | 647 if (alternative_service.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { |
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 != kProtoUnknown || | 790 DCHECK(failed_alternative_service_.protocol != |
| 791 UNINITIALIZED_ALTERNATE_PROTOCOL || |
791 failed_alternative_proxy_server_.is_valid()); | 792 failed_alternative_proxy_server_.is_valid()); |
792 | 793 |
793 if (failed_alternative_proxy_server_.is_valid()) { | 794 if (failed_alternative_proxy_server_.is_valid()) { |
794 ProxyDelegate* proxy_delegate = session_->params().proxy_delegate; | 795 ProxyDelegate* proxy_delegate = session_->params().proxy_delegate; |
795 if (proxy_delegate) | 796 if (proxy_delegate) |
796 proxy_delegate->OnAlternativeProxyBroken( | 797 proxy_delegate->OnAlternativeProxyBroken( |
797 failed_alternative_proxy_server_); | 798 failed_alternative_proxy_server_); |
798 } else { | 799 } else { |
799 HistogramBrokenAlternateProtocolLocation( | 800 HistogramBrokenAlternateProtocolLocation( |
800 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_ALT); | 801 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_ALT); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 } | 842 } |
842 | 843 |
843 AlternativeService | 844 AlternativeService |
844 HttpStreamFactoryImpl::JobController::GetAlternativeServiceFor( | 845 HttpStreamFactoryImpl::JobController::GetAlternativeServiceFor( |
845 const HttpRequestInfo& request_info, | 846 const HttpRequestInfo& request_info, |
846 HttpStreamRequest::Delegate* delegate, | 847 HttpStreamRequest::Delegate* delegate, |
847 HttpStreamRequest::StreamType stream_type) { | 848 HttpStreamRequest::StreamType stream_type) { |
848 AlternativeService alternative_service = | 849 AlternativeService alternative_service = |
849 GetAlternativeServiceForInternal(request_info, delegate, stream_type); | 850 GetAlternativeServiceForInternal(request_info, delegate, stream_type); |
850 AlternativeServiceType type; | 851 AlternativeServiceType type; |
851 if (alternative_service.protocol == kProtoUnknown) { | 852 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { |
852 type = NO_ALTERNATIVE_SERVICE; | 853 type = NO_ALTERNATIVE_SERVICE; |
853 } else if (alternative_service.protocol == kProtoQUIC) { | 854 } else if (alternative_service.protocol == QUIC) { |
854 if (request_info.url.host() == alternative_service.host) { | 855 if (request_info.url.host() == alternative_service.host) { |
855 type = QUIC_SAME_DESTINATION; | 856 type = QUIC_SAME_DESTINATION; |
856 } else { | 857 } else { |
857 type = QUIC_DIFFERENT_DESTINATION; | 858 type = QUIC_DIFFERENT_DESTINATION; |
858 } | 859 } |
859 } else { | 860 } else { |
860 if (request_info.url.host() == alternative_service.host) { | 861 if (request_info.url.host() == alternative_service.host) { |
861 type = NOT_QUIC_SAME_DESTINATION; | 862 type = NOT_QUIC_SAME_DESTINATION; |
862 } else { | 863 } else { |
863 type = NOT_QUIC_DIFFERENT_DESTINATION; | 864 type = NOT_QUIC_DIFFERENT_DESTINATION; |
(...skipping 24 matching lines...) Expand all Loading... |
888 | 889 |
889 bool quic_advertised = false; | 890 bool quic_advertised = false; |
890 bool quic_all_broken = true; | 891 bool quic_all_broken = true; |
891 | 892 |
892 // First Alt-Svc that is not marked as broken. | 893 // First Alt-Svc that is not marked as broken. |
893 AlternativeService first_alternative_service; | 894 AlternativeService first_alternative_service; |
894 | 895 |
895 for (const AlternativeService& alternative_service : | 896 for (const AlternativeService& alternative_service : |
896 alternative_service_vector) { | 897 alternative_service_vector) { |
897 DCHECK(IsAlternateProtocolValid(alternative_service.protocol)); | 898 DCHECK(IsAlternateProtocolValid(alternative_service.protocol)); |
898 if (!quic_advertised && alternative_service.protocol == kProtoQUIC) | 899 if (!quic_advertised && alternative_service.protocol == QUIC) |
899 quic_advertised = true; | 900 quic_advertised = true; |
900 if (http_server_properties.IsAlternativeServiceBroken( | 901 if (http_server_properties.IsAlternativeServiceBroken( |
901 alternative_service)) { | 902 alternative_service)) { |
902 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN, false); | 903 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN, false); |
903 continue; | 904 continue; |
904 } | 905 } |
905 | 906 |
906 | 907 |
907 // Some shared unix systems may have user home directories (like | 908 // Some shared unix systems may have user home directories (like |
908 // http://foo.com/~mike) which allow users to emit headers. This is a bad | 909 // http://foo.com/~mike) which allow users to emit headers. This is a bad |
909 // idea already, but with Alternate-Protocol, it provides the ability for a | 910 // idea already, but with Alternate-Protocol, it provides the ability for a |
910 // single user on a multi-user system to hijack the alternate protocol. | 911 // single user on a multi-user system to hijack the alternate protocol. |
911 // These systems also enforce ports <1024 as restricted ports. So don't | 912 // These systems also enforce ports <1024 as restricted ports. So don't |
912 // allow protocol upgrades to user-controllable ports. | 913 // allow protocol upgrades to user-controllable ports. |
913 const int kUnrestrictedPort = 1024; | 914 const int kUnrestrictedPort = 1024; |
914 if (!session_->params().enable_user_alternate_protocol_ports && | 915 if (!session_->params().enable_user_alternate_protocol_ports && |
915 (alternative_service.port >= kUnrestrictedPort && | 916 (alternative_service.port >= kUnrestrictedPort && |
916 origin.port() < kUnrestrictedPort)) | 917 origin.port() < kUnrestrictedPort)) |
917 continue; | 918 continue; |
918 | 919 |
919 if (alternative_service.protocol == kProtoHTTP2) { | 920 if (alternative_service.protocol == NPN_HTTP_2) { |
920 if (origin.host() != alternative_service.host && | 921 if (origin.host() != alternative_service.host && |
921 !session_->params() | 922 !session_->params() |
922 .enable_http2_alternative_service_with_different_host) { | 923 .enable_http2_alternative_service_with_different_host) { |
923 continue; | 924 continue; |
924 } | 925 } |
925 | 926 |
926 // Cache this entry if we don't have a non-broken Alt-Svc yet. | 927 // Cache this entry if we don't have a non-broken Alt-Svc yet. |
927 if (first_alternative_service.protocol == kProtoUnknown) | 928 if (first_alternative_service.protocol == |
| 929 UNINITIALIZED_ALTERNATE_PROTOCOL) |
928 first_alternative_service = alternative_service; | 930 first_alternative_service = alternative_service; |
929 continue; | 931 continue; |
930 } | 932 } |
931 | 933 |
932 DCHECK_EQ(kProtoQUIC, alternative_service.protocol); | 934 DCHECK_EQ(QUIC, alternative_service.protocol); |
933 if (origin.host() != alternative_service.host && | 935 if (origin.host() != alternative_service.host && |
934 !session_->params() | 936 !session_->params() |
935 .enable_quic_alternative_service_with_different_host) { | 937 .enable_quic_alternative_service_with_different_host) { |
936 continue; | 938 continue; |
937 } | 939 } |
938 | 940 |
939 quic_all_broken = false; | 941 quic_all_broken = false; |
940 if (!session_->params().enable_quic) | 942 if (!session_->params().enable_quic) |
941 continue; | 943 continue; |
942 | 944 |
(...skipping 18 matching lines...) Expand all Loading... |
961 | 963 |
962 HostPortPair destination(alternative_service.host_port_pair()); | 964 HostPortPair destination(alternative_service.host_port_pair()); |
963 ignore_result(ApplyHostMappingRules(original_url, &destination)); | 965 ignore_result(ApplyHostMappingRules(original_url, &destination)); |
964 | 966 |
965 if (session_->quic_stream_factory()->CanUseExistingSession(server_id, | 967 if (session_->quic_stream_factory()->CanUseExistingSession(server_id, |
966 destination)) { | 968 destination)) { |
967 return alternative_service; | 969 return alternative_service; |
968 } | 970 } |
969 | 971 |
970 // Cache this entry if we don't have a non-broken Alt-Svc yet. | 972 // Cache this entry if we don't have a non-broken Alt-Svc yet. |
971 if (first_alternative_service.protocol == kProtoUnknown) | 973 if (first_alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) |
972 first_alternative_service = alternative_service; | 974 first_alternative_service = alternative_service; |
973 } | 975 } |
974 | 976 |
975 // Ask delegate to mark QUIC as broken for the origin. | 977 // Ask delegate to mark QUIC as broken for the origin. |
976 if (quic_advertised && quic_all_broken && delegate != nullptr) | 978 if (quic_advertised && quic_all_broken && delegate != nullptr) |
977 delegate->OnQuicBroken(); | 979 delegate->OnQuicBroken(); |
978 | 980 |
979 return first_alternative_service; | 981 return first_alternative_service; |
980 } | 982 } |
981 | 983 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 } | 1073 } |
1072 | 1074 |
1073 void HttpStreamFactoryImpl::JobController::StartAlternativeProxyServerJob() { | 1075 void HttpStreamFactoryImpl::JobController::StartAlternativeProxyServerJob() { |
1074 if (!alternative_job_ || !request_) | 1076 if (!alternative_job_ || !request_) |
1075 return; | 1077 return; |
1076 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); | 1078 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); |
1077 alternative_job_->Start(request_->stream_type()); | 1079 alternative_job_->Start(request_->stream_type()); |
1078 } | 1080 } |
1079 | 1081 |
1080 } // namespace net | 1082 } // namespace net |
OLD | NEW |