Chromium Code Reviews| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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_job.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 Loading... | |
| 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 | |
| 506 int QuicStreamRequest::Request(const HostPortPair& host_port_pair, | 510 int QuicStreamRequest::Request(const HostPortPair& host_port_pair, |
| 507 PrivacyMode privacy_mode, | 511 PrivacyMode privacy_mode, |
| 508 int cert_verify_flags, | 512 int cert_verify_flags, |
| 509 base::StringPiece origin_host, | 513 base::StringPiece origin_host, |
| 510 base::StringPiece method, | 514 base::StringPiece method, |
| 511 const BoundNetLog& net_log, | 515 const BoundNetLog& net_log, |
| 512 const CompletionCallback& callback) { | 516 const CompletionCallback& callback) { |
| 517 return Request(host_port_pair, privacy_mode, cert_verify_flags, origin_host, | |
| 518 method, net_log, callback, false); | |
| 519 } | |
| 520 | |
| 521 int QuicStreamRequest::Request(const HostPortPair& host_port_pair, | |
| 522 PrivacyMode privacy_mode, | |
| 523 int cert_verify_flags, | |
| 524 base::StringPiece origin_host, | |
| 525 base::StringPiece method, | |
| 526 const BoundNetLog& net_log, | |
| 527 const CompletionCallback& callback, | |
| 528 bool for_bidirectional) { | |
| 513 DCHECK(!stream_); | 529 DCHECK(!stream_); |
| 530 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) | |
| 531 DCHECK(!bidirectional_stream_job_); | |
| 532 #endif | |
| 514 DCHECK(callback_.is_null()); | 533 DCHECK(callback_.is_null()); |
| 515 DCHECK(factory_); | 534 DCHECK(factory_); |
| 516 origin_host_ = origin_host.as_string(); | 535 origin_host_ = origin_host.as_string(); |
| 517 privacy_mode_ = privacy_mode; | 536 privacy_mode_ = privacy_mode; |
| 537 for_bidirectional_ = for_bidirectional; | |
| 538 | |
| 518 int rv = factory_->Create(host_port_pair, privacy_mode, cert_verify_flags, | 539 int rv = factory_->Create(host_port_pair, privacy_mode, cert_verify_flags, |
| 519 origin_host, method, net_log, this); | 540 origin_host, method, net_log, this); |
| 520 if (rv == ERR_IO_PENDING) { | 541 if (rv == ERR_IO_PENDING) { |
| 521 host_port_pair_ = host_port_pair; | 542 host_port_pair_ = host_port_pair; |
| 522 net_log_ = net_log; | 543 net_log_ = net_log; |
| 523 callback_ = callback; | 544 callback_ = callback; |
| 524 } else { | 545 } else { |
| 525 factory_ = nullptr; | 546 factory_ = nullptr; |
| 526 } | 547 } |
| 527 if (rv == OK) | 548 if (rv == OK) { |
| 549 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) | |
| 550 DCHECK(stream_ || (for_bidirectional_ && bidirectional_stream_job_)); | |
| 551 #else | |
| 528 DCHECK(stream_); | 552 DCHECK(stream_); |
| 553 #endif | |
| 554 } | |
| 529 return rv; | 555 return rv; |
| 530 } | 556 } |
| 531 | 557 |
| 532 void QuicStreamRequest::set_stream(scoped_ptr<QuicHttpStream> stream) { | 558 void QuicStreamRequest::InitializeStreamFromSession( |
| 533 DCHECK(stream); | 559 QuicChromiumClientSession* session) { |
| 534 stream_ = std::move(stream); | 560 DCHECK(session); |
| 561 if (for_bidirectional_) { | |
| 562 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) | |
| 563 bidirectional_stream_job_.reset( | |
| 564 new BidirectionalStreamQuicJob(session->GetWeakPtr())); | |
| 565 #else | |
| 566 DCHECK(false); | |
| 567 #endif | |
|
Ryan Hamilton
2016/02/27 00:21:14
I find this maze of ifdefs exceptionally hard to r
xunjieli
2016/02/29 15:21:37
Acknowledged.
| |
| 568 } else { | |
| 569 stream_.reset(new QuicHttpStream(session->GetWeakPtr())); | |
| 570 } | |
| 535 } | 571 } |
| 536 | 572 |
| 537 void QuicStreamRequest::OnRequestComplete(int rv) { | 573 void QuicStreamRequest::OnRequestComplete(int rv) { |
| 538 factory_ = nullptr; | 574 factory_ = nullptr; |
| 539 callback_.Run(rv); | 575 callback_.Run(rv); |
| 540 } | 576 } |
| 541 | 577 |
| 542 base::TimeDelta QuicStreamRequest::GetTimeDelayForWaitingJob() const { | 578 base::TimeDelta QuicStreamRequest::GetTimeDelayForWaitingJob() const { |
| 543 if (!factory_) | 579 if (!factory_) |
| 544 return base::TimeDelta(); | 580 return base::TimeDelta(); |
| 545 return factory_->GetTimeDelayForWaitingJob( | 581 return factory_->GetTimeDelayForWaitingJob( |
| 546 QuicServerId(host_port_pair_, privacy_mode_)); | 582 QuicServerId(host_port_pair_, privacy_mode_)); |
| 547 } | 583 } |
| 548 | 584 |
| 549 scoped_ptr<QuicHttpStream> QuicStreamRequest::ReleaseStream() { | 585 scoped_ptr<QuicHttpStream> QuicStreamRequest::ReleaseStream() { |
| 550 DCHECK(stream_); | 586 DCHECK(stream_); |
| 587 DCHECK(!for_bidirectional_); | |
| 551 return std::move(stream_); | 588 return std::move(stream_); |
| 552 } | 589 } |
| 553 | 590 |
| 591 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) | |
| 592 scoped_ptr<BidirectionalStreamJob> | |
| 593 QuicStreamRequest::ReleaseBidirectionalStreamJob() { | |
| 594 DCHECK(bidirectional_stream_job_); | |
| 595 DCHECK(for_bidirectional_); | |
| 596 | |
| 597 return std::move(bidirectional_stream_job_); | |
| 598 } | |
| 599 #endif | |
| 600 | |
| 554 QuicStreamFactory::QuicStreamFactory( | 601 QuicStreamFactory::QuicStreamFactory( |
| 555 HostResolver* host_resolver, | 602 HostResolver* host_resolver, |
| 556 ClientSocketFactory* client_socket_factory, | 603 ClientSocketFactory* client_socket_factory, |
| 557 base::WeakPtr<HttpServerProperties> http_server_properties, | 604 base::WeakPtr<HttpServerProperties> http_server_properties, |
| 558 CertVerifier* cert_verifier, | 605 CertVerifier* cert_verifier, |
| 559 CTPolicyEnforcer* ct_policy_enforcer, | 606 CTPolicyEnforcer* ct_policy_enforcer, |
| 560 ChannelIDService* channel_id_service, | 607 ChannelIDService* channel_id_service, |
| 561 TransportSecurityState* transport_security_state, | 608 TransportSecurityState* transport_security_state, |
| 562 CTVerifier* cert_transparency_verifier, | 609 CTVerifier* cert_transparency_verifier, |
| 563 SocketPerformanceWatcherFactory* socket_performance_watcher_factory, | 610 SocketPerformanceWatcherFactory* socket_performance_watcher_factory, |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 765 const BoundNetLog& net_log, | 812 const BoundNetLog& net_log, |
| 766 QuicStreamRequest* request) { | 813 QuicStreamRequest* request) { |
| 767 QuicServerId server_id(host_port_pair, privacy_mode); | 814 QuicServerId server_id(host_port_pair, privacy_mode); |
| 768 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() checks. | 815 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() checks. |
| 769 if (!active_sessions_.empty()) { | 816 if (!active_sessions_.empty()) { |
| 770 SessionMap::iterator it = active_sessions_.find(server_id); | 817 SessionMap::iterator it = active_sessions_.find(server_id); |
| 771 if (it != active_sessions_.end()) { | 818 if (it != active_sessions_.end()) { |
| 772 QuicChromiumClientSession* session = it->second; | 819 QuicChromiumClientSession* session = it->second; |
| 773 if (!session->CanPool(origin_host.as_string(), privacy_mode)) | 820 if (!session->CanPool(origin_host.as_string(), privacy_mode)) |
| 774 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; | 821 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; |
| 775 request->set_stream(CreateFromSession(session)); | 822 request->InitializeStreamFromSession(session); |
| 776 return OK; | 823 return OK; |
| 777 } | 824 } |
| 778 } | 825 } |
| 779 | 826 |
| 780 if (HasActiveJob(server_id)) { | 827 if (HasActiveJob(server_id)) { |
| 781 active_requests_[request] = server_id; | 828 active_requests_[request] = server_id; |
| 782 job_requests_map_[server_id].insert(request); | 829 job_requests_map_[server_id].insert(request); |
| 783 return ERR_IO_PENDING; | 830 return ERR_IO_PENDING; |
| 784 } | 831 } |
| 785 | 832 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 821 // related changes. | 868 // related changes. |
| 822 if (active_sessions_.empty()) | 869 if (active_sessions_.empty()) |
| 823 return ERR_QUIC_PROTOCOL_ERROR; | 870 return ERR_QUIC_PROTOCOL_ERROR; |
| 824 SessionMap::iterator it = active_sessions_.find(server_id); | 871 SessionMap::iterator it = active_sessions_.find(server_id); |
| 825 DCHECK(it != active_sessions_.end()); | 872 DCHECK(it != active_sessions_.end()); |
| 826 if (it == active_sessions_.end()) | 873 if (it == active_sessions_.end()) |
| 827 return ERR_QUIC_PROTOCOL_ERROR; | 874 return ERR_QUIC_PROTOCOL_ERROR; |
| 828 QuicChromiumClientSession* session = it->second; | 875 QuicChromiumClientSession* session = it->second; |
| 829 if (!session->CanPool(origin_host.as_string(), privacy_mode)) | 876 if (!session->CanPool(origin_host.as_string(), privacy_mode)) |
| 830 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; | 877 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; |
| 831 request->set_stream(CreateFromSession(session)); | 878 request->InitializeStreamFromSession(session); |
| 832 } | 879 } |
| 833 return rv; | 880 return rv; |
| 834 } | 881 } |
| 835 | 882 |
| 836 void QuicStreamFactory::CreateAuxilaryJob(const QuicServerId server_id, | 883 void QuicStreamFactory::CreateAuxilaryJob(const QuicServerId server_id, |
| 837 int cert_verify_flags, | 884 int cert_verify_flags, |
| 838 bool server_and_origin_have_same_host, | 885 bool server_and_origin_have_same_host, |
| 839 bool is_post, | 886 bool is_post, |
| 840 const BoundNetLog& net_log) { | 887 const BoundNetLog& net_log) { |
| 841 Job* aux_job = new Job( | 888 Job* aux_job = new Job( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 899 RequestSet::iterator old_request_it = request_it; | 946 RequestSet::iterator old_request_it = request_it; |
| 900 ++request_it; | 947 ++request_it; |
| 901 // Remove request from containers so that OnRequestComplete() is not | 948 // Remove request from containers so that OnRequestComplete() is not |
| 902 // called later again on the same request. | 949 // called later again on the same request. |
| 903 job_requests_map_[server_id].erase(old_request_it); | 950 job_requests_map_[server_id].erase(old_request_it); |
| 904 active_requests_.erase(request); | 951 active_requests_.erase(request); |
| 905 // Notify request of certificate error. | 952 // Notify request of certificate error. |
| 906 request->OnRequestComplete(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN); | 953 request->OnRequestComplete(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN); |
| 907 continue; | 954 continue; |
| 908 } | 955 } |
| 909 request->set_stream(CreateFromSession(session)); | 956 request->InitializeStreamFromSession(session); |
| 910 ++request_it; | 957 ++request_it; |
| 911 } | 958 } |
| 912 } | 959 } |
| 913 | 960 |
| 914 while (!job_requests_map_[server_id].empty()) { | 961 while (!job_requests_map_[server_id].empty()) { |
| 915 RequestSet::iterator it = job_requests_map_[server_id].begin(); | 962 RequestSet::iterator it = job_requests_map_[server_id].begin(); |
| 916 QuicStreamRequest* request = *it; | 963 QuicStreamRequest* request = *it; |
| 917 job_requests_map_[server_id].erase(it); | 964 job_requests_map_[server_id].erase(it); |
| 918 active_requests_.erase(request); | 965 active_requests_.erase(request); |
| 919 // Even though we're invoking callbacks here, we don't need to worry | 966 // 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 Loading... | |
| 1645 // Since the session was active, there's no longer an | 1692 // Since the session was active, there's no longer an |
| 1646 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP | 1693 // 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 | 1694 // 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 | 1695 // it as recently broken, which means that 0-RTT will be disabled but we'll |
| 1649 // still race. | 1696 // still race. |
| 1650 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 1697 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
| 1651 alternative_service); | 1698 alternative_service); |
| 1652 } | 1699 } |
| 1653 | 1700 |
| 1654 } // namespace net | 1701 } // namespace net |
| OLD | NEW |