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

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

Issue 1692253004: QUIC - chromium server push support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review feedback round 1 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 20 matching lines...) Expand all
31 #include "net/quic/crypto/channel_id_chromium.h" 31 #include "net/quic/crypto/channel_id_chromium.h"
32 #include "net/quic/crypto/proof_verifier_chromium.h" 32 #include "net/quic/crypto/proof_verifier_chromium.h"
33 #include "net/quic/crypto/properties_based_quic_server_info.h" 33 #include "net/quic/crypto/properties_based_quic_server_info.h"
34 #include "net/quic/crypto/quic_random.h" 34 #include "net/quic/crypto/quic_random.h"
35 #include "net/quic/crypto/quic_server_info.h" 35 #include "net/quic/crypto/quic_server_info.h"
36 #include "net/quic/port_suggester.h" 36 #include "net/quic/port_suggester.h"
37 #include "net/quic/quic_chromium_client_session.h" 37 #include "net/quic/quic_chromium_client_session.h"
38 #include "net/quic/quic_chromium_connection_helper.h" 38 #include "net/quic/quic_chromium_connection_helper.h"
39 #include "net/quic/quic_chromium_packet_reader.h" 39 #include "net/quic/quic_chromium_packet_reader.h"
40 #include "net/quic/quic_chromium_packet_writer.h" 40 #include "net/quic/quic_chromium_packet_writer.h"
41 #include "net/quic/quic_client_promised_info.h"
41 #include "net/quic/quic_clock.h" 42 #include "net/quic/quic_clock.h"
42 #include "net/quic/quic_connection.h" 43 #include "net/quic/quic_connection.h"
43 #include "net/quic/quic_crypto_client_stream_factory.h" 44 #include "net/quic/quic_crypto_client_stream_factory.h"
44 #include "net/quic/quic_flags.h" 45 #include "net/quic/quic_flags.h"
45 #include "net/quic/quic_http_stream.h" 46 #include "net/quic/quic_http_stream.h"
46 #include "net/quic/quic_protocol.h" 47 #include "net/quic/quic_protocol.h"
47 #include "net/quic/quic_server_id.h" 48 #include "net/quic/quic_server_id.h"
48 #include "net/socket/client_socket_factory.h" 49 #include "net/socket/client_socket_factory.h"
49 #include "net/udp/udp_client_socket.h" 50 #include "net/udp/udp_client_socket.h"
50 51
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 : factory_(factory) {} 500 : factory_(factory) {}
500 501
501 QuicStreamRequest::~QuicStreamRequest() { 502 QuicStreamRequest::~QuicStreamRequest() {
502 if (factory_ && !callback_.is_null()) 503 if (factory_ && !callback_.is_null())
503 factory_->CancelRequest(this); 504 factory_->CancelRequest(this);
504 } 505 }
505 506
506 int QuicStreamRequest::Request(const HostPortPair& host_port_pair, 507 int QuicStreamRequest::Request(const HostPortPair& host_port_pair,
507 PrivacyMode privacy_mode, 508 PrivacyMode privacy_mode,
508 int cert_verify_flags, 509 int cert_verify_flags,
509 base::StringPiece origin_host, 510 const GURL& url,
510 base::StringPiece method, 511 base::StringPiece method,
511 const BoundNetLog& net_log, 512 const BoundNetLog& net_log,
512 const CompletionCallback& callback) { 513 const CompletionCallback& callback) {
513 DCHECK(!stream_); 514 DCHECK(!stream_);
514 DCHECK(callback_.is_null()); 515 DCHECK(callback_.is_null());
515 DCHECK(factory_); 516 DCHECK(factory_);
516 origin_host_ = origin_host.as_string(); 517 origin_host_ = url.host();
517 privacy_mode_ = privacy_mode; 518 privacy_mode_ = privacy_mode;
518 int rv = factory_->Create(host_port_pair, privacy_mode, cert_verify_flags, 519 int rv = factory_->Create(host_port_pair, privacy_mode, cert_verify_flags,
519 origin_host, method, net_log, this); 520 url, method, net_log, this);
520 if (rv == ERR_IO_PENDING) { 521 if (rv == ERR_IO_PENDING) {
521 host_port_pair_ = host_port_pair; 522 host_port_pair_ = host_port_pair;
522 net_log_ = net_log; 523 net_log_ = net_log;
523 callback_ = callback; 524 callback_ = callback;
524 } else { 525 } else {
525 factory_ = nullptr; 526 factory_ = nullptr;
526 } 527 }
527 if (rv == OK) 528 if (rv == OK)
528 DCHECK(stream_); 529 DCHECK(stream_);
529 return rv; 530 return rv;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 kQuicYieldAfterDurationMilliseconds)), 636 kQuicYieldAfterDurationMilliseconds)),
636 close_sessions_on_ip_change_(close_sessions_on_ip_change), 637 close_sessions_on_ip_change_(close_sessions_on_ip_change),
637 migrate_sessions_on_network_change_( 638 migrate_sessions_on_network_change_(
638 migrate_sessions_on_network_change && 639 migrate_sessions_on_network_change &&
639 NetworkChangeNotifier::AreNetworkHandlesSupported()), 640 NetworkChangeNotifier::AreNetworkHandlesSupported()),
640 migrate_sessions_early_(migrate_sessions_early && 641 migrate_sessions_early_(migrate_sessions_early &&
641 migrate_sessions_on_network_change_), 642 migrate_sessions_on_network_change_),
642 port_seed_(random_generator_->RandUint64()), 643 port_seed_(random_generator_->RandUint64()),
643 check_persisted_supports_quic_(true), 644 check_persisted_supports_quic_(true),
644 has_initialized_data_(false), 645 has_initialized_data_(false),
646 num_push_streams_created_(0),
645 task_runner_(nullptr), 647 task_runner_(nullptr),
646 weak_factory_(this) { 648 weak_factory_(this) {
647 if (disable_quic_on_timeout_with_open_streams) 649 if (disable_quic_on_timeout_with_open_streams)
648 threshold_timeouts_with_open_streams_ = 1; 650 threshold_timeouts_with_open_streams_ = 1;
649 DCHECK(transport_security_state_); 651 DCHECK(transport_security_state_);
650 DCHECK(http_server_properties_); 652 DCHECK(http_server_properties_);
651 crypto_config_.set_user_agent_id(user_agent_id); 653 crypto_config_.set_user_agent_id(user_agent_id);
652 crypto_config_.AddCanonicalSuffix(".c.youtube.com"); 654 crypto_config_.AddCanonicalSuffix(".c.youtube.com");
653 crypto_config_.AddCanonicalSuffix(".googlevideo.com"); 655 crypto_config_.AddCanonicalSuffix(".googlevideo.com");
654 crypto_config_.AddCanonicalSuffix(".googleusercontent.com"); 656 crypto_config_.AddCanonicalSuffix(".googleusercontent.com");
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 SessionMap::iterator it = active_sessions_.find(server_id); 755 SessionMap::iterator it = active_sessions_.find(server_id);
754 if (it == active_sessions_.end()) 756 if (it == active_sessions_.end())
755 return false; 757 return false;
756 QuicChromiumClientSession* session = it->second; 758 QuicChromiumClientSession* session = it->second;
757 return session->CanPool(origin_host.as_string(), privacy_mode); 759 return session->CanPool(origin_host.as_string(), privacy_mode);
758 } 760 }
759 761
760 int QuicStreamFactory::Create(const HostPortPair& host_port_pair, 762 int QuicStreamFactory::Create(const HostPortPair& host_port_pair,
761 PrivacyMode privacy_mode, 763 PrivacyMode privacy_mode,
762 int cert_verify_flags, 764 int cert_verify_flags,
763 base::StringPiece origin_host, 765 const GURL& url,
764 base::StringPiece method, 766 base::StringPiece method,
765 const BoundNetLog& net_log, 767 const BoundNetLog& net_log,
766 QuicStreamRequest* request) { 768 QuicStreamRequest* request) {
769 // Enforce session affinity for promised streams.
770 QuicClientPromisedInfo* promised =
771 push_promise_index_.GetPromised(url.spec());
772 if (promised) {
773 QuicChromiumClientSession* session =
774 static_cast<QuicChromiumClientSession*>(promised->session());
775 DCHECK(session);
776 if (session->server_id().privacy_mode() == privacy_mode) {
777 request->set_stream(CreateFromSession(session));
778 ++num_push_streams_created_;
779 return OK;
780 }
781 // This should happen extremely rarely (if ever), but if somehow a
782 // request comes in with a mismatched privacy mode, consider the
783 // promise borked.
784 promised->Cancel();
785 }
786
767 QuicServerId server_id(host_port_pair, privacy_mode); 787 QuicServerId server_id(host_port_pair, privacy_mode);
768 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() checks. 788 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() checks.
769 if (!active_sessions_.empty()) { 789 if (!active_sessions_.empty()) {
770 SessionMap::iterator it = active_sessions_.find(server_id); 790 SessionMap::iterator it = active_sessions_.find(server_id);
771 if (it != active_sessions_.end()) { 791 if (it != active_sessions_.end()) {
772 QuicChromiumClientSession* session = it->second; 792 QuicChromiumClientSession* session = it->second;
773 if (!session->CanPool(origin_host.as_string(), privacy_mode)) 793 if (!session->CanPool(url.host(), privacy_mode))
774 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; 794 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN;
775 request->set_stream(CreateFromSession(session)); 795 request->set_stream(CreateFromSession(session));
776 return OK; 796 return OK;
777 } 797 }
778 } 798 }
779 799
780 if (HasActiveJob(server_id)) { 800 if (HasActiveJob(server_id)) {
781 active_requests_[request] = server_id; 801 active_requests_[request] = server_id;
782 job_requests_map_[server_id].insert(request); 802 job_requests_map_[server_id].insert(request);
783 return ERR_IO_PENDING; 803 return ERR_IO_PENDING;
(...skipping 12 matching lines...) Expand all
796 server_id.host_port_pair())) { 816 server_id.host_port_pair())) {
797 // If there is no entry for QUIC, consider that as a new server and 817 // If there is no entry for QUIC, consider that as a new server and
798 // don't wait for Cache thread to load the data for that server. 818 // don't wait for Cache thread to load the data for that server.
799 load_from_disk_cache = false; 819 load_from_disk_cache = false;
800 } 820 }
801 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) { 821 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) {
802 quic_server_info = quic_server_info_factory_->GetForServer(server_id); 822 quic_server_info = quic_server_info_factory_->GetForServer(server_id);
803 } 823 }
804 } 824 }
805 825
806 bool server_and_origin_have_same_host = host_port_pair.host() == origin_host; 826 bool server_and_origin_have_same_host = host_port_pair.host() == url.host();
807 scoped_ptr<Job> job(new Job( 827 scoped_ptr<Job> job(new Job(
808 this, host_resolver_, host_port_pair, server_and_origin_have_same_host, 828 this, host_resolver_, host_port_pair, server_and_origin_have_same_host,
809 WasQuicRecentlyBroken(server_id), privacy_mode, cert_verify_flags, 829 WasQuicRecentlyBroken(server_id), privacy_mode, cert_verify_flags,
810 method == "POST" /* is_post */, quic_server_info, net_log)); 830 method == "POST" /* is_post */, quic_server_info, net_log));
811 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, 831 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete,
812 base::Unretained(this), job.get())); 832 base::Unretained(this), job.get()));
813 if (rv == ERR_IO_PENDING) { 833 if (rv == ERR_IO_PENDING) {
814 active_requests_[request] = server_id; 834 active_requests_[request] = server_id;
815 job_requests_map_[server_id].insert(request); 835 job_requests_map_[server_id].insert(request);
816 active_jobs_[server_id].insert(job.release()); 836 active_jobs_[server_id].insert(job.release());
817 return rv; 837 return rv;
818 } 838 }
819 if (rv == OK) { 839 if (rv == OK) {
820 // TODO(rtenneti): crbug.com/498823 - revert active_sessions_.empty() 840 // TODO(rtenneti): crbug.com/498823 - revert active_sessions_.empty()
821 // related changes. 841 // related changes.
822 if (active_sessions_.empty()) 842 if (active_sessions_.empty())
823 return ERR_QUIC_PROTOCOL_ERROR; 843 return ERR_QUIC_PROTOCOL_ERROR;
824 SessionMap::iterator it = active_sessions_.find(server_id); 844 SessionMap::iterator it = active_sessions_.find(server_id);
825 DCHECK(it != active_sessions_.end()); 845 DCHECK(it != active_sessions_.end());
826 if (it == active_sessions_.end()) 846 if (it == active_sessions_.end())
827 return ERR_QUIC_PROTOCOL_ERROR; 847 return ERR_QUIC_PROTOCOL_ERROR;
828 QuicChromiumClientSession* session = it->second; 848 QuicChromiumClientSession* session = it->second;
829 if (!session->CanPool(origin_host.as_string(), privacy_mode)) 849 if (!session->CanPool(url.host(), privacy_mode))
830 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; 850 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN;
831 request->set_stream(CreateFromSession(session)); 851 request->set_stream(CreateFromSession(session));
832 } 852 }
833 return rv; 853 return rv;
834 } 854 }
835 855
836 void QuicStreamFactory::CreateAuxilaryJob(const QuicServerId server_id, 856 void QuicStreamFactory::CreateAuxilaryJob(const QuicServerId server_id,
837 int cert_verify_flags, 857 int cert_verify_flags,
838 bool server_and_origin_have_same_host, 858 bool server_and_origin_have_same_host,
839 bool is_post, 859 bool is_post,
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after
1645 // Since the session was active, there's no longer an 1665 // Since the session was active, there's no longer an
1646 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP 1666 // 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 1667 // 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 1668 // it as recently broken, which means that 0-RTT will be disabled but we'll
1649 // still race. 1669 // still race.
1650 http_server_properties_->MarkAlternativeServiceRecentlyBroken( 1670 http_server_properties_->MarkAlternativeServiceRecentlyBroken(
1651 alternative_service); 1671 alternative_service);
1652 } 1672 }
1653 1673
1654 } // namespace net 1674 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698