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

Side by Side Diff: net/quic/chromium/quic_stream_factory.cc

Issue 2842883002: Change QuicStreamFactory::active_jobs_ to a Map from QuicServerId to Job (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « net/quic/chromium/quic_stream_factory.h ('k') | net/quic/chromium/quic_stream_factory_peer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/quic/chromium/quic_stream_factory.h" 5 #include "net/quic/chromium/quic_stream_factory.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <tuple> 8 #include <tuple>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 if (it != active_sessions_.end()) { 891 if (it != active_sessions_.end()) {
892 QuicChromiumClientSession* session = it->second; 892 QuicChromiumClientSession* session = it->second;
893 request->SetSession(session); 893 request->SetSession(session);
894 return OK; 894 return OK;
895 } 895 }
896 } 896 }
897 897
898 // Associate with active job to |server_id| if such exists. 898 // Associate with active job to |server_id| if such exists.
899 auto it = active_jobs_.find(server_id); 899 auto it = active_jobs_.find(server_id);
900 if (it != active_jobs_.end()) { 900 if (it != active_jobs_.end()) {
901 const JobSet& job_set = it->second; 901 const NetLogWithSource& job_net_log = it->second->net_log();
902 // TODO(zhongyi): figure out how to link the NetLogs if there are more than 902 job_net_log.AddEvent(
903 // one job serving the same server id, i.e., auxiliary job is also 903 NetLogEventType::QUIC_STREAM_FACTORY_JOB_BOUND_TO_HTTP_STREAM_JOB,
904 // created. 904 net_log.source().ToEventParametersCallback());
905 if (job_set.size() == 1) { 905 net_log.AddEvent(
906 const NetLogWithSource& job_net_log = job_set.begin()->first->net_log(); 906 NetLogEventType::HTTP_STREAM_JOB_BOUND_TO_QUIC_STREAM_FACTORY_JOB,
907 job_net_log.AddEvent( 907 job_net_log.source().ToEventParametersCallback());
908 NetLogEventType::QUIC_STREAM_FACTORY_JOB_BOUND_TO_HTTP_STREAM_JOB,
909 net_log.source().ToEventParametersCallback());
910 net_log.AddEvent(
911 NetLogEventType::HTTP_STREAM_JOB_BOUND_TO_QUIC_STREAM_FACTORY_JOB,
912 job_net_log.source().ToEventParametersCallback());
913 }
914 job_requests_map_[server_id].insert(request); 908 job_requests_map_[server_id].insert(request);
915 return ERR_IO_PENDING; 909 return ERR_IO_PENDING;
916 } 910 }
917 911
918 // Pool to active session to |destination| if possible. 912 // Pool to active session to |destination| if possible.
919 if (!active_sessions_.empty()) { 913 if (!active_sessions_.empty()) {
920 for (const auto& key_value : active_sessions_) { 914 for (const auto& key_value : active_sessions_) {
921 QuicChromiumClientSession* session = key_value.second; 915 QuicChromiumClientSession* session = key_value.second;
922 if (destination.Equals(all_sessions_[session].destination()) && 916 if (destination.Equals(all_sessions_[session].destination()) &&
923 session->CanPool(server_id.host(), server_id.privacy_mode())) { 917 session->CanPool(server_id.host(), server_id.privacy_mode())) {
(...skipping 11 matching lines...) Expand all
935 ignore_result(StartCertVerifyJob(server_id, cert_verify_flags, net_log)); 929 ignore_result(StartCertVerifyJob(server_id, cert_verify_flags, net_log));
936 930
937 QuicSessionKey key(destination, server_id); 931 QuicSessionKey key(destination, server_id);
938 std::unique_ptr<Job> job = base::MakeUnique<Job>( 932 std::unique_ptr<Job> job = base::MakeUnique<Job>(
939 this, host_resolver_, key, WasQuicRecentlyBroken(server_id), 933 this, host_resolver_, key, WasQuicRecentlyBroken(server_id),
940 cert_verify_flags, net_log); 934 cert_verify_flags, net_log);
941 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, 935 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete,
942 base::Unretained(this), job.get())); 936 base::Unretained(this), job.get()));
943 if (rv == ERR_IO_PENDING) { 937 if (rv == ERR_IO_PENDING) {
944 job_requests_map_[server_id].insert(request); 938 job_requests_map_[server_id].insert(request);
945 Job* job_ptr = job.get(); 939 active_jobs_[server_id] = std::move(job);
946 active_jobs_[server_id][job_ptr] = std::move(job);
947 return rv; 940 return rv;
948 } 941 }
949 if (rv == OK) { 942 if (rv == OK) {
950 // TODO(rtenneti): crbug.com/498823 - revert active_sessions_.empty() 943 // TODO(rtenneti): crbug.com/498823 - revert active_sessions_.empty()
951 // related changes. 944 // related changes.
952 if (active_sessions_.empty()) 945 if (active_sessions_.empty())
953 return ERR_QUIC_PROTOCOL_ERROR; 946 return ERR_QUIC_PROTOCOL_ERROR;
954 SessionMap::iterator it = active_sessions_.find(server_id); 947 SessionMap::iterator it = active_sessions_.find(server_id);
955 DCHECK(it != active_sessions_.end()); 948 DCHECK(it != active_sessions_.end());
956 if (it == active_sessions_.end()) 949 if (it == active_sessions_.end())
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 return true; 993 return true;
1001 } 994 }
1002 } 995 }
1003 return false; 996 return false;
1004 } 997 }
1005 998
1006 void QuicStreamFactory::OnJobComplete(Job* job, int rv) { 999 void QuicStreamFactory::OnJobComplete(Job* job, int rv) {
1007 // Copy |server_id|, because |job| might be destroyed before this method 1000 // Copy |server_id|, because |job| might be destroyed before this method
1008 // returns. 1001 // returns.
1009 const QuicServerId server_id(job->key().server_id()); 1002 const QuicServerId server_id(job->key().server_id());
1010 if (rv != OK) {
1011 JobSet* jobs = &(active_jobs_[server_id]);
1012 if (jobs->size() > 1) {
1013 // If there is another pending job, then we can delete this job and let
1014 // the other job handle the request.
1015 job->Cancel();
1016 jobs->erase(job);
1017 return;
1018 }
1019 }
1020 1003
1021 ServerIDRequestsMap::iterator requests_iter = 1004 ServerIDRequestsMap::iterator requests_iter =
1022 job_requests_map_.find(server_id); 1005 job_requests_map_.find(server_id);
1023 DCHECK(requests_iter != job_requests_map_.end()); 1006 DCHECK(requests_iter != job_requests_map_.end());
1024 if (rv == OK) { 1007 if (rv == OK) {
1025 set_require_confirmation(false); 1008 set_require_confirmation(false);
1026 1009
1027 if (!requests_iter->second.empty()) { 1010 if (!requests_iter->second.empty()) {
1028 SessionMap::iterator session_it = active_sessions_.find(server_id); 1011 SessionMap::iterator session_it = active_sessions_.find(server_id);
1029 DCHECK(session_it != active_sessions_.end()); 1012 DCHECK(session_it != active_sessions_.end());
1030 QuicChromiumClientSession* session = session_it->second; 1013 QuicChromiumClientSession* session = session_it->second;
1031 for (QuicStreamRequest* request : requests_iter->second) { 1014 for (QuicStreamRequest* request : requests_iter->second) {
1032 DCHECK(request->server_id() == server_id); 1015 DCHECK(request->server_id() == server_id);
1033 // Do not notify |request| yet. 1016 // Do not notify |request| yet.
1034 request->SetSession(session); 1017 request->SetSession(session);
1035 } 1018 }
1036 } 1019 }
1037 } 1020 }
1038 1021
1039 // It's okay not to erase |request| from |requests_iter->second| because the 1022 // It's okay not to erase |request| from |requests_iter->second| because the
1040 // entire RequestSet will be erased from |job_requests_map_|. 1023 // entire RequestSet will be erased from |job_requests_map_|.
1041 for (auto* request : requests_iter->second) { 1024 for (auto* request : requests_iter->second) {
1042 // Even though we're invoking callbacks here, we don't need to worry 1025 // Even though we're invoking callbacks here, we don't need to worry
1043 // about |this| being deleted, because the factory is owned by the 1026 // about |this| being deleted, because the factory is owned by the
1044 // profile which can not be deleted via callbacks. 1027 // profile which can not be deleted via callbacks.
1045 request->OnRequestComplete(rv); 1028 request->OnRequestComplete(rv);
1046 } 1029 }
1047 1030
1048 for (auto& other_job : active_jobs_[server_id]) {
1049 if (other_job.first != job)
1050 other_job.first->Cancel();
1051 }
1052
1053 active_jobs_[server_id].clear();
1054 active_jobs_.erase(server_id); 1031 active_jobs_.erase(server_id);
1055 job_requests_map_.erase(requests_iter); 1032 job_requests_map_.erase(requests_iter);
1056 } 1033 }
1057 1034
1058 void QuicStreamFactory::OnCertVerifyJobComplete(CertVerifierJob* job, int rv) { 1035 void QuicStreamFactory::OnCertVerifyJobComplete(CertVerifierJob* job, int rv) {
1059 active_cert_verifier_jobs_.erase(job->server_id()); 1036 active_cert_verifier_jobs_.erase(job->server_id());
1060 } 1037 }
1061 1038
1062 void QuicStreamFactory::OnIdleSession(QuicChromiumClientSession* session) {} 1039 void QuicStreamFactory::OnIdleSession(QuicChromiumClientSession* session) {}
1063 1040
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 // Since the session was active, there's no longer an 1703 // Since the session was active, there's no longer an
1727 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP 1704 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP
1728 // job also fails. So to avoid not using QUIC when we otherwise could, we mark 1705 // job also fails. So to avoid not using QUIC when we otherwise could, we mark
1729 // it as recently broken, which means that 0-RTT will be disabled but we'll 1706 // it as recently broken, which means that 0-RTT will be disabled but we'll
1730 // still race. 1707 // still race.
1731 http_server_properties_->MarkAlternativeServiceRecentlyBroken( 1708 http_server_properties_->MarkAlternativeServiceRecentlyBroken(
1732 alternative_service); 1709 alternative_service);
1733 } 1710 }
1734 1711
1735 } // namespace net 1712 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/chromium/quic_stream_factory.h ('k') | net/quic/chromium/quic_stream_factory_peer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698