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 <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 618 return true; | 618 return true; |
| 619 } | 619 } |
| 620 | 620 |
| 621 void HttpStreamFactoryImpl::JobController::SetSpdySessionKey( | 621 void HttpStreamFactoryImpl::JobController::SetSpdySessionKey( |
| 622 Job* job, | 622 Job* job, |
| 623 const SpdySessionKey& spdy_session_key) { | 623 const SpdySessionKey& spdy_session_key) { |
| 624 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) | 624 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) |
| 625 return; | 625 return; |
| 626 | 626 |
| 627 DCHECK(request_); | 627 DCHECK(request_); |
| 628 if (!request_->HasSpdySessionKey()) { | 628 if (!request_->HasSpdySessionKey()) { |
|
Bence
2017/03/31 16:21:27
Is it possible that |request_| already has a SpdyS
xunjieli
2017/03/31 17:45:26
Good catch! It's possible that |request| already h
| |
| 629 RequestSet& request_set = | 629 RequestSet& request_set = |
| 630 factory_->spdy_session_request_map_[spdy_session_key]; | 630 factory_->spdy_session_request_map_[spdy_session_key]; |
| 631 DCHECK(!base::ContainsKey(request_set, request_)); | 631 DCHECK(!base::ContainsKey(request_set, request_)); |
| 632 request_set.insert(request_); | 632 request_set.insert(request_); |
| 633 request_->SetSpdySessionKey(spdy_session_key); | 633 request_->SetSpdySessionKey(spdy_session_key); |
| 634 } | 634 } |
| 635 } | 635 } |
| 636 | 636 |
| 637 void HttpStreamFactoryImpl::JobController:: | 637 void HttpStreamFactoryImpl::JobController:: |
| 638 RemoveRequestFromSpdySessionRequestMapForJob(Job* job) { | 638 RemoveRequestFromSpdySessionRequestMapForJob(Job* job) { |
| 639 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) | 639 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) |
| 640 return; | 640 return; |
| 641 DCHECK(request_); | 641 DCHECK(request_); |
| 642 | 642 |
| 643 RemoveRequestFromSpdySessionRequestMap(); | 643 factory_->RemoveRequestFromSpdySessionRequestMap(request_); |
| 644 } | |
| 645 | |
| 646 void HttpStreamFactoryImpl::JobController:: | |
| 647 RemoveRequestFromSpdySessionRequestMap() { | |
| 648 const SpdySessionKey* spdy_session_key = request_->spdy_session_key(); | |
| 649 if (spdy_session_key) { | |
| 650 SpdySessionRequestMap& spdy_session_request_map = | |
| 651 factory_->spdy_session_request_map_; | |
| 652 DCHECK(base::ContainsKey(spdy_session_request_map, *spdy_session_key)); | |
| 653 RequestSet& request_set = spdy_session_request_map[*spdy_session_key]; | |
| 654 DCHECK(base::ContainsKey(request_set, request_)); | |
| 655 request_set.erase(request_); | |
| 656 if (request_set.empty()) | |
| 657 spdy_session_request_map.erase(*spdy_session_key); | |
| 658 request_->ResetSpdySessionKey(); | |
| 659 } | |
| 660 } | 644 } |
| 661 | 645 |
| 662 const NetLogWithSource* HttpStreamFactoryImpl::JobController::GetNetLog( | 646 const NetLogWithSource* HttpStreamFactoryImpl::JobController::GetNetLog( |
| 663 Job* job) const { | 647 Job* job) const { |
| 664 return &net_log_; | 648 return &net_log_; |
| 665 } | 649 } |
| 666 | 650 |
| 667 void HttpStreamFactoryImpl::JobController::MaybeSetWaitTimeForMainJob( | 651 void HttpStreamFactoryImpl::JobController::MaybeSetWaitTimeForMainJob( |
| 668 const base::TimeDelta& delay) { | 652 const base::TimeDelta& delay) { |
| 669 if (main_job_is_blocked_) { | 653 if (main_job_is_blocked_) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 766 job->net_log().source().ToEventParametersCallback()); | 750 job->net_log().source().ToEventParametersCallback()); |
| 767 job->net_log().AddEvent( | 751 job->net_log().AddEvent( |
| 768 NetLogEventType::HTTP_STREAM_JOB_BOUND_TO_REQUEST, | 752 NetLogEventType::HTTP_STREAM_JOB_BOUND_TO_REQUEST, |
| 769 request_->net_log().source().ToEventParametersCallback()); | 753 request_->net_log().source().ToEventParametersCallback()); |
| 770 | 754 |
| 771 OrphanUnboundJob(); | 755 OrphanUnboundJob(); |
| 772 } | 756 } |
| 773 | 757 |
| 774 void HttpStreamFactoryImpl::JobController::CancelJobs() { | 758 void HttpStreamFactoryImpl::JobController::CancelJobs() { |
| 775 DCHECK(request_); | 759 DCHECK(request_); |
| 776 RemoveRequestFromSpdySessionRequestMap(); | 760 factory_->RemoveRequestFromSpdySessionRequestMap(request_); |
| 777 if (job_bound_) | 761 if (job_bound_) |
| 778 return; | 762 return; |
| 779 if (alternative_job_) { | 763 if (alternative_job_) { |
| 780 factory_->request_map_.erase(alternative_job_.get()); | 764 factory_->request_map_.erase(alternative_job_.get()); |
| 781 alternative_job_.reset(); | 765 alternative_job_.reset(); |
| 782 } | 766 } |
| 783 if (main_job_) { | 767 if (main_job_) { |
| 784 factory_->request_map_.erase(main_job_.get()); | 768 factory_->request_map_.erase(main_job_.get()); |
| 785 main_job_.reset(); | 769 main_job_.reset(); |
| 786 } | 770 } |
| 787 } | 771 } |
| 788 | 772 |
| 789 void HttpStreamFactoryImpl::JobController::OrphanUnboundJob() { | 773 void HttpStreamFactoryImpl::JobController::OrphanUnboundJob() { |
| 790 DCHECK(request_); | 774 DCHECK(request_); |
| 791 RemoveRequestFromSpdySessionRequestMap(); | 775 factory_->RemoveRequestFromSpdySessionRequestMap(request_); |
| 792 | 776 |
| 793 DCHECK(bound_job_); | 777 DCHECK(bound_job_); |
| 794 if (bound_job_->job_type() == MAIN && alternative_job_) { | 778 if (bound_job_->job_type() == MAIN && alternative_job_) { |
| 795 factory_->request_map_.erase(alternative_job_.get()); | 779 factory_->request_map_.erase(alternative_job_.get()); |
| 796 alternative_job_->Orphan(); | 780 alternative_job_->Orphan(); |
| 797 } else if (bound_job_->job_type() == ALTERNATIVE && main_job_) { | 781 } else if (bound_job_->job_type() == ALTERNATIVE && main_job_) { |
| 798 // Orphan main job. | 782 // Orphan main job. |
| 799 factory_->request_map_.erase(main_job_.get()); | 783 factory_->request_map_.erase(main_job_.get()); |
| 800 // If ResumeMainJob() is not executed, reset |main_job_|. Otherwise, | 784 // If ResumeMainJob() is not executed, reset |main_job_|. Otherwise, |
| 801 // OnOrphanedJobComplete() will clean up |this| when the job completes. | 785 // OnOrphanedJobComplete() will clean up |this| when the job completes. |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1173 return; | 1157 return; |
| 1174 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); | 1158 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); |
| 1175 alternative_job_->Start(request_->stream_type()); | 1159 alternative_job_->Start(request_->stream_type()); |
| 1176 } | 1160 } |
| 1177 | 1161 |
| 1178 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const { | 1162 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const { |
| 1179 return !request_ || (job_bound_ && bound_job_ != job); | 1163 return !request_ || (job_bound_ && bound_job_ != job); |
| 1180 } | 1164 } |
| 1181 | 1165 |
| 1182 } // namespace net | 1166 } // namespace net |
| OLD | NEW |