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