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

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

Issue 2784143003: Fix a potential infinite loop in HttpStreamFactoryImpl when a new SpdySession is established (Closed)
Patch Set: Address comments Created 3 years, 8 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 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Remove old key request mapping if applicable.
629 RequestSet& request_set = 629 if (request_->HasSpdySessionKey())
630 factory_->spdy_session_request_map_[spdy_session_key]; 630 factory_->RemoveRequestFromSpdySessionRequestMap(request_);
631 DCHECK(!base::ContainsKey(request_set, request_)); 631
632 request_set.insert(request_); 632 // Insert a new mapping for the request.
633 request_->SetSpdySessionKey(spdy_session_key); 633 RequestSet& request_set =
634 } 634 factory_->spdy_session_request_map_[spdy_session_key];
635 DCHECK(!base::ContainsKey(request_set, request_));
636 request_set.insert(request_);
637 request_->SetSpdySessionKey(spdy_session_key);
635 } 638 }
636 639
637 void HttpStreamFactoryImpl::JobController:: 640 void HttpStreamFactoryImpl::JobController::
638 RemoveRequestFromSpdySessionRequestMapForJob(Job* job) { 641 RemoveRequestFromSpdySessionRequestMapForJob(Job* job) {
639 if (is_preconnect_ || (job_bound_ && bound_job_ != job)) 642 if (is_preconnect_ || (job_bound_ && bound_job_ != job))
640 return; 643 return;
641 DCHECK(request_); 644 DCHECK(request_);
642 645
643 RemoveRequestFromSpdySessionRequestMap(); 646 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 } 647 }
661 648
662 const NetLogWithSource* HttpStreamFactoryImpl::JobController::GetNetLog( 649 const NetLogWithSource* HttpStreamFactoryImpl::JobController::GetNetLog(
663 Job* job) const { 650 Job* job) const {
664 return &net_log_; 651 return &net_log_;
665 } 652 }
666 653
667 void HttpStreamFactoryImpl::JobController::MaybeSetWaitTimeForMainJob( 654 void HttpStreamFactoryImpl::JobController::MaybeSetWaitTimeForMainJob(
668 const base::TimeDelta& delay) { 655 const base::TimeDelta& delay) {
669 if (main_job_is_blocked_) { 656 if (main_job_is_blocked_) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 job->net_log().source().ToEventParametersCallback()); 753 job->net_log().source().ToEventParametersCallback());
767 job->net_log().AddEvent( 754 job->net_log().AddEvent(
768 NetLogEventType::HTTP_STREAM_JOB_BOUND_TO_REQUEST, 755 NetLogEventType::HTTP_STREAM_JOB_BOUND_TO_REQUEST,
769 request_->net_log().source().ToEventParametersCallback()); 756 request_->net_log().source().ToEventParametersCallback());
770 757
771 OrphanUnboundJob(); 758 OrphanUnboundJob();
772 } 759 }
773 760
774 void HttpStreamFactoryImpl::JobController::CancelJobs() { 761 void HttpStreamFactoryImpl::JobController::CancelJobs() {
775 DCHECK(request_); 762 DCHECK(request_);
776 RemoveRequestFromSpdySessionRequestMap(); 763 factory_->RemoveRequestFromSpdySessionRequestMap(request_);
777 if (job_bound_) 764 if (job_bound_)
778 return; 765 return;
779 if (alternative_job_) { 766 if (alternative_job_) {
780 factory_->request_map_.erase(alternative_job_.get()); 767 factory_->request_map_.erase(alternative_job_.get());
781 alternative_job_.reset(); 768 alternative_job_.reset();
782 } 769 }
783 if (main_job_) { 770 if (main_job_) {
784 factory_->request_map_.erase(main_job_.get()); 771 factory_->request_map_.erase(main_job_.get());
785 main_job_.reset(); 772 main_job_.reset();
786 } 773 }
787 } 774 }
788 775
789 void HttpStreamFactoryImpl::JobController::OrphanUnboundJob() { 776 void HttpStreamFactoryImpl::JobController::OrphanUnboundJob() {
790 DCHECK(request_); 777 DCHECK(request_);
791 RemoveRequestFromSpdySessionRequestMap(); 778 factory_->RemoveRequestFromSpdySessionRequestMap(request_);
792 779
793 DCHECK(bound_job_); 780 DCHECK(bound_job_);
794 if (bound_job_->job_type() == MAIN && alternative_job_) { 781 if (bound_job_->job_type() == MAIN && alternative_job_) {
795 factory_->request_map_.erase(alternative_job_.get()); 782 factory_->request_map_.erase(alternative_job_.get());
796 alternative_job_->Orphan(); 783 alternative_job_->Orphan();
797 } else if (bound_job_->job_type() == ALTERNATIVE && main_job_) { 784 } else if (bound_job_->job_type() == ALTERNATIVE && main_job_) {
798 // Orphan main job. 785 // Orphan main job.
799 factory_->request_map_.erase(main_job_.get()); 786 factory_->request_map_.erase(main_job_.get());
800 // If ResumeMainJob() is not executed, reset |main_job_|. Otherwise, 787 // If ResumeMainJob() is not executed, reset |main_job_|. Otherwise,
801 // OnOrphanedJobComplete() will clean up |this| when the job completes. 788 // OnOrphanedJobComplete() will clean up |this| when the job completes.
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 return; 1160 return;
1174 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); 1161 DCHECK(alternative_job_->alternative_proxy_server().is_valid());
1175 alternative_job_->Start(request_->stream_type()); 1162 alternative_job_->Start(request_->stream_type());
1176 } 1163 }
1177 1164
1178 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const { 1165 bool HttpStreamFactoryImpl::JobController::IsJobOrphaned(Job* job) const {
1179 return !request_ || (job_bound_ && bound_job_ != job); 1166 return !request_ || (job_bound_ && bound_job_ != job);
1180 } 1167 }
1181 1168
1182 } // namespace net 1169 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl_job_controller.h ('k') | net/http/http_stream_factory_impl_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698