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 <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())); |
|
Zhongyi Shi
2017/03/29 03:05:06
This is trying to start a alternative proxy job, j
Bence
2017/03/29 16:46:08
That is correct.
In fact, in a follow-up CL, I wi
Zhongyi Shi
2017/03/30 22:33:02
SGTM!
| |
| 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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 698 const SSLConfig& proxy_ssl_config, | 700 const SSLConfig& proxy_ssl_config, |
| 699 HttpStreamRequest::Delegate* delegate, | 701 HttpStreamRequest::Delegate* delegate, |
| 700 HttpStreamRequest::StreamType stream_type) { | 702 HttpStreamRequest::StreamType stream_type) { |
| 701 DCHECK(!main_job_); | 703 DCHECK(!main_job_); |
| 702 DCHECK(!alternative_job_); | 704 DCHECK(!alternative_job_); |
| 703 HostPortPair destination(HostPortPair::FromURL(request_info.url)); | 705 HostPortPair destination(HostPortPair::FromURL(request_info.url)); |
| 704 GURL origin_url = ApplyHostMappingRules(request_info.url, &destination); | 706 GURL origin_url = ApplyHostMappingRules(request_info.url, &destination); |
| 705 | 707 |
| 706 main_job_.reset(job_factory_->CreateJob( | 708 main_job_.reset(job_factory_->CreateJob( |
| 707 this, MAIN, session_, request_info, priority, server_ssl_config, | 709 this, MAIN, session_, request_info, priority, server_ssl_config, |
| 708 proxy_ssl_config, destination, origin_url, net_log_.net_log())); | 710 proxy_ssl_config, destination, origin_url, enable_ip_based_pooling_, |
| 711 net_log_.net_log())); | |
| 709 AttachJob(main_job_.get()); | 712 AttachJob(main_job_.get()); |
| 710 | 713 |
| 711 // Create an alternative job if alternative service is set up for this domain. | 714 // Create an alternative job if alternative service is set up for this domain. |
| 712 const AlternativeService alternative_service = | 715 const AlternativeService alternative_service = |
| 713 GetAlternativeServiceFor(request_info, delegate, stream_type); | 716 GetAlternativeServiceFor(request_info, delegate, stream_type); |
| 714 | 717 |
| 715 if (alternative_service.protocol != kProtoUnknown) { | 718 if (alternative_service.protocol != kProtoUnknown) { |
| 716 // Never share connection with other jobs for FTP requests. | 719 // Never share connection with other jobs for FTP requests. |
| 717 DVLOG(1) << "Selected alternative service (host: " | 720 DVLOG(1) << "Selected alternative service (host: " |
| 718 << alternative_service.host_port_pair().host() | 721 << alternative_service.host_port_pair().host() |
| 719 << " port: " << alternative_service.host_port_pair().port() << ")"; | 722 << " port: " << alternative_service.host_port_pair().port() << ")"; |
| 720 | 723 |
| 721 DCHECK(!request_info.url.SchemeIs(url::kFtpScheme)); | 724 DCHECK(!request_info.url.SchemeIs(url::kFtpScheme)); |
| 722 HostPortPair alternative_destination(alternative_service.host_port_pair()); | 725 HostPortPair alternative_destination(alternative_service.host_port_pair()); |
| 723 ignore_result( | 726 ignore_result( |
| 724 ApplyHostMappingRules(request_info.url, &alternative_destination)); | 727 ApplyHostMappingRules(request_info.url, &alternative_destination)); |
| 725 | 728 |
| 726 alternative_job_.reset(job_factory_->CreateJob( | 729 alternative_job_.reset(job_factory_->CreateJob( |
| 727 this, ALTERNATIVE, session_, request_info, priority, server_ssl_config, | 730 this, ALTERNATIVE, session_, request_info, priority, server_ssl_config, |
| 728 proxy_ssl_config, alternative_destination, origin_url, | 731 proxy_ssl_config, alternative_destination, origin_url, |
| 729 alternative_service, net_log_.net_log())); | 732 alternative_service, enable_ip_based_pooling_, net_log_.net_log())); |
| 730 AttachJob(alternative_job_.get()); | 733 AttachJob(alternative_job_.get()); |
| 731 | 734 |
| 732 main_job_is_blocked_ = true; | 735 main_job_is_blocked_ = true; |
| 733 alternative_job_->Start(request_->stream_type()); | 736 alternative_job_->Start(request_->stream_type()); |
| 734 } else { | 737 } else { |
| 735 can_start_alternative_proxy_job_ = true; | 738 can_start_alternative_proxy_job_ = true; |
| 736 } | 739 } |
| 737 // Even if |alternative_job| has already finished, it will not have notified | 740 // Even if |alternative_job| has already finished, it will not have notified |
| 738 // the request yet, since we defer that to the next iteration of the | 741 // the request yet, since we defer that to the next iteration of the |
| 739 // MessageLoop, so starting |main_job_| is always safe. | 742 // MessageLoop, so starting |main_job_| is always safe. |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1168 return; | 1171 return; |
| 1169 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); | 1172 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); |
| 1170 alternative_job_->Start(request_->stream_type()); | 1173 alternative_job_->Start(request_->stream_type()); |
| 1171 } | 1174 } |
| 1172 | 1175 |
| 1173 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const { | 1176 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const { |
| 1174 return !request_ || (job_bound_ && bound_job_ != job); | 1177 return !request_ || (job_bound_ && bound_job_ != job); |
| 1175 } | 1178 } |
| 1176 | 1179 |
| 1177 } // namespace net | 1180 } // namespace net |
| OLD | NEW |