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 30 matching lines...) Expand all Loading... |
41 dict->SetBoolean("is_preconnect", is_preconnect); | 41 dict->SetBoolean("is_preconnect", is_preconnect); |
42 return std::move(dict); | 42 return std::move(dict); |
43 } | 43 } |
44 | 44 |
45 HttpStreamFactoryImpl::JobController::JobController( | 45 HttpStreamFactoryImpl::JobController::JobController( |
46 HttpStreamFactoryImpl* factory, | 46 HttpStreamFactoryImpl* factory, |
47 HttpStreamRequest::Delegate* delegate, | 47 HttpStreamRequest::Delegate* delegate, |
48 HttpNetworkSession* session, | 48 HttpNetworkSession* session, |
49 JobFactory* job_factory, | 49 JobFactory* job_factory, |
50 const HttpRequestInfo& request_info, | 50 const HttpRequestInfo& request_info, |
51 bool is_preconnect) | 51 bool is_preconnect, |
| 52 bool enable_ip_based_pooling) |
52 : factory_(factory), | 53 : factory_(factory), |
53 session_(session), | 54 session_(session), |
54 job_factory_(job_factory), | 55 job_factory_(job_factory), |
55 request_(nullptr), | 56 request_(nullptr), |
56 delegate_(delegate), | 57 delegate_(delegate), |
57 is_preconnect_(is_preconnect), | 58 is_preconnect_(is_preconnect), |
| 59 enable_ip_based_pooling_(enable_ip_based_pooling), |
58 alternative_job_net_error_(OK), | 60 alternative_job_net_error_(OK), |
59 job_bound_(false), | 61 job_bound_(false), |
60 main_job_is_blocked_(false), | 62 main_job_is_blocked_(false), |
61 main_job_is_resumed_(false), | 63 main_job_is_resumed_(false), |
62 bound_job_(nullptr), | 64 bound_job_(nullptr), |
63 can_start_alternative_proxy_job_(false), | 65 can_start_alternative_proxy_job_(false), |
64 privacy_mode_(PRIVACY_MODE_DISABLED), | 66 privacy_mode_(PRIVACY_MODE_DISABLED), |
65 net_log_( | 67 net_log_( |
66 NetLogWithSource::Make(session->net_log(), | 68 NetLogWithSource::Make(session->net_log(), |
67 NetLogSourceType::HTTP_STREAM_JOB_CONTROLLER)), | 69 NetLogSourceType::HTTP_STREAM_JOB_CONTROLLER)), |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 ignore_result(ApplyHostMappingRules(request_info.url, &destination)); | 144 ignore_result(ApplyHostMappingRules(request_info.url, &destination)); |
143 } | 145 } |
144 | 146 |
145 // Due to how the socket pools handle priorities and idle sockets, only IDLE | 147 // Due to how the socket pools handle priorities and idle sockets, only IDLE |
146 // priority currently makes sense for preconnects. The priority for | 148 // priority currently makes sense for preconnects. The priority for |
147 // preconnects is currently ignored (see RequestSocketsForPool()), but could | 149 // preconnects is currently ignored (see RequestSocketsForPool()), but could |
148 // be used at some point for proxy resolution or something. | 150 // be used at some point for proxy resolution or something. |
149 main_job_.reset(job_factory_->CreateJob( | 151 main_job_.reset(job_factory_->CreateJob( |
150 this, PRECONNECT, session_, request_info, IDLE, server_ssl_config, | 152 this, PRECONNECT, session_, request_info, IDLE, server_ssl_config, |
151 proxy_ssl_config, destination, origin_url, alternative_service, | 153 proxy_ssl_config, destination, origin_url, alternative_service, |
152 session_->net_log())); | 154 enable_ip_based_pooling_, session_->net_log())); |
153 main_job_->Preconnect(num_streams); | 155 main_job_->Preconnect(num_streams); |
154 } | 156 } |
155 | 157 |
156 LoadState HttpStreamFactoryImpl::JobController::GetLoadState() const { | 158 LoadState HttpStreamFactoryImpl::JobController::GetLoadState() const { |
157 DCHECK(request_); | 159 DCHECK(request_); |
158 DCHECK(main_job_ || alternative_job_); | 160 DCHECK(main_job_ || alternative_job_); |
159 if (bound_job_) | 161 if (bound_job_) |
160 return bound_job_->GetLoadState(); | 162 return bound_job_->GetLoadState(); |
161 | 163 |
162 // Just pick the first one. | 164 // Just pick the first one. |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 DCHECK_EQ(MAIN, job->job_type()); | 427 DCHECK_EQ(MAIN, job->job_type()); |
426 DCHECK(!alternative_job_); | 428 DCHECK(!alternative_job_); |
427 DCHECK(!main_job_is_blocked_); | 429 DCHECK(!main_job_is_blocked_); |
428 | 430 |
429 HostPortPair destination(HostPortPair::FromURL(request_info.url)); | 431 HostPortPair destination(HostPortPair::FromURL(request_info.url)); |
430 GURL origin_url = ApplyHostMappingRules(request_info.url, &destination); | 432 GURL origin_url = ApplyHostMappingRules(request_info.url, &destination); |
431 | 433 |
432 alternative_job_.reset(job_factory_->CreateJob( | 434 alternative_job_.reset(job_factory_->CreateJob( |
433 this, ALTERNATIVE, session_, request_info, priority, server_ssl_config, | 435 this, ALTERNATIVE, session_, request_info, priority, server_ssl_config, |
434 proxy_ssl_config, destination, origin_url, alternative_proxy_server, | 436 proxy_ssl_config, destination, origin_url, alternative_proxy_server, |
435 job->net_log().net_log())); | 437 enable_ip_based_pooling_, job->net_log().net_log())); |
436 AttachJob(alternative_job_.get()); | 438 AttachJob(alternative_job_.get()); |
437 | 439 |
438 can_start_alternative_proxy_job_ = false; | 440 can_start_alternative_proxy_job_ = false; |
439 main_job_is_blocked_ = true; | 441 main_job_is_blocked_ = true; |
440 | 442 |
441 base::ThreadTaskRunnerHandle::Get()->PostTask( | 443 base::ThreadTaskRunnerHandle::Get()->PostTask( |
442 FROM_HERE, | 444 FROM_HERE, |
443 base::Bind( | 445 base::Bind( |
444 &HttpStreamFactoryImpl::JobController::StartAlternativeProxyServerJob, | 446 &HttpStreamFactoryImpl::JobController::StartAlternativeProxyServerJob, |
445 ptr_factory_.GetWeakPtr())); | 447 ptr_factory_.GetWeakPtr())); |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 const SSLConfig& proxy_ssl_config, | 702 const SSLConfig& proxy_ssl_config, |
701 HttpStreamRequest::Delegate* delegate, | 703 HttpStreamRequest::Delegate* delegate, |
702 HttpStreamRequest::StreamType stream_type) { | 704 HttpStreamRequest::StreamType stream_type) { |
703 DCHECK(!main_job_); | 705 DCHECK(!main_job_); |
704 DCHECK(!alternative_job_); | 706 DCHECK(!alternative_job_); |
705 HostPortPair destination(HostPortPair::FromURL(request_info.url)); | 707 HostPortPair destination(HostPortPair::FromURL(request_info.url)); |
706 GURL origin_url = ApplyHostMappingRules(request_info.url, &destination); | 708 GURL origin_url = ApplyHostMappingRules(request_info.url, &destination); |
707 | 709 |
708 main_job_.reset(job_factory_->CreateJob( | 710 main_job_.reset(job_factory_->CreateJob( |
709 this, MAIN, session_, request_info, priority, server_ssl_config, | 711 this, MAIN, session_, request_info, priority, server_ssl_config, |
710 proxy_ssl_config, destination, origin_url, net_log_.net_log())); | 712 proxy_ssl_config, destination, origin_url, enable_ip_based_pooling_, |
| 713 net_log_.net_log())); |
711 AttachJob(main_job_.get()); | 714 AttachJob(main_job_.get()); |
712 | 715 |
713 // Create an alternative job if alternative service is set up for this domain. | 716 // Create an alternative job if alternative service is set up for this domain. |
714 const AlternativeService alternative_service = | 717 const AlternativeService alternative_service = |
715 GetAlternativeServiceFor(request_info, delegate, stream_type); | 718 GetAlternativeServiceFor(request_info, delegate, stream_type); |
716 | 719 |
717 if (alternative_service.protocol != kProtoUnknown) { | 720 if (alternative_service.protocol != kProtoUnknown) { |
718 // Never share connection with other jobs for FTP requests. | 721 // Never share connection with other jobs for FTP requests. |
719 DVLOG(1) << "Selected alternative service (host: " | 722 DVLOG(1) << "Selected alternative service (host: " |
720 << alternative_service.host_port_pair().host() | 723 << alternative_service.host_port_pair().host() |
721 << " port: " << alternative_service.host_port_pair().port() << ")"; | 724 << " port: " << alternative_service.host_port_pair().port() << ")"; |
722 | 725 |
723 DCHECK(!request_info.url.SchemeIs(url::kFtpScheme)); | 726 DCHECK(!request_info.url.SchemeIs(url::kFtpScheme)); |
724 HostPortPair alternative_destination(alternative_service.host_port_pair()); | 727 HostPortPair alternative_destination(alternative_service.host_port_pair()); |
725 ignore_result( | 728 ignore_result( |
726 ApplyHostMappingRules(request_info.url, &alternative_destination)); | 729 ApplyHostMappingRules(request_info.url, &alternative_destination)); |
727 | 730 |
728 alternative_job_.reset(job_factory_->CreateJob( | 731 alternative_job_.reset(job_factory_->CreateJob( |
729 this, ALTERNATIVE, session_, request_info, priority, server_ssl_config, | 732 this, ALTERNATIVE, session_, request_info, priority, server_ssl_config, |
730 proxy_ssl_config, alternative_destination, origin_url, | 733 proxy_ssl_config, alternative_destination, origin_url, |
731 alternative_service, net_log_.net_log())); | 734 alternative_service, enable_ip_based_pooling_, net_log_.net_log())); |
732 AttachJob(alternative_job_.get()); | 735 AttachJob(alternative_job_.get()); |
733 | 736 |
734 main_job_is_blocked_ = true; | 737 main_job_is_blocked_ = true; |
735 alternative_job_->Start(request_->stream_type()); | 738 alternative_job_->Start(request_->stream_type()); |
736 } else { | 739 } else { |
737 can_start_alternative_proxy_job_ = true; | 740 can_start_alternative_proxy_job_ = true; |
738 } | 741 } |
739 // Even if |alternative_job| has already finished, it will not have notified | 742 // Even if |alternative_job| has already finished, it will not have notified |
740 // the request yet, since we defer that to the next iteration of the | 743 // the request yet, since we defer that to the next iteration of the |
741 // MessageLoop, so starting |main_job_| is always safe. | 744 // MessageLoop, so starting |main_job_| is always safe. |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1170 return; | 1173 return; |
1171 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); | 1174 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); |
1172 alternative_job_->Start(request_->stream_type()); | 1175 alternative_job_->Start(request_->stream_type()); |
1173 } | 1176 } |
1174 | 1177 |
1175 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const { | 1178 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const { |
1176 return !request_ || (job_bound_ && bound_job_ != job); | 1179 return !request_ || (job_bound_ && bound_job_ != job); |
1177 } | 1180 } |
1178 | 1181 |
1179 } // namespace net | 1182 } // namespace net |
OLD | NEW |