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