| 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 |
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "net/base/host_mapping_rules.h" | 16 #include "net/base/host_mapping_rules.h" |
| 17 #include "net/base/proxy_delegate.h" | 17 #include "net/base/proxy_delegate.h" |
| 18 #include "net/http/bidirectional_stream_impl.h" | 18 #include "net/http/bidirectional_stream_impl.h" |
| 19 #include "net/http/transport_security_state.h" | 19 #include "net/http/transport_security_state.h" |
| 20 #include "net/log/net_log_capture_mode.h" | 20 #include "net/log/net_log_capture_mode.h" |
| 21 #include "net/log/net_log_event_type.h" | 21 #include "net/log/net_log_event_type.h" |
| 22 #include "net/log/net_log_source.h" | 22 #include "net/log/net_log_source.h" |
| 23 #include "net/log/net_log_with_source.h" | 23 #include "net/log/net_log_with_source.h" |
| 24 #include "net/proxy/proxy_server.h" | 24 #include "net/proxy/proxy_server.h" |
| 25 #include "net/spdy/spdy_session.h" | 25 #include "net/spdy/spdy_session.h" |
| 26 #include "url/url_constants.h" | 26 #include "url/url_constants.h" |
| 27 | 27 |
| 28 namespace net { | 28 namespace net { |
| 29 | 29 |
| 30 // Returns parameters associated with the delay of the HTTP stream job. |
| 31 std::unique_ptr<base::Value> NetLogHttpStreamJobDelayCallback( |
| 32 base::TimeDelta delay, |
| 33 NetLogCaptureMode /* capture_mode */) { |
| 34 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 35 dict->SetInteger("resume_after_ms", static_cast<int>(delay.InMilliseconds())); |
| 36 return std::move(dict); |
| 37 } |
| 38 |
| 30 HttpStreamFactoryImpl::JobController::JobController( | 39 HttpStreamFactoryImpl::JobController::JobController( |
| 31 HttpStreamFactoryImpl* factory, | 40 HttpStreamFactoryImpl* factory, |
| 32 HttpStreamRequest::Delegate* delegate, | 41 HttpStreamRequest::Delegate* delegate, |
| 33 HttpNetworkSession* session, | 42 HttpNetworkSession* session, |
| 34 JobFactory* job_factory) | 43 JobFactory* job_factory) |
| 35 : factory_(factory), | 44 : factory_(factory), |
| 36 session_(session), | 45 session_(session), |
| 37 job_factory_(job_factory), | 46 job_factory_(job_factory), |
| 38 request_(nullptr), | 47 request_(nullptr), |
| 39 delegate_(delegate), | 48 delegate_(delegate), |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 void HttpStreamFactoryImpl::JobController::AddConnectionAttemptsToRequest( | 508 void HttpStreamFactoryImpl::JobController::AddConnectionAttemptsToRequest( |
| 500 Job* job, | 509 Job* job, |
| 501 const ConnectionAttempts& attempts) { | 510 const ConnectionAttempts& attempts) { |
| 502 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) | 511 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) |
| 503 return; | 512 return; |
| 504 | 513 |
| 505 DCHECK(request_); | 514 DCHECK(request_); |
| 506 request_->AddConnectionAttempts(attempts); | 515 request_->AddConnectionAttempts(attempts); |
| 507 } | 516 } |
| 508 | 517 |
| 509 void HttpStreamFactoryImpl::JobController::ResumeMainJobLater( | |
| 510 const base::TimeDelta& delay) { | |
| 511 net_log_.AddEvent(NetLogEventType::HTTP_STREAM_JOB_DELAYED, | |
| 512 NetLog::Int64Callback("delay", delay.InMilliseconds())); | |
| 513 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 514 FROM_HERE, | |
| 515 base::Bind(&HttpStreamFactoryImpl::JobController::ResumeMainJob, | |
| 516 ptr_factory_.GetWeakPtr()), | |
| 517 delay); | |
| 518 } | |
| 519 | |
| 520 void HttpStreamFactoryImpl::JobController::ResumeMainJob() { | 518 void HttpStreamFactoryImpl::JobController::ResumeMainJob() { |
| 521 main_job_->net_log().AddEvent( | 519 main_job_->net_log().AddEvent( |
| 522 NetLogEventType::HTTP_STREAM_JOB_RESUMED, | 520 NetLogEventType::HTTP_STREAM_JOB_DELAYED, |
| 523 NetLog::Int64Callback("delay", main_job_wait_time_.InMilliseconds())); | 521 base::Bind(&NetLogHttpStreamJobDelayCallback, main_job_wait_time_)); |
| 524 | 522 |
| 525 main_job_->Resume(); | 523 main_job_->Resume(); |
| 526 main_job_wait_time_ = base::TimeDelta(); | 524 main_job_wait_time_ = base::TimeDelta(); |
| 527 } | 525 } |
| 528 | 526 |
| 529 void HttpStreamFactoryImpl::JobController::MaybeResumeMainJob( | 527 void HttpStreamFactoryImpl::JobController::MaybeResumeMainJob( |
| 530 Job* job, | 528 Job* job, |
| 531 const base::TimeDelta& delay) { | 529 const base::TimeDelta& delay) { |
| 532 DCHECK(job == main_job_.get() || job == alternative_job_.get()); | 530 DCHECK(job == main_job_.get() || job == alternative_job_.get()); |
| 533 | 531 |
| 534 if (!main_job_is_blocked_ || job != alternative_job_.get() || !main_job_) | 532 if (!main_job_is_blocked_ || job != alternative_job_.get() || !main_job_) |
| 535 return; | 533 return; |
| 536 | 534 |
| 537 main_job_is_blocked_ = false; | 535 main_job_is_blocked_ = false; |
| 538 | 536 |
| 539 if (!main_job_->is_waiting()) | 537 if (!main_job_->is_waiting()) |
| 540 return; | 538 return; |
| 541 | 539 |
| 542 ResumeMainJobLater(main_job_wait_time_); | 540 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 541 FROM_HERE, |
| 542 base::Bind(&HttpStreamFactoryImpl::JobController::ResumeMainJob, |
| 543 ptr_factory_.GetWeakPtr()), |
| 544 main_job_wait_time_); |
| 543 } | 545 } |
| 544 | 546 |
| 545 void HttpStreamFactoryImpl::JobController::OnConnectionInitialized(Job* job, | 547 void HttpStreamFactoryImpl::JobController::OnConnectionInitialized(Job* job, |
| 546 int rv) { | 548 int rv) { |
| 547 if (rv != OK) { | 549 if (rv != OK) { |
| 548 // Resume the main job as there's an error raised in connection | 550 // Resume the main job as there's an error raised in connection |
| 549 // initiation. | 551 // initiation. |
| 550 return MaybeResumeMainJob(job, main_job_wait_time_); | 552 return MaybeResumeMainJob(job, main_job_wait_time_); |
| 551 } | 553 } |
| 552 } | 554 } |
| 553 | 555 |
| 554 bool HttpStreamFactoryImpl::JobController::ShouldWait(Job* job) { | 556 bool HttpStreamFactoryImpl::JobController::ShouldWait(Job* job) { |
| 555 // The alternative job never waits. | 557 // The alternative job never waits. |
| 556 if (job == alternative_job_.get()) | 558 if (job == alternative_job_.get()) |
| 557 return false; | 559 return false; |
| 558 | 560 |
| 559 if (main_job_is_blocked_) | 561 if (main_job_is_blocked_) |
| 560 return true; | 562 return true; |
| 561 | 563 |
| 562 if (main_job_wait_time_.is_zero()) | 564 if (main_job_wait_time_.is_zero()) |
| 563 return false; | 565 return false; |
| 564 | 566 |
| 565 ResumeMainJobLater(main_job_wait_time_); | 567 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 568 FROM_HERE, |
| 569 base::Bind(&HttpStreamFactoryImpl::JobController::ResumeMainJob, |
| 570 ptr_factory_.GetWeakPtr()), |
| 571 main_job_wait_time_); |
| 572 |
| 566 return true; | 573 return true; |
| 567 } | 574 } |
| 568 | 575 |
| 569 void HttpStreamFactoryImpl::JobController::SetSpdySessionKey( | 576 void HttpStreamFactoryImpl::JobController::SetSpdySessionKey( |
| 570 Job* job, | 577 Job* job, |
| 571 const SpdySessionKey& spdy_session_key) { | 578 const SpdySessionKey& spdy_session_key) { |
| 572 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) | 579 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) |
| 573 return; | 580 return; |
| 574 | 581 |
| 575 DCHECK(request_); | 582 DCHECK(request_); |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1090 return; | 1097 return; |
| 1091 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); | 1098 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); |
| 1092 alternative_job_->Start(request_->stream_type()); | 1099 alternative_job_->Start(request_->stream_type()); |
| 1093 } | 1100 } |
| 1094 | 1101 |
| 1095 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const { | 1102 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const { |
| 1096 return !request_ || (job_bound_ && bound_job_ != job); | 1103 return !request_ || (job_bound_ && bound_job_ != job); |
| 1097 } | 1104 } |
| 1098 | 1105 |
| 1099 } // namespace net | 1106 } // namespace net |
| OLD | NEW |