| 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/quic_stream_factory.h" | 5 #include "net/quic/quic_stream_factory.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 #include "base/win/windows_version.h" | 54 #include "base/win/windows_version.h" |
| 55 #endif | 55 #endif |
| 56 | 56 |
| 57 #if defined(USE_OPENSSL) | 57 #if defined(USE_OPENSSL) |
| 58 #include <openssl/aead.h> | 58 #include <openssl/aead.h> |
| 59 #include "crypto/openssl_util.h" | 59 #include "crypto/openssl_util.h" |
| 60 #else | 60 #else |
| 61 #include "base/cpu.h" | 61 #include "base/cpu.h" |
| 62 #endif | 62 #endif |
| 63 | 63 |
| 64 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) |
| 65 #include "net/http/bidirectional_stream_job.h" |
| 66 #include "net/quic/bidirectional_stream_quic_impl.h" |
| 67 #endif |
| 68 |
| 64 using std::min; | 69 using std::min; |
| 65 using NetworkHandle = net::NetworkChangeNotifier::NetworkHandle; | 70 using NetworkHandle = net::NetworkChangeNotifier::NetworkHandle; |
| 66 | 71 |
| 67 namespace net { | 72 namespace net { |
| 68 | 73 |
| 69 namespace { | 74 namespace { |
| 70 | 75 |
| 71 enum CreateSessionFailure { | 76 enum CreateSessionFailure { |
| 72 CREATION_ERROR_CONNECTING_SOCKET, | 77 CREATION_ERROR_CONNECTING_SOCKET, |
| 73 CREATION_ERROR_SETTING_RECEIVE_BUFFER, | 78 CREATION_ERROR_SETTING_RECEIVE_BUFFER, |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 factory_->CancelRequest(this); | 511 factory_->CancelRequest(this); |
| 507 } | 512 } |
| 508 | 513 |
| 509 int QuicStreamRequest::Request(const HostPortPair& host_port_pair, | 514 int QuicStreamRequest::Request(const HostPortPair& host_port_pair, |
| 510 PrivacyMode privacy_mode, | 515 PrivacyMode privacy_mode, |
| 511 int cert_verify_flags, | 516 int cert_verify_flags, |
| 512 const GURL& url, | 517 const GURL& url, |
| 513 base::StringPiece method, | 518 base::StringPiece method, |
| 514 const BoundNetLog& net_log, | 519 const BoundNetLog& net_log, |
| 515 const CompletionCallback& callback) { | 520 const CompletionCallback& callback) { |
| 516 DCHECK(!stream_); | |
| 517 DCHECK(callback_.is_null()); | 521 DCHECK(callback_.is_null()); |
| 518 DCHECK(factory_); | 522 DCHECK(factory_); |
| 519 origin_host_ = url.host(); | 523 origin_host_ = url.host(); |
| 520 privacy_mode_ = privacy_mode; | 524 privacy_mode_ = privacy_mode; |
| 525 |
| 521 int rv = factory_->Create(host_port_pair, privacy_mode, cert_verify_flags, | 526 int rv = factory_->Create(host_port_pair, privacy_mode, cert_verify_flags, |
| 522 url, method, net_log, this); | 527 url, method, net_log, this); |
| 523 if (rv == ERR_IO_PENDING) { | 528 if (rv == ERR_IO_PENDING) { |
| 524 host_port_pair_ = host_port_pair; | 529 host_port_pair_ = host_port_pair; |
| 525 net_log_ = net_log; | 530 net_log_ = net_log; |
| 526 callback_ = callback; | 531 callback_ = callback; |
| 527 } else { | 532 } else { |
| 528 factory_ = nullptr; | 533 factory_ = nullptr; |
| 529 } | 534 } |
| 530 if (rv == OK) | 535 if (rv == OK) |
| 531 DCHECK(stream_); | 536 DCHECK(session_); |
| 532 return rv; | 537 return rv; |
| 533 } | 538 } |
| 534 | 539 |
| 535 void QuicStreamRequest::set_stream(scoped_ptr<QuicHttpStream> stream) { | 540 void QuicStreamRequest::SetSession(QuicChromiumClientSession* session) { |
| 536 DCHECK(stream); | 541 DCHECK(session); |
| 537 stream_ = std::move(stream); | 542 session_ = session->GetWeakPtr(); |
| 538 } | 543 } |
| 539 | 544 |
| 540 void QuicStreamRequest::OnRequestComplete(int rv) { | 545 void QuicStreamRequest::OnRequestComplete(int rv) { |
| 541 factory_ = nullptr; | 546 factory_ = nullptr; |
| 542 callback_.Run(rv); | 547 callback_.Run(rv); |
| 543 } | 548 } |
| 544 | 549 |
| 545 base::TimeDelta QuicStreamRequest::GetTimeDelayForWaitingJob() const { | 550 base::TimeDelta QuicStreamRequest::GetTimeDelayForWaitingJob() const { |
| 546 if (!factory_) | 551 if (!factory_) |
| 547 return base::TimeDelta(); | 552 return base::TimeDelta(); |
| 548 return factory_->GetTimeDelayForWaitingJob( | 553 return factory_->GetTimeDelayForWaitingJob( |
| 549 QuicServerId(host_port_pair_, privacy_mode_)); | 554 QuicServerId(host_port_pair_, privacy_mode_)); |
| 550 } | 555 } |
| 551 | 556 |
| 552 scoped_ptr<QuicHttpStream> QuicStreamRequest::ReleaseStream() { | 557 scoped_ptr<QuicHttpStream> QuicStreamRequest::CreateStream() { |
| 553 DCHECK(stream_); | 558 if (!session_) |
| 554 return std::move(stream_); | 559 return nullptr; |
| 560 return make_scoped_ptr(new QuicHttpStream(session_)); |
| 555 } | 561 } |
| 556 | 562 |
| 563 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) |
| 564 scoped_ptr<BidirectionalStreamJob> |
| 565 QuicStreamRequest::CreateBidirectionalStreamJob() { |
| 566 if (!session_) |
| 567 return nullptr; |
| 568 return make_scoped_ptr(new BidirectionalStreamQuicImpl(session_)); |
| 569 } |
| 570 #endif |
| 571 |
| 557 QuicStreamFactory::QuicStreamFactory( | 572 QuicStreamFactory::QuicStreamFactory( |
| 558 HostResolver* host_resolver, | 573 HostResolver* host_resolver, |
| 559 ClientSocketFactory* client_socket_factory, | 574 ClientSocketFactory* client_socket_factory, |
| 560 base::WeakPtr<HttpServerProperties> http_server_properties, | 575 base::WeakPtr<HttpServerProperties> http_server_properties, |
| 561 CertVerifier* cert_verifier, | 576 CertVerifier* cert_verifier, |
| 562 CTPolicyEnforcer* ct_policy_enforcer, | 577 CTPolicyEnforcer* ct_policy_enforcer, |
| 563 ChannelIDService* channel_id_service, | 578 ChannelIDService* channel_id_service, |
| 564 TransportSecurityState* transport_security_state, | 579 TransportSecurityState* transport_security_state, |
| 565 CTVerifier* cert_transparency_verifier, | 580 CTVerifier* cert_transparency_verifier, |
| 566 SocketPerformanceWatcherFactory* socket_performance_watcher_factory, | 581 SocketPerformanceWatcherFactory* socket_performance_watcher_factory, |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 const BoundNetLog& net_log, | 788 const BoundNetLog& net_log, |
| 774 QuicStreamRequest* request) { | 789 QuicStreamRequest* request) { |
| 775 // Enforce session affinity for promised streams. | 790 // Enforce session affinity for promised streams. |
| 776 QuicClientPromisedInfo* promised = | 791 QuicClientPromisedInfo* promised = |
| 777 push_promise_index_.GetPromised(url.spec()); | 792 push_promise_index_.GetPromised(url.spec()); |
| 778 if (promised) { | 793 if (promised) { |
| 779 QuicChromiumClientSession* session = | 794 QuicChromiumClientSession* session = |
| 780 static_cast<QuicChromiumClientSession*>(promised->session()); | 795 static_cast<QuicChromiumClientSession*>(promised->session()); |
| 781 DCHECK(session); | 796 DCHECK(session); |
| 782 if (session->server_id().privacy_mode() == privacy_mode) { | 797 if (session->server_id().privacy_mode() == privacy_mode) { |
| 783 request->set_stream(CreateFromSession(session)); | 798 request->SetSession(session); |
| 784 ++num_push_streams_created_; | 799 ++num_push_streams_created_; |
| 785 return OK; | 800 return OK; |
| 786 } | 801 } |
| 787 // This should happen extremely rarely (if ever), but if somehow a | 802 // This should happen extremely rarely (if ever), but if somehow a |
| 788 // request comes in with a mismatched privacy mode, consider the | 803 // request comes in with a mismatched privacy mode, consider the |
| 789 // promise borked. | 804 // promise borked. |
| 790 promised->Cancel(); | 805 promised->Cancel(); |
| 791 } | 806 } |
| 792 | 807 |
| 793 QuicServerId server_id(host_port_pair, privacy_mode); | 808 QuicServerId server_id(host_port_pair, privacy_mode); |
| 794 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() checks. | 809 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() checks. |
| 795 if (!active_sessions_.empty()) { | 810 if (!active_sessions_.empty()) { |
| 796 SessionMap::iterator it = active_sessions_.find(server_id); | 811 SessionMap::iterator it = active_sessions_.find(server_id); |
| 797 if (it != active_sessions_.end()) { | 812 if (it != active_sessions_.end()) { |
| 798 QuicChromiumClientSession* session = it->second; | 813 QuicChromiumClientSession* session = it->second; |
| 799 if (!session->CanPool(url.host(), privacy_mode)) | 814 if (!session->CanPool(url.host(), privacy_mode)) |
| 800 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; | 815 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; |
| 801 request->set_stream(CreateFromSession(session)); | 816 request->SetSession(session); |
| 802 return OK; | 817 return OK; |
| 803 } | 818 } |
| 804 } | 819 } |
| 805 | 820 |
| 806 if (HasActiveJob(server_id)) { | 821 if (HasActiveJob(server_id)) { |
| 807 active_requests_[request] = server_id; | 822 active_requests_[request] = server_id; |
| 808 job_requests_map_[server_id].insert(request); | 823 job_requests_map_[server_id].insert(request); |
| 809 return ERR_IO_PENDING; | 824 return ERR_IO_PENDING; |
| 810 } | 825 } |
| 811 | 826 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 // related changes. | 862 // related changes. |
| 848 if (active_sessions_.empty()) | 863 if (active_sessions_.empty()) |
| 849 return ERR_QUIC_PROTOCOL_ERROR; | 864 return ERR_QUIC_PROTOCOL_ERROR; |
| 850 SessionMap::iterator it = active_sessions_.find(server_id); | 865 SessionMap::iterator it = active_sessions_.find(server_id); |
| 851 DCHECK(it != active_sessions_.end()); | 866 DCHECK(it != active_sessions_.end()); |
| 852 if (it == active_sessions_.end()) | 867 if (it == active_sessions_.end()) |
| 853 return ERR_QUIC_PROTOCOL_ERROR; | 868 return ERR_QUIC_PROTOCOL_ERROR; |
| 854 QuicChromiumClientSession* session = it->second; | 869 QuicChromiumClientSession* session = it->second; |
| 855 if (!session->CanPool(url.host(), privacy_mode)) | 870 if (!session->CanPool(url.host(), privacy_mode)) |
| 856 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; | 871 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; |
| 857 request->set_stream(CreateFromSession(session)); | 872 request->SetSession(session); |
| 858 } | 873 } |
| 859 return rv; | 874 return rv; |
| 860 } | 875 } |
| 861 | 876 |
| 862 void QuicStreamFactory::CreateAuxilaryJob(const QuicServerId server_id, | 877 void QuicStreamFactory::CreateAuxilaryJob(const QuicServerId server_id, |
| 863 int cert_verify_flags, | 878 int cert_verify_flags, |
| 864 bool server_and_origin_have_same_host, | 879 bool server_and_origin_have_same_host, |
| 865 bool is_post, | 880 bool is_post, |
| 866 const BoundNetLog& net_log) { | 881 const BoundNetLog& net_log) { |
| 867 Job* aux_job = new Job( | 882 Job* aux_job = new Job( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 RequestSet::iterator old_request_it = request_it; | 940 RequestSet::iterator old_request_it = request_it; |
| 926 ++request_it; | 941 ++request_it; |
| 927 // Remove request from containers so that OnRequestComplete() is not | 942 // Remove request from containers so that OnRequestComplete() is not |
| 928 // called later again on the same request. | 943 // called later again on the same request. |
| 929 job_requests_map_[server_id].erase(old_request_it); | 944 job_requests_map_[server_id].erase(old_request_it); |
| 930 active_requests_.erase(request); | 945 active_requests_.erase(request); |
| 931 // Notify request of certificate error. | 946 // Notify request of certificate error. |
| 932 request->OnRequestComplete(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN); | 947 request->OnRequestComplete(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN); |
| 933 continue; | 948 continue; |
| 934 } | 949 } |
| 935 request->set_stream(CreateFromSession(session)); | 950 request->SetSession(session); |
| 936 ++request_it; | 951 ++request_it; |
| 937 } | 952 } |
| 938 } | 953 } |
| 939 | 954 |
| 940 while (!job_requests_map_[server_id].empty()) { | 955 while (!job_requests_map_[server_id].empty()) { |
| 941 RequestSet::iterator it = job_requests_map_[server_id].begin(); | 956 RequestSet::iterator it = job_requests_map_[server_id].begin(); |
| 942 QuicStreamRequest* request = *it; | 957 QuicStreamRequest* request = *it; |
| 943 job_requests_map_[server_id].erase(it); | 958 job_requests_map_[server_id].erase(it); |
| 944 active_requests_.erase(request); | 959 active_requests_.erase(request); |
| 945 // Even though we're invoking callbacks here, we don't need to worry | 960 // Even though we're invoking callbacks here, we don't need to worry |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1736 // Since the session was active, there's no longer an | 1751 // Since the session was active, there's no longer an |
| 1737 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP | 1752 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP |
| 1738 // job also fails. So to avoid not using QUIC when we otherwise could, we mark | 1753 // job also fails. So to avoid not using QUIC when we otherwise could, we mark |
| 1739 // it as recently broken, which means that 0-RTT will be disabled but we'll | 1754 // it as recently broken, which means that 0-RTT will be disabled but we'll |
| 1740 // still race. | 1755 // still race. |
| 1741 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 1756 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
| 1742 alternative_service); | 1757 alternative_service); |
| 1743 } | 1758 } |
| 1744 | 1759 |
| 1745 } // namespace net | 1760 } // namespace net |
| OLD | NEW |