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

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

Issue 2621983004: Improve HttpStreamFactory NetLog events (Closed)
Patch Set: Created 3 years, 11 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
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 18 matching lines...) Expand all
29 29
30 // Returns parameters associated with the delay of the HTTP stream job. 30 // Returns parameters associated with the delay of the HTTP stream job.
31 std::unique_ptr<base::Value> NetLogHttpStreamJobDelayCallback( 31 std::unique_ptr<base::Value> NetLogHttpStreamJobDelayCallback(
32 base::TimeDelta delay, 32 base::TimeDelta delay,
33 NetLogCaptureMode /* capture_mode */) { 33 NetLogCaptureMode /* capture_mode */) {
34 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 34 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
35 dict->SetInteger("resume_after_ms", static_cast<int>(delay.InMilliseconds())); 35 dict->SetInteger("resume_after_ms", static_cast<int>(delay.InMilliseconds()));
36 return std::move(dict); 36 return std::move(dict);
37 } 37 }
38 38
39 // Returns parameters associated with the start of a JobController.
40 std::unique_ptr<base::Value> NetLogJobControllerCallback(
41 const NetLogSource& source,
42 bool is_preconnect,
43 NetLogCaptureMode /* capture_mode */) {
44 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
45 if (source.IsValid())
46 source.AddToEventParameters(dict.get());
47 dict->SetBoolean("is_preconnect", is_preconnect);
48 return std::move(dict);
49 }
50
39 HttpStreamFactoryImpl::JobController::JobController( 51 HttpStreamFactoryImpl::JobController::JobController(
40 HttpStreamFactoryImpl* factory, 52 HttpStreamFactoryImpl* factory,
41 HttpStreamRequest::Delegate* delegate, 53 HttpStreamRequest::Delegate* delegate,
42 HttpNetworkSession* session, 54 HttpNetworkSession* session,
43 JobFactory* job_factory) 55 JobFactory* job_factory,
56 bool is_preconnect,
57 const NetLogWithSource& net_log)
44 : factory_(factory), 58 : factory_(factory),
45 session_(session), 59 session_(session),
46 job_factory_(job_factory), 60 job_factory_(job_factory),
47 request_(nullptr), 61 request_(nullptr),
48 delegate_(delegate), 62 delegate_(delegate),
49 is_preconnect_(false), 63 is_preconnect_(is_preconnect),
50 alternative_job_failed_(false), 64 alternative_job_failed_(false),
51 job_bound_(false), 65 job_bound_(false),
52 main_job_is_blocked_(false), 66 main_job_is_blocked_(false),
53 bound_job_(nullptr), 67 bound_job_(nullptr),
54 can_start_alternative_proxy_job_(false), 68 can_start_alternative_proxy_job_(false),
69 net_log_(
70 NetLogWithSource::Make(net_log.net_log(),
71 NetLogSourceType::HTTP_STREAM_JOB_CONTROLLER)),
55 ptr_factory_(this) { 72 ptr_factory_(this) {
56 DCHECK(factory); 73 DCHECK(factory);
74 net_log.AddEvent(NetLogEventType::HTTP_STREAM_JOB_CONTROLLER,
75 net_log_.source().ToEventParametersCallback());
76 net_log_.BeginEvent(NetLogEventType::HTTP_STREAM_JOB_CONTROLLER,
77 base::Bind(&NetLogJobControllerCallback, net_log.source(),
78 is_preconnect));
57 } 79 }
58 80
59 HttpStreamFactoryImpl::JobController::~JobController() { 81 HttpStreamFactoryImpl::JobController::~JobController() {
60 main_job_.reset(); 82 main_job_.reset();
61 alternative_job_.reset(); 83 alternative_job_.reset();
62 bound_job_ = nullptr; 84 bound_job_ = nullptr;
85 net_log_.EndEvent(NetLogEventType::HTTP_STREAM_JOB_CONTROLLER);
63 } 86 }
64 87
65 bool HttpStreamFactoryImpl::JobController::for_websockets() { 88 bool HttpStreamFactoryImpl::JobController::for_websockets() {
66 return factory_->for_websockets_; 89 return factory_->for_websockets_;
67 } 90 }
68 91
69 HttpStreamFactoryImpl::Request* HttpStreamFactoryImpl::JobController::Start( 92 HttpStreamFactoryImpl::Request* HttpStreamFactoryImpl::JobController::Start(
70 const HttpRequestInfo& request_info, 93 const HttpRequestInfo& request_info,
71 HttpStreamRequest::Delegate* delegate, 94 HttpStreamRequest::Delegate* delegate,
72 WebSocketHandshakeStreamBase::CreateHelper* 95 WebSocketHandshakeStreamBase::CreateHelper*
73 websocket_handshake_stream_create_helper, 96 websocket_handshake_stream_create_helper,
74 const NetLogWithSource& net_log,
75 HttpStreamRequest::StreamType stream_type, 97 HttpStreamRequest::StreamType stream_type,
76 RequestPriority priority, 98 RequestPriority priority,
77 const SSLConfig& server_ssl_config, 99 const SSLConfig& server_ssl_config,
78 const SSLConfig& proxy_ssl_config) { 100 const SSLConfig& proxy_ssl_config) {
79 DCHECK(factory_); 101 DCHECK(factory_);
80 DCHECK(!request_); 102 DCHECK(!request_);
81 103
82 request_ = new Request(request_info.url, this, delegate, 104 request_ = new Request(request_info.url, this, delegate,
83 websocket_handshake_stream_create_helper, net_log, 105 websocket_handshake_stream_create_helper, &net_log_,
84 stream_type); 106 stream_type);
85 107
86 CreateJobs(request_info, priority, server_ssl_config, proxy_ssl_config, 108 CreateJobs(request_info, priority, server_ssl_config, proxy_ssl_config,
87 delegate, stream_type, net_log); 109 delegate, stream_type);
88 110
89 return request_; 111 return request_;
90 } 112 }
91 113
92 void HttpStreamFactoryImpl::JobController::Preconnect( 114 void HttpStreamFactoryImpl::JobController::Preconnect(
93 int num_streams, 115 int num_streams,
94 const HttpRequestInfo& request_info, 116 const HttpRequestInfo& request_info,
95 const SSLConfig& server_ssl_config, 117 const SSLConfig& server_ssl_config,
96 const SSLConfig& proxy_ssl_config) { 118 const SSLConfig& proxy_ssl_config) {
97 DCHECK(!main_job_); 119 DCHECK(!main_job_);
98 DCHECK(!alternative_job_); 120 DCHECK(!alternative_job_);
99 121
100 is_preconnect_ = true;
101 HostPortPair destination(HostPortPair::FromURL(request_info.url)); 122 HostPortPair destination(HostPortPair::FromURL(request_info.url));
102 GURL origin_url = ApplyHostMappingRules(request_info.url, &destination); 123 GURL origin_url = ApplyHostMappingRules(request_info.url, &destination);
103 124
104 const AlternativeService alternative_service = GetAlternativeServiceFor( 125 const AlternativeService alternative_service = GetAlternativeServiceFor(
105 request_info, nullptr, HttpStreamRequest::HTTP_STREAM); 126 request_info, nullptr, HttpStreamRequest::HTTP_STREAM);
106 127
107 if (alternative_service.protocol != kProtoUnknown) { 128 if (alternative_service.protocol != kProtoUnknown) {
108 if (session_->params().quic_disable_preconnect_if_0rtt && 129 if (session_->params().quic_disable_preconnect_if_0rtt &&
109 alternative_service.protocol == kProtoQUIC && 130 alternative_service.protocol == kProtoQUIC &&
110 session_->quic_stream_factory()->ZeroRTTEnabledFor(QuicServerId( 131 session_->quic_stream_factory()->ZeroRTTEnabledFor(QuicServerId(
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 DCHECK(!is_preconnect_); 455 DCHECK(!is_preconnect_);
435 456
436 bool is_job_orphaned = IsJobOrphaned(job); 457 bool is_job_orphaned = IsJobOrphaned(job);
437 458
438 // Cache these values in case the job gets deleted. 459 // Cache these values in case the job gets deleted.
439 const SSLConfig used_ssl_config = job->server_ssl_config(); 460 const SSLConfig used_ssl_config = job->server_ssl_config();
440 const ProxyInfo used_proxy_info = job->proxy_info(); 461 const ProxyInfo used_proxy_info = job->proxy_info();
441 const bool was_alpn_negotiated = job->was_alpn_negotiated(); 462 const bool was_alpn_negotiated = job->was_alpn_negotiated();
442 const NextProto negotiated_protocol = job->negotiated_protocol(); 463 const NextProto negotiated_protocol = job->negotiated_protocol();
443 const bool using_spdy = job->using_spdy(); 464 const bool using_spdy = job->using_spdy();
444 const NetLogWithSource net_log = job->net_log();
445 465
446 // Cache this so we can still use it if the JobController is deleted. 466 // Cache this so we can still use it if the JobController is deleted.
447 HttpStreamFactoryImpl* factory = factory_; 467 HttpStreamFactoryImpl* factory = factory_;
448 468
449 // Notify |request_|. 469 // Notify |request_|.
450 if (!is_preconnect_ && !is_job_orphaned) { 470 if (!is_preconnect_ && !is_job_orphaned) {
451 if (job->job_type() == MAIN && alternative_job_failed_) 471 if (job->job_type() == MAIN && alternative_job_failed_)
452 ReportBrokenAlternativeService(); 472 ReportBrokenAlternativeService();
453 473
454 DCHECK(request_); 474 DCHECK(request_);
(...skipping 23 matching lines...) Expand all
478 DCHECK(stream); 498 DCHECK(stream);
479 delegate_->OnStreamReady(used_ssl_config, used_proxy_info, 499 delegate_->OnStreamReady(used_ssl_config, used_proxy_info,
480 stream.release()); 500 stream.release());
481 } 501 }
482 } 502 }
483 503
484 // Notify |factory_|. |request_| and |bounded_job_| might be deleted already. 504 // Notify |factory_|. |request_| and |bounded_job_| might be deleted already.
485 if (spdy_session && spdy_session->IsAvailable()) { 505 if (spdy_session && spdy_session->IsAvailable()) {
486 factory->OnNewSpdySessionReady(spdy_session, direct, used_ssl_config, 506 factory->OnNewSpdySessionReady(spdy_session, direct, used_ssl_config,
487 used_proxy_info, was_alpn_negotiated, 507 used_proxy_info, was_alpn_negotiated,
488 negotiated_protocol, using_spdy, net_log); 508 negotiated_protocol, using_spdy);
489 } 509 }
490 if (is_job_orphaned) { 510 if (is_job_orphaned) {
491 OnOrphanedJobComplete(job); 511 OnOrphanedJobComplete(job);
492 } 512 }
493 } 513 }
494 514
495 void HttpStreamFactoryImpl::JobController::OnPreconnectsComplete(Job* job) { 515 void HttpStreamFactoryImpl::JobController::OnPreconnectsComplete(Job* job) {
496 DCHECK_EQ(main_job_.get(), job); 516 DCHECK_EQ(main_job_.get(), job);
497 main_job_.reset(); 517 main_job_.reset();
498 factory_->OnPreconnectsCompleteInternal(); 518 factory_->OnPreconnectsCompleteInternal();
(...skipping 17 matching lines...) Expand all
516 Job* job, 536 Job* job,
517 const ConnectionAttempts& attempts) { 537 const ConnectionAttempts& attempts) {
518 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) 538 if (is_preconnect_ || (job_bound_ && bound_job_ != job))
519 return; 539 return;
520 540
521 DCHECK(request_); 541 DCHECK(request_);
522 request_->AddConnectionAttempts(attempts); 542 request_->AddConnectionAttempts(attempts);
523 } 543 }
524 544
525 void HttpStreamFactoryImpl::JobController::ResumeMainJob() { 545 void HttpStreamFactoryImpl::JobController::ResumeMainJob() {
526 main_job_->net_log().AddEvent( 546 net_log_.AddEvent(
527 NetLogEventType::HTTP_STREAM_JOB_DELAYED, 547 NetLogEventType::HTTP_STREAM_JOB_DELAYED,
528 base::Bind(&NetLogHttpStreamJobDelayCallback, main_job_wait_time_)); 548 base::Bind(&NetLogHttpStreamJobDelayCallback, main_job_wait_time_));
529 549
530 main_job_->Resume(); 550 main_job_->Resume();
531 main_job_wait_time_ = base::TimeDelta(); 551 main_job_wait_time_ = base::TimeDelta();
532 } 552 }
533 553
534 void HttpStreamFactoryImpl::JobController::MaybeResumeMainJob( 554 void HttpStreamFactoryImpl::JobController::MaybeResumeMainJob(
535 Job* job, 555 Job* job,
536 const base::TimeDelta& delay) { 556 const base::TimeDelta& delay) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 DCHECK(base::ContainsKey(request_set, request_)); 636 DCHECK(base::ContainsKey(request_set, request_));
617 request_set.erase(request_); 637 request_set.erase(request_);
618 if (request_set.empty()) 638 if (request_set.empty())
619 spdy_session_request_map.erase(*spdy_session_key); 639 spdy_session_request_map.erase(*spdy_session_key);
620 request_->ResetSpdySessionKey(); 640 request_->ResetSpdySessionKey();
621 } 641 }
622 } 642 }
623 643
624 const NetLogWithSource* HttpStreamFactoryImpl::JobController::GetNetLog( 644 const NetLogWithSource* HttpStreamFactoryImpl::JobController::GetNetLog(
625 Job* job) const { 645 Job* job) const {
626 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) 646 return &net_log_;
627 return nullptr;
628 DCHECK(request_);
629 return &request_->net_log();
630 } 647 }
631 648
632 void HttpStreamFactoryImpl::JobController::MaybeSetWaitTimeForMainJob( 649 void HttpStreamFactoryImpl::JobController::MaybeSetWaitTimeForMainJob(
633 const base::TimeDelta& delay) { 650 const base::TimeDelta& delay) {
634 if (main_job_is_blocked_) 651 if (main_job_is_blocked_)
635 main_job_wait_time_ = delay; 652 main_job_wait_time_ = delay;
636 } 653 }
637 654
638 WebSocketHandshakeStreamBase::CreateHelper* HttpStreamFactoryImpl:: 655 WebSocketHandshakeStreamBase::CreateHelper* HttpStreamFactoryImpl::
639 JobController::websocket_handshake_stream_create_helper() { 656 JobController::websocket_handshake_stream_create_helper() {
640 DCHECK(request_); 657 DCHECK(request_);
641 return request_->websocket_handshake_stream_create_helper(); 658 return request_->websocket_handshake_stream_create_helper();
642 } 659 }
643 660
644 void HttpStreamFactoryImpl::JobController::CreateJobs( 661 void HttpStreamFactoryImpl::JobController::CreateJobs(
645 const HttpRequestInfo& request_info, 662 const HttpRequestInfo& request_info,
646 RequestPriority priority, 663 RequestPriority priority,
647 const SSLConfig& server_ssl_config, 664 const SSLConfig& server_ssl_config,
648 const SSLConfig& proxy_ssl_config, 665 const SSLConfig& proxy_ssl_config,
649 HttpStreamRequest::Delegate* delegate, 666 HttpStreamRequest::Delegate* delegate,
650 HttpStreamRequest::StreamType stream_type, 667 HttpStreamRequest::StreamType stream_type) {
651 const NetLogWithSource& net_log) {
652 DCHECK(!main_job_); 668 DCHECK(!main_job_);
653 DCHECK(!alternative_job_); 669 DCHECK(!alternative_job_);
654 HostPortPair destination(HostPortPair::FromURL(request_info.url)); 670 HostPortPair destination(HostPortPair::FromURL(request_info.url));
655 GURL origin_url = ApplyHostMappingRules(request_info.url, &destination); 671 GURL origin_url = ApplyHostMappingRules(request_info.url, &destination);
656 672
657 main_job_.reset(job_factory_->CreateJob( 673 main_job_.reset(job_factory_->CreateJob(
658 this, MAIN, session_, request_info, priority, server_ssl_config, 674 this, MAIN, session_, request_info, priority, server_ssl_config,
659 proxy_ssl_config, destination, origin_url, net_log.net_log())); 675 proxy_ssl_config, destination, origin_url, net_log_.net_log()));
660 AttachJob(main_job_.get()); 676 AttachJob(main_job_.get());
661 677
662 // Create an alternative job if alternative service is set up for this domain. 678 // Create an alternative job if alternative service is set up for this domain.
663 const AlternativeService alternative_service = 679 const AlternativeService alternative_service =
664 GetAlternativeServiceFor(request_info, delegate, stream_type); 680 GetAlternativeServiceFor(request_info, delegate, stream_type);
665 681
666 if (alternative_service.protocol != kProtoUnknown) { 682 if (alternative_service.protocol != kProtoUnknown) {
667 // Never share connection with other jobs for FTP requests. 683 // Never share connection with other jobs for FTP requests.
668 DVLOG(1) << "Selected alternative service (host: " 684 DVLOG(1) << "Selected alternative service (host: "
669 << alternative_service.host_port_pair().host() 685 << alternative_service.host_port_pair().host()
670 << " port: " << alternative_service.host_port_pair().port() << ")"; 686 << " port: " << alternative_service.host_port_pair().port() << ")";
671 687
672 DCHECK(!request_info.url.SchemeIs(url::kFtpScheme)); 688 DCHECK(!request_info.url.SchemeIs(url::kFtpScheme));
673 HostPortPair alternative_destination(alternative_service.host_port_pair()); 689 HostPortPair alternative_destination(alternative_service.host_port_pair());
674 ignore_result( 690 ignore_result(
675 ApplyHostMappingRules(request_info.url, &alternative_destination)); 691 ApplyHostMappingRules(request_info.url, &alternative_destination));
676 692
677 alternative_job_.reset(job_factory_->CreateJob( 693 alternative_job_.reset(job_factory_->CreateJob(
678 this, ALTERNATIVE, session_, request_info, priority, server_ssl_config, 694 this, ALTERNATIVE, session_, request_info, priority, server_ssl_config,
679 proxy_ssl_config, alternative_destination, origin_url, 695 proxy_ssl_config, alternative_destination, origin_url,
680 alternative_service, net_log.net_log())); 696 alternative_service, net_log_.net_log()));
681 AttachJob(alternative_job_.get()); 697 AttachJob(alternative_job_.get());
682 698
683 main_job_is_blocked_ = true; 699 main_job_is_blocked_ = true;
684 alternative_job_->Start(request_->stream_type()); 700 alternative_job_->Start(request_->stream_type());
685 } else { 701 } else {
686 can_start_alternative_proxy_job_ = true; 702 can_start_alternative_proxy_job_ = true;
687 } 703 }
688 // Even if |alternative_job| has already finished, it will not have notified 704 // Even if |alternative_job| has already finished, it will not have notified
689 // the request yet, since we defer that to the next iteration of the 705 // the request yet, since we defer that to the next iteration of the
690 // MessageLoop, so starting |main_job_| is always safe. 706 // MessageLoop, so starting |main_job_| is always safe.
691 main_job_->Start(request_->stream_type()); 707 main_job_->Start(request_->stream_type());
692 } 708 }
693 709
694 void HttpStreamFactoryImpl::JobController::AttachJob(Job* job) { 710 void HttpStreamFactoryImpl::JobController::AttachJob(Job* job) {
695 DCHECK(job); 711 DCHECK(job);
696 factory_->request_map_[job] = request_; 712 factory_->request_map_[job] = request_;
697 } 713 }
698 714
699 void HttpStreamFactoryImpl::JobController::BindJob(Job* job) { 715 void HttpStreamFactoryImpl::JobController::BindJob(Job* job) {
700 DCHECK(request_); 716 DCHECK(request_);
701 DCHECK(job); 717 DCHECK(job);
702 DCHECK(job == alternative_job_.get() || job == main_job_.get()); 718 DCHECK(job == alternative_job_.get() || job == main_job_.get());
703 DCHECK(!job_bound_); 719 DCHECK(!job_bound_);
704 DCHECK(!bound_job_); 720 DCHECK(!bound_job_);
705 721
706 job_bound_ = true; 722 job_bound_ = true;
707 bound_job_ = job; 723 bound_job_ = job;
708 factory_->request_map_.erase(job); 724 factory_->request_map_.erase(job);
709 725
710 request_->net_log().AddEvent( 726 net_log_.AddEvent(NetLogEventType::HTTP_STREAM_REQUEST_BOUND_TO_JOB,
711 NetLogEventType::HTTP_STREAM_REQUEST_BOUND_TO_JOB, 727 job->net_log().source().ToEventParametersCallback());
712 job->net_log().source().ToEventParametersCallback());
713 job->net_log().AddEvent(
714 NetLogEventType::HTTP_STREAM_JOB_BOUND_TO_REQUEST,
715 request_->net_log().source().ToEventParametersCallback());
716
717 OrphanUnboundJob(); 728 OrphanUnboundJob();
718 } 729 }
719 730
720 void HttpStreamFactoryImpl::JobController::CancelJobs() { 731 void HttpStreamFactoryImpl::JobController::CancelJobs() {
721 DCHECK(request_); 732 DCHECK(request_);
722 RemoveRequestFromSpdySessionRequestMap(); 733 RemoveRequestFromSpdySessionRequestMap();
723 if (job_bound_) 734 if (job_bound_)
724 return; 735 return;
725 if (alternative_job_) { 736 if (alternative_job_) {
726 factory_->request_map_.erase(alternative_job_.get()); 737 factory_->request_map_.erase(alternative_job_.get());
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 return; 1105 return;
1095 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); 1106 DCHECK(alternative_job_->alternative_proxy_server().is_valid());
1096 alternative_job_->Start(request_->stream_type()); 1107 alternative_job_->Start(request_->stream_type());
1097 } 1108 }
1098 1109
1099 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const { 1110 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const {
1100 return !request_ || (job_bound_ && bound_job_ != job); 1111 return !request_ || (job_bound_ && bound_job_ != job);
1101 } 1112 }
1102 1113
1103 } // namespace net 1114 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698