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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 bool is_preconnect) | 56 bool is_preconnect) |
| 57 : factory_(factory), | 57 : factory_(factory), |
| 58 session_(session), | 58 session_(session), |
| 59 job_factory_(job_factory), | 59 job_factory_(job_factory), |
| 60 request_(nullptr), | 60 request_(nullptr), |
| 61 delegate_(delegate), | 61 delegate_(delegate), |
| 62 is_preconnect_(is_preconnect), | 62 is_preconnect_(is_preconnect), |
| 63 alternative_job_net_error_(OK), | 63 alternative_job_net_error_(OK), |
| 64 job_bound_(false), | 64 job_bound_(false), |
| 65 main_job_is_blocked_(false), | 65 main_job_is_blocked_(false), |
| 66 main_job_is_resumed_(false), | |
| 66 bound_job_(nullptr), | 67 bound_job_(nullptr), |
| 67 can_start_alternative_proxy_job_(false), | 68 can_start_alternative_proxy_job_(false), |
| 68 privacy_mode_(PRIVACY_MODE_DISABLED), | 69 privacy_mode_(PRIVACY_MODE_DISABLED), |
| 69 net_log_( | 70 net_log_( |
| 70 NetLogWithSource::Make(session->net_log(), | 71 NetLogWithSource::Make(session->net_log(), |
| 71 NetLogSourceType::HTTP_STREAM_JOB_CONTROLLER)), | 72 NetLogSourceType::HTTP_STREAM_JOB_CONTROLLER)), |
| 72 ptr_factory_(this) { | 73 ptr_factory_(this) { |
| 73 DCHECK(factory); | 74 DCHECK(factory); |
| 74 net_log_.BeginEvent(NetLogEventType::HTTP_STREAM_JOB_CONTROLLER, | 75 net_log_.BeginEvent(NetLogEventType::HTTP_STREAM_JOB_CONTROLLER, |
| 75 base::Bind(&NetLogJobControllerCallback, | 76 base::Bind(&NetLogJobControllerCallback, |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 540 Job* job, | 541 Job* job, |
| 541 const ConnectionAttempts& attempts) { | 542 const ConnectionAttempts& attempts) { |
| 542 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) | 543 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) |
| 543 return; | 544 return; |
| 544 | 545 |
| 545 DCHECK(request_); | 546 DCHECK(request_); |
| 546 request_->AddConnectionAttempts(attempts); | 547 request_->AddConnectionAttempts(attempts); |
| 547 } | 548 } |
| 548 | 549 |
| 549 void HttpStreamFactoryImpl::JobController::ResumeMainJob() { | 550 void HttpStreamFactoryImpl::JobController::ResumeMainJob() { |
| 551 if (main_job_is_resumed_) | |
| 552 return; | |
| 553 | |
| 554 main_job_is_resumed_ = true; | |
| 550 main_job_->net_log().AddEvent( | 555 main_job_->net_log().AddEvent( |
| 551 NetLogEventType::HTTP_STREAM_JOB_DELAYED, | 556 NetLogEventType::HTTP_STREAM_JOB_DELAYED, |
| 552 base::Bind(&NetLogHttpStreamJobDelayCallback, main_job_wait_time_)); | 557 base::Bind(&NetLogHttpStreamJobDelayCallback, main_job_wait_time_)); |
| 553 | 558 |
| 554 main_job_->Resume(); | 559 main_job_->Resume(); |
| 555 main_job_wait_time_ = base::TimeDelta(); | 560 main_job_wait_time_ = base::TimeDelta(); |
| 556 } | 561 } |
| 557 | 562 |
| 558 void HttpStreamFactoryImpl::JobController::MaybeResumeMainJob( | 563 void HttpStreamFactoryImpl::JobController::MaybeResumeMainJob( |
| 559 Job* job, | 564 Job* job, |
| 560 const base::TimeDelta& delay) { | 565 const base::TimeDelta& delay) { |
| 566 DCHECK(delay == base::TimeDelta() || delay == main_job_wait_time_); | |
| 561 DCHECK(job == main_job_.get() || job == alternative_job_.get()); | 567 DCHECK(job == main_job_.get() || job == alternative_job_.get()); |
| 562 | 568 |
| 563 if (!main_job_is_blocked_ || job != alternative_job_.get() || !main_job_) | 569 if (main_job_is_resumed_ || job != alternative_job_.get() || !main_job_) |
| 564 return; | 570 return; |
| 565 | 571 |
| 566 main_job_is_blocked_ = false; | 572 if (!main_job_->is_waiting()) { |
| 573 main_job_is_blocked_ = false; | |
| 574 return; | |
| 575 } | |
| 567 | 576 |
| 568 if (!main_job_->is_waiting()) | 577 if (!main_job_is_blocked_) { |
| 569 return; | 578 // A task has been posted earlier to resume the main job, though not |
| 579 // executed. This task will now resume the main job immediately. | |
| 580 main_job_wait_time_ = base::TimeDelta(); | |
| 581 DCHECK(delay == base::TimeDelta()); | |
|
Ryan Hamilton
2017/02/15 00:07:02
I don't quite understand this block. I would think
Zhongyi Shi
2017/02/15 00:26:58
Done.
| |
| 582 } | |
| 570 | 583 |
| 571 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 584 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 572 FROM_HERE, | 585 FROM_HERE, |
| 573 base::Bind(&HttpStreamFactoryImpl::JobController::ResumeMainJob, | 586 base::Bind(&HttpStreamFactoryImpl::JobController::ResumeMainJob, |
| 574 ptr_factory_.GetWeakPtr()), | 587 ptr_factory_.GetWeakPtr()), |
| 575 main_job_wait_time_); | 588 delay); |
| 589 main_job_is_blocked_ = false; | |
| 576 } | 590 } |
| 577 | 591 |
| 578 void HttpStreamFactoryImpl::JobController::OnConnectionInitialized(Job* job, | 592 void HttpStreamFactoryImpl::JobController::OnConnectionInitialized(Job* job, |
| 579 int rv) { | 593 int rv) { |
| 580 if (rv != OK) { | 594 if (rv != OK) { |
| 581 // Resume the main job as there's an error raised in connection | 595 // Resume the main job as there's an error raised in connection |
| 582 // initiation. | 596 // initiation. |
| 583 return MaybeResumeMainJob(job, main_job_wait_time_); | 597 return MaybeResumeMainJob(job, main_job_wait_time_); |
| 584 } | 598 } |
| 585 } | 599 } |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1156 return; | 1170 return; |
| 1157 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); | 1171 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); |
| 1158 alternative_job_->Start(request_->stream_type()); | 1172 alternative_job_->Start(request_->stream_type()); |
| 1159 } | 1173 } |
| 1160 | 1174 |
| 1161 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const { | 1175 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const { |
| 1162 return !request_ || (job_bound_ && bound_job_ != job); | 1176 return !request_ || (job_bound_ && bound_job_ != job); |
| 1163 } | 1177 } |
| 1164 | 1178 |
| 1165 } // namespace net | 1179 } // namespace net |
| OLD | NEW |