Chromium Code Reviews| 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 "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "net/base/host_mapping_rules.h" | 9 #include "net/base/host_mapping_rules.h" |
| 10 #include "net/http/bidirectional_stream_impl.h" | 10 #include "net/http/bidirectional_stream_impl.h" |
| 11 #include "net/http/http_stream_factory_impl.h" | 11 #include "net/http/http_stream_factory_impl.h" |
| 12 #include "net/http/http_stream_factory_impl_job.h" | 12 #include "net/http/http_stream_factory_impl_job.h" |
| 13 #include "net/http/http_stream_factory_impl_request.h" | 13 #include "net/http/http_stream_factory_impl_request.h" |
| 14 #include "net/http/transport_security_state.h" | 14 #include "net/http/transport_security_state.h" |
| 15 #include "net/spdy/spdy_session.h" | 15 #include "net/spdy/spdy_session.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 HttpStreamFactoryImpl::JobController::JobController( | 19 HttpStreamFactoryImpl::JobController::JobController( |
| 20 HttpStreamFactoryImpl* factory, | 20 HttpStreamFactoryImpl* factory, |
| 21 HttpStreamRequest::Delegate* delegate, | 21 HttpStreamRequest::Delegate* delegate, |
| 22 HttpNetworkSession* session) | 22 HttpNetworkSession* session) |
| 23 : factory_(factory), | 23 : factory_(factory), |
| 24 session_(session), | 24 session_(session), |
| 25 request_(nullptr), | 25 request_(nullptr), |
| 26 delegate_(delegate), | 26 delegate_(delegate), |
| 27 is_preconnect_(false), | 27 is_preconnect_(false), |
| 28 job_bound_(false), | 28 job_bound_(false), |
| 29 blocking_(false), | |
| 29 bound_job_(nullptr) { | 30 bound_job_(nullptr) { |
| 30 DCHECK(factory); | 31 DCHECK(factory); |
| 31 } | 32 } |
| 32 | 33 |
| 33 HttpStreamFactoryImpl::JobController::~JobController() { | 34 HttpStreamFactoryImpl::JobController::~JobController() { |
| 34 main_job_.reset(); | 35 main_job_.reset(); |
| 35 alternative_job_.reset(); | 36 alternative_job_.reset(); |
| 36 bound_job_ = nullptr; | 37 bound_job_ = nullptr; |
| 37 } | 38 } |
| 38 | 39 |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 used_proxy_info, was_npn_negotiated, | 384 used_proxy_info, was_npn_negotiated, |
| 384 protocol_negotiated, using_spdy, net_log); | 385 protocol_negotiated, using_spdy, net_log); |
| 385 } | 386 } |
| 386 if (is_job_orphaned) { | 387 if (is_job_orphaned) { |
| 387 OnOrphanedJobComplete(job); | 388 OnOrphanedJobComplete(job); |
| 388 } | 389 } |
| 389 } | 390 } |
| 390 | 391 |
| 391 void HttpStreamFactoryImpl::JobController::OnPreconnectsComplete(Job* job) { | 392 void HttpStreamFactoryImpl::JobController::OnPreconnectsComplete(Job* job) { |
| 392 DCHECK_EQ(main_job_.get(), job); | 393 DCHECK_EQ(main_job_.get(), job); |
| 394 DCHECK(!bound_job_); | |
| 393 main_job_.reset(); | 395 main_job_.reset(); |
| 394 factory_->OnPreconnectsCompleteInternal(); | 396 factory_->OnPreconnectsCompleteInternal(); |
| 395 MaybeNotifyFactoryOfCompletion(); | 397 MaybeNotifyFactoryOfCompletion(); |
| 396 } | 398 } |
| 397 | 399 |
| 398 void HttpStreamFactoryImpl::JobController::OnOrphanedJobComplete( | 400 void HttpStreamFactoryImpl::JobController::OnOrphanedJobComplete( |
| 399 const Job* job) { | 401 const Job* job) { |
| 400 if (job->job_type() == MAIN) { | 402 if (job->job_type() == MAIN) { |
| 401 DCHECK_EQ(main_job_.get(), job); | 403 DCHECK_EQ(main_job_.get(), job); |
| 402 main_job_.reset(); | 404 main_job_.reset(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 DCHECK(ContainsKey(spdy_session_request_map, *spdy_session_key)); | 454 DCHECK(ContainsKey(spdy_session_request_map, *spdy_session_key)); |
| 453 RequestSet& request_set = spdy_session_request_map[*spdy_session_key]; | 455 RequestSet& request_set = spdy_session_request_map[*spdy_session_key]; |
| 454 DCHECK(ContainsKey(request_set, request_)); | 456 DCHECK(ContainsKey(request_set, request_)); |
| 455 request_set.erase(request_); | 457 request_set.erase(request_); |
| 456 if (request_set.empty()) | 458 if (request_set.empty()) |
| 457 spdy_session_request_map.erase(*spdy_session_key); | 459 spdy_session_request_map.erase(*spdy_session_key); |
| 458 request_->ResetSpdySessionKey(); | 460 request_->ResetSpdySessionKey(); |
| 459 } | 461 } |
| 460 } | 462 } |
| 461 | 463 |
| 464 void HttpStreamFactoryImpl::JobController::MaybeResumeOtherJob( | |
| 465 Job* job, | |
| 466 const base::TimeDelta& delay) { | |
| 467 if (!blocking_) | |
| 468 return; | |
| 469 | |
| 470 if (job == alternative_job_.get() && main_job_) { | |
| 471 main_job_->Resume(delay); | |
| 472 } else if (job != main_job_.get() && job != alternative_job_.get()) { | |
|
Ryan Hamilton
2016/05/17 22:14:09
nit: I might move this to a DCHECK() at the top of
Zhongyi Shi
2016/06/29 21:49:03
Done.
| |
| 473 NOTREACHED(); | |
| 474 } | |
| 475 blocking_ = false; | |
| 476 } | |
| 477 | |
| 478 bool HttpStreamFactoryImpl::JobController::ResumeJobWithDelay(Job* job) const { | |
| 479 base::WeakPtrFactory<Job> ptr_factory(job); | |
| 480 if (wait_time_.is_zero()) { | |
| 481 if (job->job_type() == ALTERNATIVE || !blocking_) { | |
| 482 // There is no blocking job and there is no |wait_time_|. | |
| 483 return false; | |
| 484 } | |
| 485 } else { | |
| 486 DCHECK(job->job_type() == ALTERNATIVE || !blocking_); | |
| 487 job->ResumeAfterDelay(wait_time_); | |
| 488 } | |
| 489 return true; | |
| 490 } | |
| 462 const BoundNetLog* HttpStreamFactoryImpl::JobController::GetNetLog( | 491 const BoundNetLog* HttpStreamFactoryImpl::JobController::GetNetLog( |
| 463 Job* job) const { | 492 Job* job) const { |
| 464 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) | 493 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) |
| 465 return nullptr; | 494 return nullptr; |
| 466 DCHECK(request_); | 495 DCHECK(request_); |
| 467 return &request_->net_log(); | 496 return &request_->net_log(); |
| 468 } | 497 } |
| 469 | 498 |
| 470 WebSocketHandshakeStreamBase::CreateHelper* HttpStreamFactoryImpl:: | 499 WebSocketHandshakeStreamBase::CreateHelper* HttpStreamFactoryImpl:: |
| 471 JobController::websocket_handshake_stream_create_helper() { | 500 JobController::websocket_handshake_stream_create_helper() { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 HostPortPair alternative_destination(alternative_service.host_port_pair()); | 534 HostPortPair alternative_destination(alternative_service.host_port_pair()); |
| 506 ignore_result( | 535 ignore_result( |
| 507 ApplyHostMappingRules(request_info.url, &alternative_destination)); | 536 ApplyHostMappingRules(request_info.url, &alternative_destination)); |
| 508 | 537 |
| 509 alternative_job_.reset( | 538 alternative_job_.reset( |
| 510 new Job(this, ALTERNATIVE, session_, request_info, priority, | 539 new Job(this, ALTERNATIVE, session_, request_info, priority, |
| 511 server_ssl_config, proxy_ssl_config, alternative_destination, | 540 server_ssl_config, proxy_ssl_config, alternative_destination, |
| 512 origin_url, alternative_service, net_log.net_log())); | 541 origin_url, alternative_service, net_log.net_log())); |
| 513 AttachJob(alternative_job_.get()); | 542 AttachJob(alternative_job_.get()); |
| 514 | 543 |
| 515 main_job_->WaitFor(alternative_job_.get()); | 544 blocking_ = true; |
| 516 // Make sure to wait until we call WaitFor(), before starting | |
| 517 // |alternative_job|, otherwise |alternative_job| will not notify |job| | |
| 518 // appropriately. | |
| 519 alternative_job_->Start(request_->stream_type()); | 545 alternative_job_->Start(request_->stream_type()); |
| 520 } | 546 } |
| 521 // Even if |alternative_job| has already finished, it will not have notified | 547 // Even if |alternative_job| has already finished, it will not have notified |
| 522 // the request yet, since we defer that to the next iteration of the | 548 // the request yet, since we defer that to the next iteration of the |
| 523 // MessageLoop, so starting |main_job_| is always safe. | 549 // MessageLoop, so starting |main_job_| is always safe. |
| 524 main_job_->Start(request_->stream_type()); | 550 main_job_->Start(request_->stream_type()); |
| 525 } | 551 } |
| 526 | 552 |
| 527 void HttpStreamFactoryImpl::JobController::AttachJob(Job* job) { | 553 void HttpStreamFactoryImpl::JobController::AttachJob(Job* job) { |
| 528 DCHECK(job); | 554 DCHECK(job); |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 767 first_alternative_service = alternative_service; | 793 first_alternative_service = alternative_service; |
| 768 } | 794 } |
| 769 | 795 |
| 770 // Ask delegate to mark QUIC as broken for the origin. | 796 // Ask delegate to mark QUIC as broken for the origin. |
| 771 if (quic_advertised && quic_all_broken && delegate != nullptr) | 797 if (quic_advertised && quic_all_broken && delegate != nullptr) |
| 772 delegate->OnQuicBroken(); | 798 delegate->OnQuicBroken(); |
| 773 | 799 |
| 774 return first_alternative_service; | 800 return first_alternative_service; |
| 775 } | 801 } |
| 776 } | 802 } |
| OLD | NEW |