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

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

Issue 2621983004: Improve HttpStreamFactory NetLog events (Closed)
Patch Set: fix compile 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
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
11 #include "base/memory/ptr_util.h"
11 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "net/base/host_mapping_rules.h" 17 #include "net/base/host_mapping_rules.h"
17 #include "net/base/proxy_delegate.h" 18 #include "net/base/proxy_delegate.h"
18 #include "net/http/bidirectional_stream_impl.h" 19 #include "net/http/bidirectional_stream_impl.h"
19 #include "net/http/transport_security_state.h" 20 #include "net/http/transport_security_state.h"
20 #include "net/log/net_log_capture_mode.h" 21 #include "net/log/net_log_capture_mode.h"
21 #include "net/log/net_log_event_type.h" 22 #include "net/log/net_log_event_type.h"
22 #include "net/log/net_log_source.h" 23 #include "net/log/net_log_source.h"
23 #include "net/log/net_log_with_source.h" 24 #include "net/log/net_log_with_source.h"
24 #include "net/proxy/proxy_server.h" 25 #include "net/proxy/proxy_server.h"
25 #include "net/spdy/spdy_session.h" 26 #include "net/spdy/spdy_session.h"
26 #include "url/url_constants.h" 27 #include "url/url_constants.h"
27 28
28 namespace net { 29 namespace net {
29 30
30 // Returns parameters associated with the delay of the HTTP stream job. 31 // Returns parameters associated with the delay of the HTTP stream job.
31 std::unique_ptr<base::Value> NetLogHttpStreamJobDelayCallback( 32 std::unique_ptr<base::Value> NetLogHttpStreamJobDelayCallback(
32 base::TimeDelta delay, 33 base::TimeDelta delay,
33 NetLogCaptureMode /* capture_mode */) { 34 NetLogCaptureMode /* capture_mode */) {
34 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 35 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
35 dict->SetInteger("resume_after_ms", static_cast<int>(delay.InMilliseconds())); 36 dict->SetInteger("resume_after_ms", static_cast<int>(delay.InMilliseconds()));
36 return std::move(dict); 37 return std::move(dict);
37 } 38 }
38 39
40 std::unique_ptr<base::Value> NetLogJobControllerCallback(
41 const GURL* url,
42 bool is_preconnect,
43 NetLogCaptureMode /* capture_mode */) {
44 std::unique_ptr<base::DictionaryValue> dict =
Bence 2017/01/28 02:08:25 Optional: feel free to use auto here (as suggested
xunjieli 2017/01/30 14:08:39 Done.
45 base::MakeUnique<base::DictionaryValue>();
46 dict->SetString("url", url->possibly_invalid_spec());
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 const HttpRequestInfo& request_info,
57 bool is_preconnect)
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_net_error_(OK), 64 alternative_job_net_error_(OK),
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),
55 privacy_mode_(PRIVACY_MODE_DISABLED), 69 privacy_mode_(PRIVACY_MODE_DISABLED),
70 net_log_(
71 NetLogWithSource::Make(session->net_log(),
72 NetLogSourceType::HTTP_STREAM_JOB_CONTROLLER)),
56 ptr_factory_(this) { 73 ptr_factory_(this) {
57 DCHECK(factory); 74 DCHECK(factory);
75 net_log_.BeginEvent(NetLogEventType::HTTP_STREAM_JOB_CONTROLLER,
76 base::Bind(&NetLogJobControllerCallback,
77 &request_info.url, is_preconnect));
58 } 78 }
59 79
60 HttpStreamFactoryImpl::JobController::~JobController() { 80 HttpStreamFactoryImpl::JobController::~JobController() {
61 main_job_.reset(); 81 main_job_.reset();
62 alternative_job_.reset(); 82 alternative_job_.reset();
63 bound_job_ = nullptr; 83 bound_job_ = nullptr;
84 net_log_.EndEvent(NetLogEventType::HTTP_STREAM_JOB_CONTROLLER);
64 } 85 }
65 86
66 bool HttpStreamFactoryImpl::JobController::for_websockets() { 87 bool HttpStreamFactoryImpl::JobController::for_websockets() {
67 return factory_->for_websockets_; 88 return factory_->for_websockets_;
68 } 89 }
69 90
70 HttpStreamFactoryImpl::Request* HttpStreamFactoryImpl::JobController::Start( 91 HttpStreamFactoryImpl::Request* HttpStreamFactoryImpl::JobController::Start(
71 const HttpRequestInfo& request_info, 92 const HttpRequestInfo& request_info,
72 HttpStreamRequest::Delegate* delegate, 93 HttpStreamRequest::Delegate* delegate,
73 WebSocketHandshakeStreamBase::CreateHelper* 94 WebSocketHandshakeStreamBase::CreateHelper*
74 websocket_handshake_stream_create_helper, 95 websocket_handshake_stream_create_helper,
75 const NetLogWithSource& net_log, 96 const NetLogWithSource& source_net_log,
76 HttpStreamRequest::StreamType stream_type, 97 HttpStreamRequest::StreamType stream_type,
77 RequestPriority priority, 98 RequestPriority priority,
78 const SSLConfig& server_ssl_config, 99 const SSLConfig& server_ssl_config,
79 const SSLConfig& proxy_ssl_config) { 100 const SSLConfig& proxy_ssl_config) {
80 DCHECK(factory_); 101 DCHECK(factory_);
81 DCHECK(!request_); 102 DCHECK(!request_);
82 103
83 privacy_mode_ = request_info.privacy_mode; 104 privacy_mode_ = request_info.privacy_mode;
84 105
85 request_ = new Request(request_info.url, this, delegate, 106 request_ = new Request(request_info.url, this, delegate,
86 websocket_handshake_stream_create_helper, net_log, 107 websocket_handshake_stream_create_helper,
87 stream_type); 108 source_net_log, stream_type);
109 // Associates |net_log_| with |source_net_log|.
110 source_net_log.AddEvent(NetLogEventType::HTTP_STREAM_JOB_CONTROLLER_BOUND,
111 net_log_.source().ToEventParametersCallback());
112 net_log_.AddEvent(NetLogEventType::HTTP_STREAM_JOB_CONTROLLER_BOUND,
113 source_net_log.source().ToEventParametersCallback());
88 114
89 CreateJobs(request_info, priority, server_ssl_config, proxy_ssl_config, 115 CreateJobs(request_info, priority, server_ssl_config, proxy_ssl_config,
90 delegate, stream_type, net_log); 116 delegate, stream_type);
91 117
92 return request_; 118 return request_;
93 } 119 }
94 120
95 void HttpStreamFactoryImpl::JobController::Preconnect( 121 void HttpStreamFactoryImpl::JobController::Preconnect(
96 int num_streams, 122 int num_streams,
97 const HttpRequestInfo& request_info, 123 const HttpRequestInfo& request_info,
98 const SSLConfig& server_ssl_config, 124 const SSLConfig& server_ssl_config,
99 const SSLConfig& proxy_ssl_config) { 125 const SSLConfig& proxy_ssl_config) {
100 DCHECK(!main_job_); 126 DCHECK(!main_job_);
101 DCHECK(!alternative_job_); 127 DCHECK(!alternative_job_);
128 DCHECK(is_preconnect_);
102 129
103 privacy_mode_ = request_info.privacy_mode; 130 privacy_mode_ = request_info.privacy_mode;
104 131
105 is_preconnect_ = true;
106 HostPortPair destination(HostPortPair::FromURL(request_info.url)); 132 HostPortPair destination(HostPortPair::FromURL(request_info.url));
107 GURL origin_url = ApplyHostMappingRules(request_info.url, &destination); 133 GURL origin_url = ApplyHostMappingRules(request_info.url, &destination);
108 134
109 const AlternativeService alternative_service = GetAlternativeServiceFor( 135 const AlternativeService alternative_service = GetAlternativeServiceFor(
110 request_info, nullptr, HttpStreamRequest::HTTP_STREAM); 136 request_info, nullptr, HttpStreamRequest::HTTP_STREAM);
111 137
112 if (alternative_service.protocol != kProtoUnknown) { 138 if (alternative_service.protocol != kProtoUnknown) {
113 if (session_->params().quic_disable_preconnect_if_0rtt && 139 if (session_->params().quic_disable_preconnect_if_0rtt &&
114 alternative_service.protocol == kProtoQUIC && 140 alternative_service.protocol == kProtoQUIC &&
115 session_->quic_stream_factory()->ZeroRTTEnabledFor(QuicServerId( 141 session_->quic_stream_factory()->ZeroRTTEnabledFor(QuicServerId(
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 DCHECK(!is_preconnect_); 460 DCHECK(!is_preconnect_);
435 461
436 bool is_job_orphaned = IsJobOrphaned(job); 462 bool is_job_orphaned = IsJobOrphaned(job);
437 463
438 // Cache these values in case the job gets deleted. 464 // Cache these values in case the job gets deleted.
439 const SSLConfig used_ssl_config = job->server_ssl_config(); 465 const SSLConfig used_ssl_config = job->server_ssl_config();
440 const ProxyInfo used_proxy_info = job->proxy_info(); 466 const ProxyInfo used_proxy_info = job->proxy_info();
441 const bool was_alpn_negotiated = job->was_alpn_negotiated(); 467 const bool was_alpn_negotiated = job->was_alpn_negotiated();
442 const NextProto negotiated_protocol = job->negotiated_protocol(); 468 const NextProto negotiated_protocol = job->negotiated_protocol();
443 const bool using_spdy = job->using_spdy(); 469 const bool using_spdy = job->using_spdy();
444 const NetLogWithSource net_log = job->net_log();
445 470
446 // Cache this so we can still use it if the JobController is deleted. 471 // Cache this so we can still use it if the JobController is deleted.
447 HttpStreamFactoryImpl* factory = factory_; 472 HttpStreamFactoryImpl* factory = factory_;
448 473
449 // Notify |request_|. 474 // Notify |request_|.
450 if (!is_preconnect_ && !is_job_orphaned) { 475 if (!is_preconnect_ && !is_job_orphaned) {
451 if (job->job_type() == MAIN && alternative_job_net_error_ != OK) 476 if (job->job_type() == MAIN && alternative_job_net_error_ != OK)
452 ReportBrokenAlternativeService(); 477 ReportBrokenAlternativeService();
453 478
454 DCHECK(request_); 479 DCHECK(request_);
(...skipping 23 matching lines...) Expand all
478 DCHECK(stream); 503 DCHECK(stream);
479 delegate_->OnStreamReady(used_ssl_config, used_proxy_info, 504 delegate_->OnStreamReady(used_ssl_config, used_proxy_info,
480 stream.release()); 505 stream.release());
481 } 506 }
482 } 507 }
483 508
484 // Notify |factory_|. |request_| and |bounded_job_| might be deleted already. 509 // Notify |factory_|. |request_| and |bounded_job_| might be deleted already.
485 if (spdy_session && spdy_session->IsAvailable()) { 510 if (spdy_session && spdy_session->IsAvailable()) {
486 factory->OnNewSpdySessionReady(spdy_session, direct, used_ssl_config, 511 factory->OnNewSpdySessionReady(spdy_session, direct, used_ssl_config,
487 used_proxy_info, was_alpn_negotiated, 512 used_proxy_info, was_alpn_negotiated,
488 negotiated_protocol, using_spdy, net_log); 513 negotiated_protocol, using_spdy);
489 } 514 }
490 if (is_job_orphaned) { 515 if (is_job_orphaned) {
491 OnOrphanedJobComplete(job); 516 OnOrphanedJobComplete(job);
492 } 517 }
493 } 518 }
494 519
495 void HttpStreamFactoryImpl::JobController::OnPreconnectsComplete(Job* job) { 520 void HttpStreamFactoryImpl::JobController::OnPreconnectsComplete(Job* job) {
496 DCHECK_EQ(main_job_.get(), job); 521 DCHECK_EQ(main_job_.get(), job);
497 main_job_.reset(); 522 main_job_.reset();
498 factory_->OnPreconnectsCompleteInternal(); 523 factory_->OnPreconnectsCompleteInternal();
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 DCHECK(base::ContainsKey(request_set, request_)); 641 DCHECK(base::ContainsKey(request_set, request_));
617 request_set.erase(request_); 642 request_set.erase(request_);
618 if (request_set.empty()) 643 if (request_set.empty())
619 spdy_session_request_map.erase(*spdy_session_key); 644 spdy_session_request_map.erase(*spdy_session_key);
620 request_->ResetSpdySessionKey(); 645 request_->ResetSpdySessionKey();
621 } 646 }
622 } 647 }
623 648
624 const NetLogWithSource* HttpStreamFactoryImpl::JobController::GetNetLog( 649 const NetLogWithSource* HttpStreamFactoryImpl::JobController::GetNetLog(
625 Job* job) const { 650 Job* job) const {
626 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) 651 return &net_log_;
627 return nullptr;
628 DCHECK(request_);
629 return &request_->net_log();
630 } 652 }
631 653
632 void HttpStreamFactoryImpl::JobController::MaybeSetWaitTimeForMainJob( 654 void HttpStreamFactoryImpl::JobController::MaybeSetWaitTimeForMainJob(
633 const base::TimeDelta& delay) { 655 const base::TimeDelta& delay) {
634 if (main_job_is_blocked_) 656 if (main_job_is_blocked_)
635 main_job_wait_time_ = delay; 657 main_job_wait_time_ = delay;
636 } 658 }
637 659
638 bool HttpStreamFactoryImpl::JobController::HasPendingMainJob() const { 660 bool HttpStreamFactoryImpl::JobController::HasPendingMainJob() const {
639 return main_job_.get() != nullptr; 661 return main_job_.get() != nullptr;
(...skipping 17 matching lines...) Expand all
657 DCHECK(request_); 679 DCHECK(request_);
658 return request_->websocket_handshake_stream_create_helper(); 680 return request_->websocket_handshake_stream_create_helper();
659 } 681 }
660 682
661 void HttpStreamFactoryImpl::JobController::CreateJobs( 683 void HttpStreamFactoryImpl::JobController::CreateJobs(
662 const HttpRequestInfo& request_info, 684 const HttpRequestInfo& request_info,
663 RequestPriority priority, 685 RequestPriority priority,
664 const SSLConfig& server_ssl_config, 686 const SSLConfig& server_ssl_config,
665 const SSLConfig& proxy_ssl_config, 687 const SSLConfig& proxy_ssl_config,
666 HttpStreamRequest::Delegate* delegate, 688 HttpStreamRequest::Delegate* delegate,
667 HttpStreamRequest::StreamType stream_type, 689 HttpStreamRequest::StreamType stream_type) {
668 const NetLogWithSource& net_log) {
669 DCHECK(!main_job_); 690 DCHECK(!main_job_);
670 DCHECK(!alternative_job_); 691 DCHECK(!alternative_job_);
671 HostPortPair destination(HostPortPair::FromURL(request_info.url)); 692 HostPortPair destination(HostPortPair::FromURL(request_info.url));
672 GURL origin_url = ApplyHostMappingRules(request_info.url, &destination); 693 GURL origin_url = ApplyHostMappingRules(request_info.url, &destination);
673 694
674 main_job_.reset(job_factory_->CreateJob( 695 main_job_.reset(job_factory_->CreateJob(
675 this, MAIN, session_, request_info, priority, server_ssl_config, 696 this, MAIN, session_, request_info, priority, server_ssl_config,
676 proxy_ssl_config, destination, origin_url, net_log.net_log())); 697 proxy_ssl_config, destination, origin_url, net_log_.net_log()));
677 AttachJob(main_job_.get()); 698 AttachJob(main_job_.get());
678 699
679 // Create an alternative job if alternative service is set up for this domain. 700 // Create an alternative job if alternative service is set up for this domain.
680 const AlternativeService alternative_service = 701 const AlternativeService alternative_service =
681 GetAlternativeServiceFor(request_info, delegate, stream_type); 702 GetAlternativeServiceFor(request_info, delegate, stream_type);
682 703
683 if (alternative_service.protocol != kProtoUnknown) { 704 if (alternative_service.protocol != kProtoUnknown) {
684 // Never share connection with other jobs for FTP requests. 705 // Never share connection with other jobs for FTP requests.
685 DVLOG(1) << "Selected alternative service (host: " 706 DVLOG(1) << "Selected alternative service (host: "
686 << alternative_service.host_port_pair().host() 707 << alternative_service.host_port_pair().host()
687 << " port: " << alternative_service.host_port_pair().port() << ")"; 708 << " port: " << alternative_service.host_port_pair().port() << ")";
688 709
689 DCHECK(!request_info.url.SchemeIs(url::kFtpScheme)); 710 DCHECK(!request_info.url.SchemeIs(url::kFtpScheme));
690 HostPortPair alternative_destination(alternative_service.host_port_pair()); 711 HostPortPair alternative_destination(alternative_service.host_port_pair());
691 ignore_result( 712 ignore_result(
692 ApplyHostMappingRules(request_info.url, &alternative_destination)); 713 ApplyHostMappingRules(request_info.url, &alternative_destination));
693 714
694 alternative_job_.reset(job_factory_->CreateJob( 715 alternative_job_.reset(job_factory_->CreateJob(
695 this, ALTERNATIVE, session_, request_info, priority, server_ssl_config, 716 this, ALTERNATIVE, session_, request_info, priority, server_ssl_config,
696 proxy_ssl_config, alternative_destination, origin_url, 717 proxy_ssl_config, alternative_destination, origin_url,
697 alternative_service, net_log.net_log())); 718 alternative_service, net_log_.net_log()));
698 AttachJob(alternative_job_.get()); 719 AttachJob(alternative_job_.get());
699 720
700 main_job_is_blocked_ = true; 721 main_job_is_blocked_ = true;
701 alternative_job_->Start(request_->stream_type()); 722 alternative_job_->Start(request_->stream_type());
702 } else { 723 } else {
703 can_start_alternative_proxy_job_ = true; 724 can_start_alternative_proxy_job_ = true;
704 } 725 }
705 // Even if |alternative_job| has already finished, it will not have notified 726 // Even if |alternative_job| has already finished, it will not have notified
706 // the request yet, since we defer that to the next iteration of the 727 // the request yet, since we defer that to the next iteration of the
707 // MessageLoop, so starting |main_job_| is always safe. 728 // MessageLoop, so starting |main_job_| is always safe.
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 return; 1157 return;
1137 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); 1158 DCHECK(alternative_job_->alternative_proxy_server().is_valid());
1138 alternative_job_->Start(request_->stream_type()); 1159 alternative_job_->Start(request_->stream_type());
1139 } 1160 }
1140 1161
1141 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const { 1162 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const {
1142 return !request_ || (job_bound_ && bound_job_ != job); 1163 return !request_ || (job_bound_ && bound_job_ != job);
1143 } 1164 }
1144 1165
1145 } // namespace net 1166 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698