| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 JobFactory* job_factory) | 43 JobFactory* job_factory) |
| 44 : factory_(factory), | 44 : factory_(factory), |
| 45 session_(session), | 45 session_(session), |
| 46 job_factory_(job_factory), | 46 job_factory_(job_factory), |
| 47 request_(nullptr), | 47 request_(nullptr), |
| 48 delegate_(delegate), | 48 delegate_(delegate), |
| 49 is_preconnect_(false), | 49 is_preconnect_(false), |
| 50 alternative_job_failed_(false), | 50 alternative_job_failed_(false), |
| 51 job_bound_(false), | 51 job_bound_(false), |
| 52 main_job_is_blocked_(false), | 52 main_job_is_blocked_(false), |
| 53 main_job_is_resumed_(false), |
| 53 bound_job_(nullptr), | 54 bound_job_(nullptr), |
| 54 can_start_alternative_proxy_job_(false), | 55 can_start_alternative_proxy_job_(false), |
| 55 ptr_factory_(this) { | 56 ptr_factory_(this) { |
| 56 DCHECK(factory); | 57 DCHECK(factory); |
| 57 } | 58 } |
| 58 | 59 |
| 59 HttpStreamFactoryImpl::JobController::~JobController() { | 60 HttpStreamFactoryImpl::JobController::~JobController() { |
| 60 main_job_.reset(); | 61 main_job_.reset(); |
| 61 alternative_job_.reset(); | 62 alternative_job_.reset(); |
| 62 bound_job_ = nullptr; | 63 bound_job_ = nullptr; |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 Job* job, | 510 Job* job, |
| 510 const ConnectionAttempts& attempts) { | 511 const ConnectionAttempts& attempts) { |
| 511 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) | 512 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) |
| 512 return; | 513 return; |
| 513 | 514 |
| 514 DCHECK(request_); | 515 DCHECK(request_); |
| 515 request_->AddConnectionAttempts(attempts); | 516 request_->AddConnectionAttempts(attempts); |
| 516 } | 517 } |
| 517 | 518 |
| 518 void HttpStreamFactoryImpl::JobController::ResumeMainJob() { | 519 void HttpStreamFactoryImpl::JobController::ResumeMainJob() { |
| 520 if (main_job_is_resumed_) |
| 521 return; |
| 522 |
| 523 main_job_is_resumed_ = true; |
| 519 main_job_->net_log().AddEvent( | 524 main_job_->net_log().AddEvent( |
| 520 NetLogEventType::HTTP_STREAM_JOB_DELAYED, | 525 NetLogEventType::HTTP_STREAM_JOB_DELAYED, |
| 521 base::Bind(&NetLogHttpStreamJobDelayCallback, main_job_wait_time_)); | 526 base::Bind(&NetLogHttpStreamJobDelayCallback, main_job_wait_time_)); |
| 522 | 527 |
| 523 main_job_->Resume(); | 528 main_job_->Resume(); |
| 524 main_job_wait_time_ = base::TimeDelta(); | 529 main_job_wait_time_ = base::TimeDelta(); |
| 525 } | 530 } |
| 526 | 531 |
| 527 void HttpStreamFactoryImpl::JobController::MaybeResumeMainJob( | 532 void HttpStreamFactoryImpl::JobController::MaybeResumeMainJob( |
| 528 Job* job, | 533 Job* job, |
| 529 const base::TimeDelta& delay) { | 534 const base::TimeDelta& delay) { |
| 535 DCHECK(delay == base::TimeDelta() || delay == main_job_wait_time_); |
| 530 DCHECK(job == main_job_.get() || job == alternative_job_.get()); | 536 DCHECK(job == main_job_.get() || job == alternative_job_.get()); |
| 531 | 537 |
| 532 if (!main_job_is_blocked_ || job != alternative_job_.get() || !main_job_) | 538 if (job != alternative_job_.get() || !main_job_) |
| 533 return; | 539 return; |
| 534 | 540 |
| 535 main_job_is_blocked_ = false; | 541 main_job_is_blocked_ = false; |
| 536 | 542 |
| 537 if (!main_job_->is_waiting()) | 543 if (!main_job_->is_waiting()) { |
| 544 // There are two cases where the main job is not in WAIT state: |
| 545 // 1) The main job hasn't got to waiting state, do not yet post a task to |
| 546 // resume since that will happen in ShouldWait(). |
| 547 // 2) The main job has passed waiting state, so the main job does not need |
| 548 // to be resumed. |
| 538 return; | 549 return; |
| 550 } |
| 551 |
| 552 main_job_wait_time_ = delay; |
| 539 | 553 |
| 540 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 554 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 541 FROM_HERE, | 555 FROM_HERE, |
| 542 base::Bind(&HttpStreamFactoryImpl::JobController::ResumeMainJob, | 556 base::Bind(&HttpStreamFactoryImpl::JobController::ResumeMainJob, |
| 543 ptr_factory_.GetWeakPtr()), | 557 ptr_factory_.GetWeakPtr()), |
| 544 main_job_wait_time_); | 558 main_job_wait_time_); |
| 545 } | 559 } |
| 546 | 560 |
| 547 void HttpStreamFactoryImpl::JobController::OnConnectionInitialized(Job* job, | 561 void HttpStreamFactoryImpl::JobController::OnConnectionInitialized(Job* job, |
| 548 int rv) { | 562 int rv) { |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1097 return; | 1111 return; |
| 1098 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); | 1112 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); |
| 1099 alternative_job_->Start(request_->stream_type()); | 1113 alternative_job_->Start(request_->stream_type()); |
| 1100 } | 1114 } |
| 1101 | 1115 |
| 1102 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const { | 1116 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const { |
| 1103 return !request_ || (job_bound_ && bound_job_ != job); | 1117 return !request_ || (job_bound_ && bound_job_ != job); |
| 1104 } | 1118 } |
| 1105 | 1119 |
| 1106 } // namespace net | 1120 } // namespace net |
| OLD | NEW |