Chromium Code Reviews| 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 "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "net/base/host_mapping_rules.h" | 11 #include "net/base/host_mapping_rules.h" |
| 12 #include "net/base/proxy_delegate.h" | |
| 12 #include "net/http/bidirectional_stream_impl.h" | 13 #include "net/http/bidirectional_stream_impl.h" |
| 13 #include "net/http/transport_security_state.h" | 14 #include "net/http/transport_security_state.h" |
| 15 #include "net/proxy/proxy_server.h" | |
| 14 #include "net/spdy/spdy_session.h" | 16 #include "net/spdy/spdy_session.h" |
| 15 | 17 |
| 16 namespace net { | 18 namespace net { |
| 17 | 19 |
| 18 // Returns parameters associated with the delay of the HTTP stream job. | 20 // Returns parameters associated with the delay of the HTTP stream job. |
| 19 std::unique_ptr<base::Value> NetLogHttpStreamJobDelayCallback( | 21 std::unique_ptr<base::Value> NetLogHttpStreamJobDelayCallback( |
| 20 base::TimeDelta delay, | 22 base::TimeDelta delay, |
| 21 NetLogCaptureMode /* capture_mode */) { | 23 NetLogCaptureMode /* capture_mode */) { |
| 22 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 24 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 23 dict->SetInteger("resume_after_ms", static_cast<int>(delay.InMilliseconds())); | 25 dict->SetInteger("resume_after_ms", static_cast<int>(delay.InMilliseconds())); |
| 24 return std::move(dict); | 26 return std::move(dict); |
| 25 } | 27 } |
| 26 | 28 |
| 27 HttpStreamFactoryImpl::JobController::JobController( | 29 HttpStreamFactoryImpl::JobController::JobController( |
| 28 HttpStreamFactoryImpl* factory, | 30 HttpStreamFactoryImpl* factory, |
| 29 HttpStreamRequest::Delegate* delegate, | 31 HttpStreamRequest::Delegate* delegate, |
| 30 HttpNetworkSession* session, | 32 HttpNetworkSession* session, |
| 31 JobFactory* job_factory) | 33 JobFactory* job_factory) |
| 32 : factory_(factory), | 34 : factory_(factory), |
| 33 session_(session), | 35 session_(session), |
| 34 job_factory_(job_factory), | 36 job_factory_(job_factory), |
| 35 request_(nullptr), | 37 request_(nullptr), |
| 36 delegate_(delegate), | 38 delegate_(delegate), |
| 37 is_preconnect_(false), | 39 is_preconnect_(false), |
| 38 job_bound_(false), | 40 job_bound_(false), |
| 39 main_job_is_blocked_(false), | 41 main_job_is_blocked_(false), |
| 40 bound_job_(nullptr), | 42 bound_job_(nullptr), |
| 43 can_start_alternative_proxy_job_(false), | |
| 41 ptr_factory_(this) { | 44 ptr_factory_(this) { |
| 42 DCHECK(factory); | 45 DCHECK(factory); |
| 43 } | 46 } |
| 44 | 47 |
| 45 HttpStreamFactoryImpl::JobController::~JobController() { | 48 HttpStreamFactoryImpl::JobController::~JobController() { |
| 46 main_job_.reset(); | 49 main_job_.reset(); |
| 47 alternative_job_.reset(); | 50 alternative_job_.reset(); |
| 48 bound_job_ = nullptr; | 51 bound_job_ = nullptr; |
| 49 } | 52 } |
| 50 | 53 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 ignore_result(ApplyHostMappingRules(request_info.url, &destination)); | 105 ignore_result(ApplyHostMappingRules(request_info.url, &destination)); |
| 103 } | 106 } |
| 104 | 107 |
| 105 // Due to how the socket pools handle priorities and idle sockets, only IDLE | 108 // Due to how the socket pools handle priorities and idle sockets, only IDLE |
| 106 // priority currently makes sense for preconnects. The priority for | 109 // priority currently makes sense for preconnects. The priority for |
| 107 // preconnects is currently ignored (see RequestSocketsForPool()), but could | 110 // preconnects is currently ignored (see RequestSocketsForPool()), but could |
| 108 // be used at some point for proxy resolution or something. | 111 // be used at some point for proxy resolution or something. |
| 109 main_job_.reset(job_factory_->CreateJob( | 112 main_job_.reset(job_factory_->CreateJob( |
| 110 this, PRECONNECT, session_, request_info, IDLE, server_ssl_config, | 113 this, PRECONNECT, session_, request_info, IDLE, server_ssl_config, |
| 111 proxy_ssl_config, destination, origin_url, alternative_service, | 114 proxy_ssl_config, destination, origin_url, alternative_service, |
| 112 session_->net_log())); | 115 ProxyServer(), session_->net_log())); |
| 113 main_job_->Preconnect(num_streams); | 116 main_job_->Preconnect(num_streams); |
| 114 } | 117 } |
| 115 | 118 |
| 116 LoadState HttpStreamFactoryImpl::JobController::GetLoadState() const { | 119 LoadState HttpStreamFactoryImpl::JobController::GetLoadState() const { |
| 117 DCHECK(request_); | 120 DCHECK(request_); |
| 118 DCHECK(main_job_ || alternative_job_); | 121 DCHECK(main_job_ || alternative_job_); |
| 119 if (bound_job_) | 122 if (bound_job_) |
| 120 return bound_job_->GetLoadState(); | 123 return bound_job_->GetLoadState(); |
| 121 | 124 |
| 122 // Just pick the first one. | 125 // Just pick the first one. |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 } | 351 } |
| 349 | 352 |
| 350 if (!request_) | 353 if (!request_) |
| 351 return; | 354 return; |
| 352 if (!bound_job_) | 355 if (!bound_job_) |
| 353 BindJob(job); | 356 BindJob(job); |
| 354 request_->OnNeedsProxyAuth(proxy_response, used_ssl_config, used_proxy_info, | 357 request_->OnNeedsProxyAuth(proxy_response, used_ssl_config, used_proxy_info, |
| 355 auth_controller); | 358 auth_controller); |
| 356 } | 359 } |
| 357 | 360 |
| 361 void HttpStreamFactoryImpl::JobController::OnResolveProxyComplete( | |
| 362 Job* job, | |
| 363 const HttpRequestInfo& request_info, | |
| 364 RequestPriority priority, | |
| 365 const SSLConfig& server_ssl_config, | |
| 366 const SSLConfig& proxy_ssl_config, | |
| 367 HttpStreamRequest::StreamType stream_type) { | |
| 368 DCHECK(job); | |
| 369 | |
| 370 ProxyServer alternative_proxy_server; | |
| 371 if (!ShouldCreateAlternativeProxyServerJob(job, job->proxy_info(), | |
| 372 request_info.url, | |
| 373 &alternative_proxy_server)) { | |
| 374 return; | |
| 375 } | |
| 376 | |
| 377 DCHECK(main_job_); | |
| 378 DCHECK(!alternative_job_); | |
| 379 DCHECK(!main_job_is_blocked_); | |
| 380 | |
| 381 HostPortPair destination(HostPortPair::FromURL(request_info.url)); | |
| 382 GURL origin_url = ApplyHostMappingRules(request_info.url, &destination); | |
| 383 | |
| 384 alternative_job_.reset(job_factory_->CreateJob( | |
| 385 this, ALTERNATIVE, session_, request_info, priority, server_ssl_config, | |
| 386 proxy_ssl_config, destination, origin_url, AlternativeService(), | |
| 387 alternative_proxy_server, job->net_log().net_log())); | |
| 388 AttachJob(alternative_job_.get()); | |
| 389 | |
| 390 can_start_alternative_proxy_job_ = false; | |
| 391 main_job_is_blocked_ = true; | |
|
Zhongyi Shi
2016/08/20 06:15:40
I am a little bit concerned on starting the altern
tbansal1
2016/08/22 15:42:33
Done.
| |
| 392 alternative_job_->Start(request_->stream_type()); | |
| 393 } | |
| 394 | |
| 358 void HttpStreamFactoryImpl::JobController::OnNewSpdySessionReady( | 395 void HttpStreamFactoryImpl::JobController::OnNewSpdySessionReady( |
| 359 Job* job, | 396 Job* job, |
| 360 const base::WeakPtr<SpdySession>& spdy_session, | 397 const base::WeakPtr<SpdySession>& spdy_session, |
| 361 bool direct) { | 398 bool direct) { |
| 362 DCHECK(job); | 399 DCHECK(job); |
| 363 DCHECK(job->using_spdy()); | 400 DCHECK(job->using_spdy()); |
| 364 | 401 |
| 365 bool is_job_orphaned = job_bound_ && bound_job_ != job; | 402 bool is_job_orphaned = job_bound_ && bound_job_ != job; |
| 366 | 403 |
| 367 // Cache these values in case the job gets deleted. | 404 // Cache these values in case the job gets deleted. |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 << " port: " << alternative_service.host_port_pair().port() << ")"; | 632 << " port: " << alternative_service.host_port_pair().port() << ")"; |
| 596 | 633 |
| 597 DCHECK(!request_info.url.SchemeIs("ftp")); | 634 DCHECK(!request_info.url.SchemeIs("ftp")); |
| 598 HostPortPair alternative_destination(alternative_service.host_port_pair()); | 635 HostPortPair alternative_destination(alternative_service.host_port_pair()); |
| 599 ignore_result( | 636 ignore_result( |
| 600 ApplyHostMappingRules(request_info.url, &alternative_destination)); | 637 ApplyHostMappingRules(request_info.url, &alternative_destination)); |
| 601 | 638 |
| 602 alternative_job_.reset(job_factory_->CreateJob( | 639 alternative_job_.reset(job_factory_->CreateJob( |
| 603 this, ALTERNATIVE, session_, request_info, priority, server_ssl_config, | 640 this, ALTERNATIVE, session_, request_info, priority, server_ssl_config, |
| 604 proxy_ssl_config, alternative_destination, origin_url, | 641 proxy_ssl_config, alternative_destination, origin_url, |
| 605 alternative_service, net_log.net_log())); | 642 alternative_service, ProxyServer(), net_log.net_log())); |
| 606 AttachJob(alternative_job_.get()); | 643 AttachJob(alternative_job_.get()); |
| 607 | 644 |
| 608 main_job_is_blocked_ = true; | 645 main_job_is_blocked_ = true; |
| 609 alternative_job_->Start(request_->stream_type()); | 646 alternative_job_->Start(request_->stream_type()); |
| 647 } else { | |
|
Zhongyi Shi
2016/08/20 06:15:40
Rather than wait until later check, how about set
tbansal1
2016/08/22 15:42:33
I do not understand this comment. It seems that he
Zhongyi Shi
2016/08/23 05:42:33
Okay. I thought the url scheme check can be part o
tbansal1
2016/08/23 20:56:40
Acknowledged.
| |
| 648 can_start_alternative_proxy_job_ = true; | |
| 610 } | 649 } |
| 611 // Even if |alternative_job| has already finished, it will not have notified | 650 // Even if |alternative_job| has already finished, it will not have notified |
| 612 // the request yet, since we defer that to the next iteration of the | 651 // the request yet, since we defer that to the next iteration of the |
| 613 // MessageLoop, so starting |main_job_| is always safe. | 652 // MessageLoop, so starting |main_job_| is always safe. |
| 614 main_job_->Start(request_->stream_type()); | 653 main_job_->Start(request_->stream_type()); |
| 615 } | 654 } |
| 616 | 655 |
| 617 void HttpStreamFactoryImpl::JobController::AttachJob(Job* job) { | 656 void HttpStreamFactoryImpl::JobController::AttachJob(Job* job) { |
| 618 DCHECK(job); | 657 DCHECK(job); |
| 619 factory_->request_map_[job] = request_; | 658 factory_->request_map_[job] = request_; |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 888 if (first_alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) | 927 if (first_alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) |
| 889 first_alternative_service = alternative_service; | 928 first_alternative_service = alternative_service; |
| 890 } | 929 } |
| 891 | 930 |
| 892 // Ask delegate to mark QUIC as broken for the origin. | 931 // Ask delegate to mark QUIC as broken for the origin. |
| 893 if (quic_advertised && quic_all_broken && delegate != nullptr) | 932 if (quic_advertised && quic_all_broken && delegate != nullptr) |
| 894 delegate->OnQuicBroken(); | 933 delegate->OnQuicBroken(); |
| 895 | 934 |
| 896 return first_alternative_service; | 935 return first_alternative_service; |
| 897 } | 936 } |
| 937 | |
| 938 bool HttpStreamFactoryImpl::JobController:: | |
| 939 ShouldCreateAlternativeProxyServerJob( | |
| 940 Job* job, | |
| 941 const ProxyInfo& proxy_info, | |
| 942 const GURL& url, | |
| 943 ProxyServer* alternative_proxy_server) const { | |
|
Zhongyi Shi
2016/08/20 06:15:40
nit: DCHECK(!alternative_proxy_server);
tbansal1
2016/08/22 15:42:33
Done.
| |
| 944 if (job->job_type() == ALTERNATIVE) { | |
| 945 // If |job| is using alternative service, then alternative proxy server | |
| 946 // should not be used. | |
| 947 return false; | |
| 948 } | |
| 949 | |
| 950 if (job->job_type() == PRECONNECT) { | |
| 951 // Preconnects should be fetched using only the main job to keep the | |
| 952 // resource utilization down. | |
| 953 return false; | |
| 954 } | |
| 955 | |
| 956 if (proxy_info.is_empty() || proxy_info.is_direct() || proxy_info.is_quic()) { | |
| 957 // Alternative proxy server job can be created only if |job| fetches the | |
| 958 // |request_| through a non-QUIC proxy. | |
| 959 return false; | |
| 960 } | |
| 961 | |
| 962 if (!url.SchemeIs(url::kHttpScheme)) { | |
| 963 // Only HTTP URLs can be fetched through alternative proxy server, since the | |
| 964 // alternative proxy server may not support fetching of URLs with other | |
| 965 // schemes. | |
| 966 return false; | |
| 967 } | |
| 968 | |
| 969 if (!can_start_alternative_proxy_job_) { | |
|
Zhongyi Shi
2016/08/20 06:15:40
I think this is more like a meta bit of informatio
tbansal1
2016/08/22 15:42:33
Done.
| |
| 970 // Either an alternative service job or an alternative proxy server job has | |
| 971 // already been started. | |
| 972 return false; | |
| 973 } | |
| 974 | |
| 975 ProxyDelegate* proxy_delegate = session_->params().proxy_delegate; | |
| 976 if (!proxy_delegate) | |
| 977 return false; | |
| 978 | |
| 979 proxy_delegate->GetAlternativeProxy(url, proxy_info.proxy_server(), | |
| 980 alternative_proxy_server); | |
| 981 | |
| 982 if (!alternative_proxy_server->is_valid()) | |
| 983 return false; | |
| 984 | |
| 985 DCHECK(!(*alternative_proxy_server == proxy_info.proxy_server())); | |
| 986 | |
| 987 if (!alternative_proxy_server->is_https() && | |
| 988 !alternative_proxy_server->is_quic()) { | |
| 989 // Alternative proxy server should be a secure server. | |
| 990 return false; | |
| 991 } | |
| 992 | |
| 993 if (alternative_proxy_server->is_quic()) { | |
| 994 // Check that QUIC is enabled globally, and it is not disabled on | |
| 995 // the specified port. | |
| 996 if (!session_->params().enable_quic || | |
| 997 session_->quic_stream_factory()->IsQuicDisabled( | |
| 998 alternative_proxy_server->host_port_pair().port())) { | |
| 999 return false; | |
| 1000 } | |
| 1001 } | |
| 1002 | |
| 1003 return true; | |
| 898 } | 1004 } |
| 1005 } | |
| OLD | NEW |