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

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

Issue 1744693002: Implement QUIC-based net::BidirectionalStream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@basecl
Patch Set: Address Ryan's comments Created 4 years, 9 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/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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "base/win/windows_version.h" 52 #include "base/win/windows_version.h"
53 #endif 53 #endif
54 54
55 #if defined(USE_OPENSSL) 55 #if defined(USE_OPENSSL)
56 #include <openssl/aead.h> 56 #include <openssl/aead.h>
57 #include "crypto/openssl_util.h" 57 #include "crypto/openssl_util.h"
58 #else 58 #else
59 #include "base/cpu.h" 59 #include "base/cpu.h"
60 #endif 60 #endif
61 61
62 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM)
63 #include "net/http/bidirectional_stream_job.h"
64 #include "net/quic/bidirectional_stream_quic_impl.h"
65 #endif
66
62 using std::min; 67 using std::min;
63 using NetworkHandle = net::NetworkChangeNotifier::NetworkHandle; 68 using NetworkHandle = net::NetworkChangeNotifier::NetworkHandle;
64 69
65 namespace net { 70 namespace net {
66 71
67 namespace { 72 namespace {
68 73
69 enum CreateSessionFailure { 74 enum CreateSessionFailure {
70 CREATION_ERROR_CONNECTING_SOCKET, 75 CREATION_ERROR_CONNECTING_SOCKET,
71 CREATION_ERROR_SETTING_RECEIVE_BUFFER, 76 CREATION_ERROR_SETTING_RECEIVE_BUFFER,
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 session_ = nullptr; 494 session_ = nullptr;
490 return OK; 495 return OK;
491 } 496 }
492 497
493 factory_->ActivateSession(server_id_, session_); 498 factory_->ActivateSession(server_id_, session_);
494 499
495 return OK; 500 return OK;
496 } 501 }
497 502
498 QuicStreamRequest::QuicStreamRequest(QuicStreamFactory* factory) 503 QuicStreamRequest::QuicStreamRequest(QuicStreamFactory* factory)
499 : factory_(factory) {} 504 : factory_(factory), for_bidirectional_(false) {}
500 505
501 QuicStreamRequest::~QuicStreamRequest() { 506 QuicStreamRequest::~QuicStreamRequest() {
502 if (factory_ && !callback_.is_null()) 507 if (factory_ && !callback_.is_null())
503 factory_->CancelRequest(this); 508 factory_->CancelRequest(this);
504 } 509 }
505 510
506 int QuicStreamRequest::Request(const HostPortPair& host_port_pair, 511 int QuicStreamRequest::Request(const HostPortPair& host_port_pair,
507 PrivacyMode privacy_mode, 512 PrivacyMode privacy_mode,
508 int cert_verify_flags, 513 int cert_verify_flags,
509 base::StringPiece origin_host, 514 base::StringPiece origin_host,
510 base::StringPiece method, 515 base::StringPiece method,
511 const BoundNetLog& net_log, 516 const BoundNetLog& net_log,
512 const CompletionCallback& callback) { 517 const CompletionCallback& callback,
518 bool for_bidirectional) {
513 DCHECK(!stream_); 519 DCHECK(!stream_);
520 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM)
521 DCHECK(!bidirectional_stream_job_);
522 #endif
514 DCHECK(callback_.is_null()); 523 DCHECK(callback_.is_null());
515 DCHECK(factory_); 524 DCHECK(factory_);
516 origin_host_ = origin_host.as_string(); 525 origin_host_ = origin_host.as_string();
517 privacy_mode_ = privacy_mode; 526 privacy_mode_ = privacy_mode;
527 for_bidirectional_ = for_bidirectional;
528
518 int rv = factory_->Create(host_port_pair, privacy_mode, cert_verify_flags, 529 int rv = factory_->Create(host_port_pair, privacy_mode, cert_verify_flags,
519 origin_host, method, net_log, this); 530 origin_host, method, net_log, this);
520 if (rv == ERR_IO_PENDING) { 531 if (rv == ERR_IO_PENDING) {
521 host_port_pair_ = host_port_pair; 532 host_port_pair_ = host_port_pair;
522 net_log_ = net_log; 533 net_log_ = net_log;
523 callback_ = callback; 534 callback_ = callback;
524 } else { 535 } else {
525 factory_ = nullptr; 536 factory_ = nullptr;
526 } 537 }
527 if (rv == OK) 538 if (rv == OK) {
539 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM)
540 DCHECK(stream_ || (for_bidirectional_ && bidirectional_stream_job_));
541 #else
528 DCHECK(stream_); 542 DCHECK(stream_);
543 #endif
544 }
529 return rv; 545 return rv;
530 } 546 }
531 547
532 void QuicStreamRequest::set_stream(scoped_ptr<QuicHttpStream> stream) { 548 void QuicStreamRequest::InitializeStreamFromSession(
533 DCHECK(stream); 549 QuicChromiumClientSession* session) {
534 stream_ = std::move(stream); 550 DCHECK(session);
551 if (for_bidirectional_) {
552 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM)
553 bidirectional_stream_job_.reset(
554 new BidirectionalStreamQuicImpl(session->GetWeakPtr()));
555 #else
556 DCHECK(false);
557 #endif
558 } else {
559 stream_.reset(new QuicHttpStream(session->GetWeakPtr()));
560 }
535 } 561 }
536 562
537 void QuicStreamRequest::OnRequestComplete(int rv) { 563 void QuicStreamRequest::OnRequestComplete(int rv) {
538 factory_ = nullptr; 564 factory_ = nullptr;
539 callback_.Run(rv); 565 callback_.Run(rv);
540 } 566 }
541 567
542 base::TimeDelta QuicStreamRequest::GetTimeDelayForWaitingJob() const { 568 base::TimeDelta QuicStreamRequest::GetTimeDelayForWaitingJob() const {
543 if (!factory_) 569 if (!factory_)
544 return base::TimeDelta(); 570 return base::TimeDelta();
545 return factory_->GetTimeDelayForWaitingJob( 571 return factory_->GetTimeDelayForWaitingJob(
546 QuicServerId(host_port_pair_, privacy_mode_)); 572 QuicServerId(host_port_pair_, privacy_mode_));
547 } 573 }
548 574
549 scoped_ptr<QuicHttpStream> QuicStreamRequest::ReleaseStream() { 575 scoped_ptr<QuicHttpStream> QuicStreamRequest::ReleaseStream() {
550 DCHECK(stream_); 576 DCHECK(stream_);
577 DCHECK(!for_bidirectional_);
551 return std::move(stream_); 578 return std::move(stream_);
552 } 579 }
553 580
581 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM)
582 scoped_ptr<BidirectionalStreamJob>
583 QuicStreamRequest::ReleaseBidirectionalStreamJob() {
584 DCHECK(bidirectional_stream_job_);
585 DCHECK(for_bidirectional_);
586
587 return std::move(bidirectional_stream_job_);
588 }
589 #endif
590
554 QuicStreamFactory::QuicStreamFactory( 591 QuicStreamFactory::QuicStreamFactory(
555 HostResolver* host_resolver, 592 HostResolver* host_resolver,
556 ClientSocketFactory* client_socket_factory, 593 ClientSocketFactory* client_socket_factory,
557 base::WeakPtr<HttpServerProperties> http_server_properties, 594 base::WeakPtr<HttpServerProperties> http_server_properties,
558 CertVerifier* cert_verifier, 595 CertVerifier* cert_verifier,
559 CTPolicyEnforcer* ct_policy_enforcer, 596 CTPolicyEnforcer* ct_policy_enforcer,
560 ChannelIDService* channel_id_service, 597 ChannelIDService* channel_id_service,
561 TransportSecurityState* transport_security_state, 598 TransportSecurityState* transport_security_state,
562 CTVerifier* cert_transparency_verifier, 599 CTVerifier* cert_transparency_verifier,
563 SocketPerformanceWatcherFactory* socket_performance_watcher_factory, 600 SocketPerformanceWatcherFactory* socket_performance_watcher_factory,
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 const BoundNetLog& net_log, 802 const BoundNetLog& net_log,
766 QuicStreamRequest* request) { 803 QuicStreamRequest* request) {
767 QuicServerId server_id(host_port_pair, privacy_mode); 804 QuicServerId server_id(host_port_pair, privacy_mode);
768 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() checks. 805 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() checks.
769 if (!active_sessions_.empty()) { 806 if (!active_sessions_.empty()) {
770 SessionMap::iterator it = active_sessions_.find(server_id); 807 SessionMap::iterator it = active_sessions_.find(server_id);
771 if (it != active_sessions_.end()) { 808 if (it != active_sessions_.end()) {
772 QuicChromiumClientSession* session = it->second; 809 QuicChromiumClientSession* session = it->second;
773 if (!session->CanPool(origin_host.as_string(), privacy_mode)) 810 if (!session->CanPool(origin_host.as_string(), privacy_mode))
774 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; 811 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN;
775 request->set_stream(CreateFromSession(session)); 812 request->InitializeStreamFromSession(session);
776 return OK; 813 return OK;
777 } 814 }
778 } 815 }
779 816
780 if (HasActiveJob(server_id)) { 817 if (HasActiveJob(server_id)) {
781 active_requests_[request] = server_id; 818 active_requests_[request] = server_id;
782 job_requests_map_[server_id].insert(request); 819 job_requests_map_[server_id].insert(request);
783 return ERR_IO_PENDING; 820 return ERR_IO_PENDING;
784 } 821 }
785 822
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 // related changes. 858 // related changes.
822 if (active_sessions_.empty()) 859 if (active_sessions_.empty())
823 return ERR_QUIC_PROTOCOL_ERROR; 860 return ERR_QUIC_PROTOCOL_ERROR;
824 SessionMap::iterator it = active_sessions_.find(server_id); 861 SessionMap::iterator it = active_sessions_.find(server_id);
825 DCHECK(it != active_sessions_.end()); 862 DCHECK(it != active_sessions_.end());
826 if (it == active_sessions_.end()) 863 if (it == active_sessions_.end())
827 return ERR_QUIC_PROTOCOL_ERROR; 864 return ERR_QUIC_PROTOCOL_ERROR;
828 QuicChromiumClientSession* session = it->second; 865 QuicChromiumClientSession* session = it->second;
829 if (!session->CanPool(origin_host.as_string(), privacy_mode)) 866 if (!session->CanPool(origin_host.as_string(), privacy_mode))
830 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; 867 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN;
831 request->set_stream(CreateFromSession(session)); 868 request->InitializeStreamFromSession(session);
832 } 869 }
833 return rv; 870 return rv;
834 } 871 }
835 872
836 void QuicStreamFactory::CreateAuxilaryJob(const QuicServerId server_id, 873 void QuicStreamFactory::CreateAuxilaryJob(const QuicServerId server_id,
837 int cert_verify_flags, 874 int cert_verify_flags,
838 bool server_and_origin_have_same_host, 875 bool server_and_origin_have_same_host,
839 bool is_post, 876 bool is_post,
840 const BoundNetLog& net_log) { 877 const BoundNetLog& net_log) {
841 Job* aux_job = new Job( 878 Job* aux_job = new Job(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 RequestSet::iterator old_request_it = request_it; 936 RequestSet::iterator old_request_it = request_it;
900 ++request_it; 937 ++request_it;
901 // Remove request from containers so that OnRequestComplete() is not 938 // Remove request from containers so that OnRequestComplete() is not
902 // called later again on the same request. 939 // called later again on the same request.
903 job_requests_map_[server_id].erase(old_request_it); 940 job_requests_map_[server_id].erase(old_request_it);
904 active_requests_.erase(request); 941 active_requests_.erase(request);
905 // Notify request of certificate error. 942 // Notify request of certificate error.
906 request->OnRequestComplete(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN); 943 request->OnRequestComplete(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN);
907 continue; 944 continue;
908 } 945 }
909 request->set_stream(CreateFromSession(session)); 946 request->InitializeStreamFromSession(session);
910 ++request_it; 947 ++request_it;
911 } 948 }
912 } 949 }
913 950
914 while (!job_requests_map_[server_id].empty()) { 951 while (!job_requests_map_[server_id].empty()) {
915 RequestSet::iterator it = job_requests_map_[server_id].begin(); 952 RequestSet::iterator it = job_requests_map_[server_id].begin();
916 QuicStreamRequest* request = *it; 953 QuicStreamRequest* request = *it;
917 job_requests_map_[server_id].erase(it); 954 job_requests_map_[server_id].erase(it);
918 active_requests_.erase(request); 955 active_requests_.erase(request);
919 // Even though we're invoking callbacks here, we don't need to worry 956 // Even though we're invoking callbacks here, we don't need to worry
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
1645 // Since the session was active, there's no longer an 1682 // Since the session was active, there's no longer an
1646 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP 1683 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP
1647 // job also fails. So to avoid not using QUIC when we otherwise could, we mark 1684 // job also fails. So to avoid not using QUIC when we otherwise could, we mark
1648 // it as recently broken, which means that 0-RTT will be disabled but we'll 1685 // it as recently broken, which means that 0-RTT will be disabled but we'll
1649 // still race. 1686 // still race.
1650 http_server_properties_->MarkAlternativeServiceRecentlyBroken( 1687 http_server_properties_->MarkAlternativeServiceRecentlyBroken(
1651 alternative_service); 1688 alternative_service);
1652 } 1689 }
1653 1690
1654 } // namespace net 1691 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698