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

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

Issue 2754003002: [DO NOT SUBMIT, PATCH on commit 7fa349e632a44c152b05ca6a66ade5f2e5b3f139] (Closed)
Patch Set: Created 3 years, 9 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 NetLogSourceType::HTTP_STREAM_JOB_CONTROLLER)), 67 NetLogSourceType::HTTP_STREAM_JOB_CONTROLLER)),
68 ptr_factory_(this) { 68 ptr_factory_(this) {
69 DCHECK(factory); 69 DCHECK(factory);
70 net_log_.BeginEvent(NetLogEventType::HTTP_STREAM_JOB_CONTROLLER, 70 net_log_.BeginEvent(NetLogEventType::HTTP_STREAM_JOB_CONTROLLER,
71 base::Bind(&NetLogJobControllerCallback, 71 base::Bind(&NetLogJobControllerCallback,
72 &request_info.url, is_preconnect)); 72 &request_info.url, is_preconnect));
73 } 73 }
74 74
75 HttpStreamFactoryImpl::JobController::~JobController() { 75 HttpStreamFactoryImpl::JobController::~JobController() {
76 main_job_.reset(); 76 main_job_.reset();
77 net_log_.AddEvent(
78 NetLogEventType::ALT_JOB_DELETED_ON_DESTRUCT_JOB_CONTROLLER);
eroman 2017/03/16 04:32:08 Instead of having multiple different event types (
77 alternative_job_.reset(); 79 alternative_job_.reset();
78 bound_job_ = nullptr; 80 bound_job_ = nullptr;
79 net_log_.EndEvent(NetLogEventType::HTTP_STREAM_JOB_CONTROLLER); 81 net_log_.EndEvent(NetLogEventType::HTTP_STREAM_JOB_CONTROLLER);
80 } 82 }
81 83
82 bool HttpStreamFactoryImpl::JobController::for_websockets() { 84 bool HttpStreamFactoryImpl::JobController::for_websockets() {
83 return factory_->for_websockets_; 85 return factory_->for_websockets_;
84 } 86 }
85 87
86 HttpStreamFactoryImpl::Request* HttpStreamFactoryImpl::JobController::Start( 88 HttpStreamFactoryImpl::Request* HttpStreamFactoryImpl::JobController::Start(
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 request_ = nullptr; 172 request_ = nullptr;
171 if (bound_job_) { 173 if (bound_job_) {
172 if (bound_job_->job_type() == MAIN) { 174 if (bound_job_->job_type() == MAIN) {
173 main_job_.reset(); 175 main_job_.reset();
174 // |alternative_job_| can be non-null if |main_job_| is resumed after 176 // |alternative_job_| can be non-null if |main_job_| is resumed after
175 // |main_job_wait_time_| has elapsed. Allow |alternative_job_| to run to 177 // |main_job_wait_time_| has elapsed. Allow |alternative_job_| to run to
176 // completion, rather than resetting it. OnOrphanedJobComplete() will 178 // completion, rather than resetting it. OnOrphanedJobComplete() will
177 // clean up |this| when the job completes. 179 // clean up |this| when the job completes.
178 } else { 180 } else {
179 DCHECK(bound_job_->job_type() == ALTERNATIVE); 181 DCHECK(bound_job_->job_type() == ALTERNATIVE);
182 net_log_.AddEvent(
183 NetLogEventType::ALT_JOB_DELETED_ON_REQUEST_COMPLETE_AND_BOUND);
180 alternative_job_.reset(); 184 alternative_job_.reset();
181 } 185 }
182 bound_job_ = nullptr; 186 bound_job_ = nullptr;
183 } 187 }
184 MaybeNotifyFactoryOfCompletion(); 188 MaybeNotifyFactoryOfCompletion();
185 } 189 }
186 190
187 int HttpStreamFactoryImpl::JobController::RestartTunnelWithProxyAuth() { 191 int HttpStreamFactoryImpl::JobController::RestartTunnelWithProxyAuth() {
188 DCHECK(bound_job_); 192 DCHECK(bound_job_);
189 return bound_job_->RestartTunnelWithProxyAuth(); 193 return bound_job_->RestartTunnelWithProxyAuth();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 274
271 OnJobSucceeded(job); 275 OnJobSucceeded(job);
272 request_->OnWebSocketHandshakeStreamReady(used_ssl_config, used_proxy_info, 276 request_->OnWebSocketHandshakeStreamReady(used_ssl_config, used_proxy_info,
273 stream); 277 stream);
274 } 278 }
275 279
276 void HttpStreamFactoryImpl::JobController::OnStreamFailed( 280 void HttpStreamFactoryImpl::JobController::OnStreamFailed(
277 Job* job, 281 Job* job,
278 int status, 282 int status,
279 const SSLConfig& used_ssl_config) { 283 const SSLConfig& used_ssl_config) {
284 net_log_.BeginEvent(NetLogEventType::HTTP_STREAM_JOB_ON_STREAM_FAILED,
285 NetLog::BoolCallback("is_orphaned", IsJobOrphaned(job)));
280 if (job->job_type() == ALTERNATIVE) { 286 if (job->job_type() == ALTERNATIVE) {
281 DCHECK_EQ(alternative_job_.get(), job); 287 DCHECK_EQ(alternative_job_.get(), job);
282 OnAlternativeJobFailed(status); 288 OnAlternativeJobFailed(status);
283 } 289 }
284 290
285 MaybeResumeMainJob(job, base::TimeDelta()); 291 MaybeResumeMainJob(job, base::TimeDelta());
286 292
287 if (IsJobOrphaned(job)) { 293 if (IsJobOrphaned(job)) {
288 // We have bound a job to the associated Request, |job| has been orphaned. 294 // We have bound a job to the associated Request, |job| has been orphaned.
289 OnOrphanedJobComplete(job); 295 OnOrphanedJobComplete(job);
296 net_log_.EndEvent(NetLogEventType::HTTP_STREAM_JOB_ON_STREAM_FAILED);
eroman 2017/03/16 04:32:08 The begin/end measured by this event is entire syn
290 return; 297 return;
291 } 298 }
292 299
293 if (!request_) 300 if (!request_) {
301 net_log_.EndEvent(NetLogEventType::HTTP_STREAM_JOB_ON_STREAM_FAILED);
294 return; 302 return;
303 }
295 DCHECK_NE(OK, status); 304 DCHECK_NE(OK, status);
296 DCHECK(job); 305 DCHECK(job);
297 306
298 if (!bound_job_) { 307 if (!bound_job_) {
299 if (main_job_ && alternative_job_) { 308 if (main_job_ && alternative_job_) {
300 // Hey, we've got other jobs! Maybe one of them will succeed, let's just 309 // Hey, we've got other jobs! Maybe one of them will succeed, let's just
301 // ignore this failure. 310 // ignore this failure.
302 factory_->request_map_.erase(job); 311 factory_->request_map_.erase(job);
303 if (job->job_type() == MAIN) { 312 if (job->job_type() == MAIN) {
304 main_job_.reset(); 313 main_job_.reset();
305 } else { 314 } else {
306 DCHECK(job->job_type() == ALTERNATIVE); 315 DCHECK(job->job_type() == ALTERNATIVE);
316 net_log_.AddEvent(NetLogEventType::ALT_JOB_DELETED_ON_STREAM_FAILED);
307 alternative_job_.reset(); 317 alternative_job_.reset();
308 } 318 }
319 net_log_.EndEvent(NetLogEventType::HTTP_STREAM_JOB_ON_STREAM_FAILED);
309 return; 320 return;
310 } else { 321 } else {
311 BindJob(job); 322 BindJob(job);
312 } 323 }
313 } 324 }
314 325
315 request_->OnStreamFailed(status, used_ssl_config); 326 request_->OnStreamFailed(status, used_ssl_config);
327 net_log_.EndEvent(NetLogEventType::HTTP_STREAM_JOB_ON_STREAM_FAILED);
316 } 328 }
317 329
318 void HttpStreamFactoryImpl::JobController::OnCertificateError( 330 void HttpStreamFactoryImpl::JobController::OnCertificateError(
319 Job* job, 331 Job* job,
320 int status, 332 int status,
321 const SSLConfig& used_ssl_config, 333 const SSLConfig& used_ssl_config,
322 const SSLInfo& ssl_info) { 334 const SSLInfo& ssl_info) {
323 MaybeResumeMainJob(job, base::TimeDelta()); 335 MaybeResumeMainJob(job, base::TimeDelta());
324 336
325 if (IsJobOrphaned(job)) { 337 if (IsJobOrphaned(job)) {
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 MaybeNotifyFactoryOfCompletion(); 530 MaybeNotifyFactoryOfCompletion();
519 } 531 }
520 532
521 void HttpStreamFactoryImpl::JobController::OnOrphanedJobComplete( 533 void HttpStreamFactoryImpl::JobController::OnOrphanedJobComplete(
522 const Job* job) { 534 const Job* job) {
523 if (job->job_type() == MAIN) { 535 if (job->job_type() == MAIN) {
524 DCHECK_EQ(main_job_.get(), job); 536 DCHECK_EQ(main_job_.get(), job);
525 main_job_.reset(); 537 main_job_.reset();
526 } else { 538 } else {
527 DCHECK_EQ(alternative_job_.get(), job); 539 DCHECK_EQ(alternative_job_.get(), job);
540 net_log_.AddEvent(
541 NetLogEventType::ALT_JOB_DELETED_IN_ON_ORPHANED_JOB_COMPLETE);
528 alternative_job_.reset(); 542 alternative_job_.reset();
529 } 543 }
530 544
531 MaybeNotifyFactoryOfCompletion(); 545 MaybeNotifyFactoryOfCompletion();
532 } 546 }
533 547
534 void HttpStreamFactoryImpl::JobController::AddConnectionAttemptsToRequest( 548 void HttpStreamFactoryImpl::JobController::AddConnectionAttemptsToRequest(
535 Job* job, 549 Job* job,
536 const ConnectionAttempts& attempts) { 550 const ConnectionAttempts& attempts) {
537 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) 551 if (is_preconnect_ || (job_bound_ && bound_job_ != job))
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 671
658 const NetLogWithSource* HttpStreamFactoryImpl::JobController::GetNetLog( 672 const NetLogWithSource* HttpStreamFactoryImpl::JobController::GetNetLog(
659 Job* job) const { 673 Job* job) const {
660 return &net_log_; 674 return &net_log_;
661 } 675 }
662 676
663 void HttpStreamFactoryImpl::JobController::MaybeSetWaitTimeForMainJob( 677 void HttpStreamFactoryImpl::JobController::MaybeSetWaitTimeForMainJob(
664 const base::TimeDelta& delay) { 678 const base::TimeDelta& delay) {
665 if (main_job_is_blocked_) { 679 if (main_job_is_blocked_) {
666 main_job_wait_time_ = std::min( 680 main_job_wait_time_ = std::min(
667 delay, base::TimeDelta::FromSeconds(kMaxDelayTimeForMainJobSecs)); 681 delay, base::TimeDelta::FromMilliseconds(kMaxDelayTimeForMainJobSecs));
eroman 2017/03/16 04:32:08 Why this change? The variable is named "ForSecs".
668 } 682 }
669 } 683 }
670 684
671 bool HttpStreamFactoryImpl::JobController::HasPendingMainJob() const { 685 bool HttpStreamFactoryImpl::JobController::HasPendingMainJob() const {
672 return main_job_.get() != nullptr; 686 return main_job_.get() != nullptr;
673 } 687 }
674 688
675 bool HttpStreamFactoryImpl::JobController::HasPendingAltJob() const { 689 bool HttpStreamFactoryImpl::JobController::HasPendingAltJob() const {
676 return alternative_job_.get() != nullptr; 690 return alternative_job_.get() != nullptr;
677 } 691 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 OrphanUnboundJob(); 780 OrphanUnboundJob();
767 } 781 }
768 782
769 void HttpStreamFactoryImpl::JobController::CancelJobs() { 783 void HttpStreamFactoryImpl::JobController::CancelJobs() {
770 DCHECK(request_); 784 DCHECK(request_);
771 RemoveRequestFromSpdySessionRequestMap(); 785 RemoveRequestFromSpdySessionRequestMap();
772 if (job_bound_) 786 if (job_bound_)
773 return; 787 return;
774 if (alternative_job_) { 788 if (alternative_job_) {
775 factory_->request_map_.erase(alternative_job_.get()); 789 factory_->request_map_.erase(alternative_job_.get());
790 net_log_.AddEvent(NetLogEventType::ALT_JOB_DELETED_ON_CANCEL_JOBS);
776 alternative_job_.reset(); 791 alternative_job_.reset();
777 } 792 }
778 if (main_job_) { 793 if (main_job_) {
779 factory_->request_map_.erase(main_job_.get()); 794 factory_->request_map_.erase(main_job_.get());
780 main_job_.reset(); 795 main_job_.reset();
781 } 796 }
782 } 797 }
783 798
784 void HttpStreamFactoryImpl::JobController::OrphanUnboundJob() { 799 void HttpStreamFactoryImpl::JobController::OrphanUnboundJob() {
785 DCHECK(request_); 800 DCHECK(request_);
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 return; 1183 return;
1169 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); 1184 DCHECK(alternative_job_->alternative_proxy_server().is_valid());
1170 alternative_job_->Start(request_->stream_type()); 1185 alternative_job_->Start(request_->stream_type());
1171 } 1186 }
1172 1187
1173 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const { 1188 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const {
1174 return !request_ || (job_bound_ && bound_job_ != job); 1189 return !request_ || (job_bound_ && bound_job_ != job);
1175 } 1190 }
1176 1191
1177 } // namespace net 1192 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698