Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: net/http/http_stream_factory_impl_job_controller.cc

Issue 2699433003: Add net-log entries when HttpStream jobs are forced to wait, and when they're delayed and resumed. (Closed)
Patch Set: fix comments from eroman Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_stream_factory_impl_job_controller.h ('k') | net/log/net_log_event_type_list.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10 matching lines...) Expand all
21 #include "net/log/net_log_capture_mode.h" 21 #include "net/log/net_log_capture_mode.h"
22 #include "net/log/net_log_event_type.h" 22 #include "net/log/net_log_event_type.h"
23 #include "net/log/net_log_source.h" 23 #include "net/log/net_log_source.h"
24 #include "net/log/net_log_with_source.h" 24 #include "net/log/net_log_with_source.h"
25 #include "net/proxy/proxy_server.h" 25 #include "net/proxy/proxy_server.h"
26 #include "net/spdy/spdy_session.h" 26 #include "net/spdy/spdy_session.h"
27 #include "url/url_constants.h" 27 #include "url/url_constants.h"
28 28
29 namespace net { 29 namespace net {
30 30
31 // Returns parameters associated with the delay of the HTTP stream job.
32 std::unique_ptr<base::Value> NetLogHttpStreamJobDelayCallback(
33 base::TimeDelta delay,
34 NetLogCaptureMode /* capture_mode */) {
35 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
36 dict->SetInteger("resume_after_ms", static_cast<int>(delay.InMilliseconds()));
37 return std::move(dict);
38 }
39
40 std::unique_ptr<base::Value> NetLogJobControllerCallback( 31 std::unique_ptr<base::Value> NetLogJobControllerCallback(
41 const GURL* url, 32 const GURL* url,
42 bool is_preconnect, 33 bool is_preconnect,
43 NetLogCaptureMode /* capture_mode */) { 34 NetLogCaptureMode /* capture_mode */) {
44 auto dict = base::MakeUnique<base::DictionaryValue>(); 35 auto dict = base::MakeUnique<base::DictionaryValue>();
45 dict->SetString("url", url->possibly_invalid_spec()); 36 dict->SetString("url", url->possibly_invalid_spec());
46 dict->SetBoolean("is_preconnect", is_preconnect); 37 dict->SetBoolean("is_preconnect", is_preconnect);
47 return std::move(dict); 38 return std::move(dict);
48 } 39 }
49 40
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 void HttpStreamFactoryImpl::JobController::AddConnectionAttemptsToRequest( 530 void HttpStreamFactoryImpl::JobController::AddConnectionAttemptsToRequest(
540 Job* job, 531 Job* job,
541 const ConnectionAttempts& attempts) { 532 const ConnectionAttempts& attempts) {
542 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) 533 if (is_preconnect_ || (job_bound_ && bound_job_ != job))
543 return; 534 return;
544 535
545 DCHECK(request_); 536 DCHECK(request_);
546 request_->AddConnectionAttempts(attempts); 537 request_->AddConnectionAttempts(attempts);
547 } 538 }
548 539
540 void HttpStreamFactoryImpl::JobController::ResumeMainJobLater(
541 const base::TimeDelta& delay) {
542 net_log_.AddEvent(NetLogEventType::HTTP_STREAM_JOB_DELAYED,
543 NetLog::Int64Callback("delay", delay.InMilliseconds()));
eroman 2017/02/14 21:46:36 I guess the downside to my recommendation here is
Ryan Hamilton 2017/02/14 22:18:16 Yeah, I'm totally fine with that 'cause it's two d
544 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
545 FROM_HERE,
546 base::Bind(&HttpStreamFactoryImpl::JobController::ResumeMainJob,
547 ptr_factory_.GetWeakPtr()),
548 delay);
549 }
550
549 void HttpStreamFactoryImpl::JobController::ResumeMainJob() { 551 void HttpStreamFactoryImpl::JobController::ResumeMainJob() {
550 main_job_->net_log().AddEvent( 552 main_job_->net_log().AddEvent(
551 NetLogEventType::HTTP_STREAM_JOB_DELAYED, 553 NetLogEventType::HTTP_STREAM_JOB_RESUMED,
552 base::Bind(&NetLogHttpStreamJobDelayCallback, main_job_wait_time_)); 554 NetLog::Int64Callback("delay", main_job_wait_time_.InMilliseconds()));
553 555
554 main_job_->Resume(); 556 main_job_->Resume();
555 main_job_wait_time_ = base::TimeDelta(); 557 main_job_wait_time_ = base::TimeDelta();
556 } 558 }
557 559
558 void HttpStreamFactoryImpl::JobController::MaybeResumeMainJob( 560 void HttpStreamFactoryImpl::JobController::MaybeResumeMainJob(
559 Job* job, 561 Job* job,
560 const base::TimeDelta& delay) { 562 const base::TimeDelta& delay) {
561 DCHECK(job == main_job_.get() || job == alternative_job_.get()); 563 DCHECK(job == main_job_.get() || job == alternative_job_.get());
562 564
563 if (!main_job_is_blocked_ || job != alternative_job_.get() || !main_job_) 565 if (!main_job_is_blocked_ || job != alternative_job_.get() || !main_job_)
564 return; 566 return;
565 567
566 main_job_is_blocked_ = false; 568 main_job_is_blocked_ = false;
567 569
568 if (!main_job_->is_waiting()) 570 if (!main_job_->is_waiting())
569 return; 571 return;
570 572
571 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 573 ResumeMainJobLater(main_job_wait_time_);
572 FROM_HERE,
573 base::Bind(&HttpStreamFactoryImpl::JobController::ResumeMainJob,
574 ptr_factory_.GetWeakPtr()),
575 main_job_wait_time_);
576 } 574 }
577 575
578 void HttpStreamFactoryImpl::JobController::OnConnectionInitialized(Job* job, 576 void HttpStreamFactoryImpl::JobController::OnConnectionInitialized(Job* job,
579 int rv) { 577 int rv) {
580 if (rv != OK) { 578 if (rv != OK) {
581 // Resume the main job as there's an error raised in connection 579 // Resume the main job as there's an error raised in connection
582 // initiation. 580 // initiation.
583 return MaybeResumeMainJob(job, main_job_wait_time_); 581 return MaybeResumeMainJob(job, main_job_wait_time_);
584 } 582 }
585 } 583 }
586 584
587 bool HttpStreamFactoryImpl::JobController::ShouldWait(Job* job) { 585 bool HttpStreamFactoryImpl::JobController::ShouldWait(Job* job) {
588 // The alternative job never waits. 586 // The alternative job never waits.
589 if (job == alternative_job_.get()) 587 if (job == alternative_job_.get())
590 return false; 588 return false;
591 589
592 if (main_job_is_blocked_) 590 if (main_job_is_blocked_)
593 return true; 591 return true;
594 592
595 if (main_job_wait_time_.is_zero()) 593 if (main_job_wait_time_.is_zero())
596 return false; 594 return false;
597 595
598 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 596 ResumeMainJobLater(main_job_wait_time_);
599 FROM_HERE,
600 base::Bind(&HttpStreamFactoryImpl::JobController::ResumeMainJob,
601 ptr_factory_.GetWeakPtr()),
602 main_job_wait_time_);
603
604 return true; 597 return true;
605 } 598 }
606 599
607 void HttpStreamFactoryImpl::JobController::SetSpdySessionKey( 600 void HttpStreamFactoryImpl::JobController::SetSpdySessionKey(
608 Job* job, 601 Job* job,
609 const SpdySessionKey& spdy_session_key) { 602 const SpdySessionKey& spdy_session_key) {
610 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) 603 if (is_preconnect_ || (job_bound_ && bound_job_ != job))
611 return; 604 return;
612 605
613 DCHECK(request_); 606 DCHECK(request_);
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 return; 1149 return;
1157 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); 1150 DCHECK(alternative_job_->alternative_proxy_server().is_valid());
1158 alternative_job_->Start(request_->stream_type()); 1151 alternative_job_->Start(request_->stream_type());
1159 } 1152 }
1160 1153
1161 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const { 1154 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const {
1162 return !request_ || (job_bound_ && bound_job_ != job); 1155 return !request_ || (job_bound_ && bound_job_ != job);
1163 } 1156 }
1164 1157
1165 } // namespace net 1158 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl_job_controller.h ('k') | net/log/net_log_event_type_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698