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

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

Issue 2334943002: Add a new QuicChromiumClientSession::Handle class (Closed)
Patch Set: cleanup 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
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 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 net_log_ = net_log; 600 net_log_ = net_log;
601 callback_ = callback; 601 callback_ = callback;
602 } else { 602 } else {
603 factory_ = nullptr; 603 factory_ = nullptr;
604 } 604 }
605 if (rv == OK) 605 if (rv == OK)
606 DCHECK(session_); 606 DCHECK(session_);
607 return rv; 607 return rv;
608 } 608 }
609 609
610 void QuicStreamRequest::SetSession(QuicChromiumClientSession* session) { 610 void QuicStreamRequest::SetSession(
611 DCHECK(session); 611 const QuicChromiumClientSession::Handle& session) {
612 session_ = session->GetWeakPtr(); 612 session_.reset(new QuicChromiumClientSession::Handle(session));
613 } 613 }
614 614
615 void QuicStreamRequest::OnRequestComplete(int rv) { 615 void QuicStreamRequest::OnRequestComplete(int rv) {
616 factory_ = nullptr; 616 factory_ = nullptr;
617 base::ResetAndReturn(&callback_).Run(rv); 617 base::ResetAndReturn(&callback_).Run(rv);
618 } 618 }
619 619
620 base::TimeDelta QuicStreamRequest::GetTimeDelayForWaitingJob() const { 620 base::TimeDelta QuicStreamRequest::GetTimeDelayForWaitingJob() const {
621 if (!factory_) 621 if (!factory_)
622 return base::TimeDelta(); 622 return base::TimeDelta();
623 return factory_->GetTimeDelayForWaitingJob(server_id_); 623 return factory_->GetTimeDelayForWaitingJob(server_id_);
624 } 624 }
625 625
626 std::unique_ptr<HttpStream> QuicStreamRequest::CreateStream() { 626 std::unique_ptr<HttpStream> QuicStreamRequest::CreateStream() {
627 if (!session_) 627 if (!session_ || !session_->IsConnected())
628 return nullptr; 628 return nullptr;
629 return base::MakeUnique<QuicHttpStream>(session_, http_server_properties_); 629
630 return base::MakeUnique<QuicHttpStream>(*session_, http_server_properties_);
630 } 631 }
631 632
632 std::unique_ptr<BidirectionalStreamImpl> 633 std::unique_ptr<BidirectionalStreamImpl>
633 QuicStreamRequest::CreateBidirectionalStreamImpl() { 634 QuicStreamRequest::CreateBidirectionalStreamImpl() {
634 if (!session_) 635 if (!session_ || !session_->IsConnected())
635 return nullptr; 636 return nullptr;
636 return base::MakeUnique<BidirectionalStreamQuicImpl>(session_); 637
638 return base::MakeUnique<BidirectionalStreamQuicImpl>(*session_);
637 } 639 }
638 640
639 QuicStreamFactory::QuicStreamFactory( 641 QuicStreamFactory::QuicStreamFactory(
640 NetLog* net_log, 642 NetLog* net_log,
641 HostResolver* host_resolver, 643 HostResolver* host_resolver,
642 SSLConfigService* ssl_config_service, 644 SSLConfigService* ssl_config_service,
643 ClientSocketFactory* client_socket_factory, 645 ClientSocketFactory* client_socket_factory,
644 HttpServerProperties* http_server_properties, 646 HttpServerProperties* http_server_properties,
645 ProxyDelegate* proxy_delegate, 647 ProxyDelegate* proxy_delegate,
646 CertVerifier* cert_verifier, 648 CertVerifier* cert_verifier,
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 } 869 }
868 DCHECK(server_id.host_port_pair().Equals(HostPortPair::FromURL(url))); 870 DCHECK(server_id.host_port_pair().Equals(HostPortPair::FromURL(url)));
869 // Enforce session affinity for promised streams. 871 // Enforce session affinity for promised streams.
870 QuicClientPromisedInfo* promised = 872 QuicClientPromisedInfo* promised =
871 push_promise_index_.GetPromised(url.spec()); 873 push_promise_index_.GetPromised(url.spec());
872 if (promised) { 874 if (promised) {
873 QuicChromiumClientSession* session = 875 QuicChromiumClientSession* session =
874 static_cast<QuicChromiumClientSession*>(promised->session()); 876 static_cast<QuicChromiumClientSession*>(promised->session());
875 DCHECK(session); 877 DCHECK(session);
876 if (session->server_id().privacy_mode() == server_id.privacy_mode()) { 878 if (session->server_id().privacy_mode() == server_id.privacy_mode()) {
877 request->SetSession(session); 879 request->SetSession(session->GetHandle());
878 ++num_push_streams_created_; 880 ++num_push_streams_created_;
879 return OK; 881 return OK;
880 } 882 }
881 // This should happen extremely rarely (if ever), but if somehow a 883 // This should happen extremely rarely (if ever), but if somehow a
882 // request comes in with a mismatched privacy mode, consider the 884 // request comes in with a mismatched privacy mode, consider the
883 // promise borked. 885 // promise borked.
884 promised->Cancel(); 886 promised->Cancel();
885 } 887 }
886 888
887 // Use active session for |server_id| if such exists. 889 // Use active session for |server_id| if such exists.
888 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() checks. 890 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() checks.
889 if (!active_sessions_.empty()) { 891 if (!active_sessions_.empty()) {
890 SessionMap::iterator it = active_sessions_.find(server_id); 892 SessionMap::iterator it = active_sessions_.find(server_id);
891 if (it != active_sessions_.end()) { 893 if (it != active_sessions_.end()) {
892 QuicChromiumClientSession* session = it->second; 894 QuicChromiumClientSession* session = it->second;
893 request->SetSession(session); 895 request->SetSession(session->GetHandle());
894 return OK; 896 return OK;
895 } 897 }
896 } 898 }
897 899
898 // Associate with active job to |server_id| if such exists. 900 // Associate with active job to |server_id| if such exists.
899 auto it = active_jobs_.find(server_id); 901 auto it = active_jobs_.find(server_id);
900 if (it != active_jobs_.end()) { 902 if (it != active_jobs_.end()) {
901 const NetLogWithSource& job_net_log = it->second->net_log(); 903 const NetLogWithSource& job_net_log = it->second->net_log();
902 job_net_log.AddEvent( 904 job_net_log.AddEvent(
903 NetLogEventType::QUIC_STREAM_FACTORY_JOB_BOUND_TO_HTTP_STREAM_JOB, 905 NetLogEventType::QUIC_STREAM_FACTORY_JOB_BOUND_TO_HTTP_STREAM_JOB,
904 net_log.source().ToEventParametersCallback()); 906 net_log.source().ToEventParametersCallback());
905 net_log.AddEvent( 907 net_log.AddEvent(
906 NetLogEventType::HTTP_STREAM_JOB_BOUND_TO_QUIC_STREAM_FACTORY_JOB, 908 NetLogEventType::HTTP_STREAM_JOB_BOUND_TO_QUIC_STREAM_FACTORY_JOB,
907 job_net_log.source().ToEventParametersCallback()); 909 job_net_log.source().ToEventParametersCallback());
908 job_requests_map_[server_id].insert(request); 910 job_requests_map_[server_id].insert(request);
909 return ERR_IO_PENDING; 911 return ERR_IO_PENDING;
910 } 912 }
911 913
912 // Pool to active session to |destination| if possible. 914 // Pool to active session to |destination| if possible.
913 if (!active_sessions_.empty()) { 915 if (!active_sessions_.empty()) {
914 for (const auto& key_value : active_sessions_) { 916 for (const auto& key_value : active_sessions_) {
915 QuicChromiumClientSession* session = key_value.second; 917 QuicChromiumClientSession* session = key_value.second;
916 if (destination.Equals(all_sessions_[session].destination()) && 918 if (destination.Equals(all_sessions_[session].destination()) &&
917 session->CanPool(server_id.host(), server_id.privacy_mode())) { 919 session->CanPool(server_id.host(), server_id.privacy_mode())) {
918 request->SetSession(session); 920 request->SetSession(session->GetHandle());
919 return OK; 921 return OK;
920 } 922 }
921 } 923 }
922 } 924 }
923 925
924 // TODO(rtenneti): |task_runner_| is used by the Job. Initialize task_runner_ 926 // TODO(rtenneti): |task_runner_| is used by the Job. Initialize task_runner_
925 // in the constructor after WebRequestActionWithThreadsTest.* tests are fixed. 927 // in the constructor after WebRequestActionWithThreadsTest.* tests are fixed.
926 if (!task_runner_) 928 if (!task_runner_)
927 task_runner_ = base::ThreadTaskRunnerHandle::Get().get(); 929 task_runner_ = base::ThreadTaskRunnerHandle::Get().get();
928 930
(...skipping 13 matching lines...) Expand all
942 if (rv == OK) { 944 if (rv == OK) {
943 // TODO(rtenneti): crbug.com/498823 - revert active_sessions_.empty() 945 // TODO(rtenneti): crbug.com/498823 - revert active_sessions_.empty()
944 // related changes. 946 // related changes.
945 if (active_sessions_.empty()) 947 if (active_sessions_.empty())
946 return ERR_QUIC_PROTOCOL_ERROR; 948 return ERR_QUIC_PROTOCOL_ERROR;
947 SessionMap::iterator it = active_sessions_.find(server_id); 949 SessionMap::iterator it = active_sessions_.find(server_id);
948 DCHECK(it != active_sessions_.end()); 950 DCHECK(it != active_sessions_.end());
949 if (it == active_sessions_.end()) 951 if (it == active_sessions_.end())
950 return ERR_QUIC_PROTOCOL_ERROR; 952 return ERR_QUIC_PROTOCOL_ERROR;
951 QuicChromiumClientSession* session = it->second; 953 QuicChromiumClientSession* session = it->second;
952 request->SetSession(session); 954 request->SetSession(session->GetHandle());
953 } 955 }
954 return rv; 956 return rv;
955 } 957 }
956 958
957 QuicStreamFactory::QuicSessionKey::QuicSessionKey( 959 QuicStreamFactory::QuicSessionKey::QuicSessionKey(
958 const HostPortPair& destination, 960 const HostPortPair& destination,
959 const QuicServerId& server_id) 961 const QuicServerId& server_id)
960 : destination_(destination), server_id_(server_id) {} 962 : destination_(destination), server_id_(server_id) {}
961 963
962 bool QuicStreamFactory::QuicSessionKey::operator<( 964 bool QuicStreamFactory::QuicSessionKey::operator<(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 if (rv == OK) { 1009 if (rv == OK) {
1008 set_require_confirmation(false); 1010 set_require_confirmation(false);
1009 1011
1010 if (!requests_iter->second.empty()) { 1012 if (!requests_iter->second.empty()) {
1011 SessionMap::iterator session_it = active_sessions_.find(server_id); 1013 SessionMap::iterator session_it = active_sessions_.find(server_id);
1012 DCHECK(session_it != active_sessions_.end()); 1014 DCHECK(session_it != active_sessions_.end());
1013 QuicChromiumClientSession* session = session_it->second; 1015 QuicChromiumClientSession* session = session_it->second;
1014 for (QuicStreamRequest* request : requests_iter->second) { 1016 for (QuicStreamRequest* request : requests_iter->second) {
1015 DCHECK(request->server_id() == server_id); 1017 DCHECK(request->server_id() == server_id);
1016 // Do not notify |request| yet. 1018 // Do not notify |request| yet.
1017 request->SetSession(session); 1019 request->SetSession(session->GetHandle());
1018 } 1020 }
1019 } 1021 }
1020 } 1022 }
1021 1023
1022 // It's okay not to erase |request| from |requests_iter->second| because the 1024 // It's okay not to erase |request| from |requests_iter->second| because the
1023 // entire RequestSet will be erased from |job_requests_map_|. 1025 // entire RequestSet will be erased from |job_requests_map_|.
1024 for (auto* request : requests_iter->second) { 1026 for (auto* request : requests_iter->second) {
1025 // Even though we're invoking callbacks here, we don't need to worry 1027 // Even though we're invoking callbacks here, we don't need to worry
1026 // about |this| being deleted, because the factory is owned by the 1028 // about |this| being deleted, because the factory is owned by the
1027 // profile which can not be deleted via callbacks. 1029 // profile which can not be deleted via callbacks.
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 // Since the session was active, there's no longer an 1705 // Since the session was active, there's no longer an
1704 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP 1706 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP
1705 // job also fails. So to avoid not using QUIC when we otherwise could, we mark 1707 // job also fails. So to avoid not using QUIC when we otherwise could, we mark
1706 // it as recently broken, which means that 0-RTT will be disabled but we'll 1708 // it as recently broken, which means that 0-RTT will be disabled but we'll
1707 // still race. 1709 // still race.
1708 http_server_properties_->MarkAlternativeServiceRecentlyBroken( 1710 http_server_properties_->MarkAlternativeServiceRecentlyBroken(
1709 alternative_service); 1711 alternative_service);
1710 } 1712 }
1711 1713
1712 } // namespace net 1714 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698