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/chromium/quic_stream_factory.h" | 5 #include "net/quic/chromium/quic_stream_factory.h" |
6 | 6 |
7 #include <openssl/aead.h> | 7 #include <openssl/aead.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <tuple> | 10 #include <tuple> |
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 } | 853 } |
854 | 854 |
855 QuicStreamFactory::~QuicStreamFactory() { | 855 QuicStreamFactory::~QuicStreamFactory() { |
856 CloseAllSessions(ERR_ABORTED, QUIC_CONNECTION_CANCELLED); | 856 CloseAllSessions(ERR_ABORTED, QUIC_CONNECTION_CANCELLED); |
857 while (!all_sessions_.empty()) { | 857 while (!all_sessions_.empty()) { |
858 delete all_sessions_.begin()->first; | 858 delete all_sessions_.begin()->first; |
859 all_sessions_.erase(all_sessions_.begin()); | 859 all_sessions_.erase(all_sessions_.begin()); |
860 } | 860 } |
861 while (!active_jobs_.empty()) { | 861 while (!active_jobs_.empty()) { |
862 const QuicServerId server_id = active_jobs_.begin()->first; | 862 const QuicServerId server_id = active_jobs_.begin()->first; |
863 STLDeleteElements(&(active_jobs_[server_id])); | 863 base::STLDeleteElements(&(active_jobs_[server_id])); |
864 active_jobs_.erase(server_id); | 864 active_jobs_.erase(server_id); |
865 } | 865 } |
866 while (!active_cert_verifier_jobs_.empty()) | 866 while (!active_cert_verifier_jobs_.empty()) |
867 active_cert_verifier_jobs_.erase(active_cert_verifier_jobs_.begin()); | 867 active_cert_verifier_jobs_.erase(active_cert_verifier_jobs_.begin()); |
868 if (ssl_config_service_.get()) | 868 if (ssl_config_service_.get()) |
869 ssl_config_service_->RemoveObserver(this); | 869 ssl_config_service_->RemoveObserver(this); |
870 if (migrate_sessions_on_network_change_) { | 870 if (migrate_sessions_on_network_change_) { |
871 NetworkChangeNotifier::RemoveNetworkObserver(this); | 871 NetworkChangeNotifier::RemoveNetworkObserver(this); |
872 } else if (close_sessions_on_ip_change_) { | 872 } else if (close_sessions_on_ip_change_) { |
873 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 873 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 quic_server_info_factory_.reset(quic_server_info_factory); | 905 quic_server_info_factory_.reset(quic_server_info_factory); |
906 } | 906 } |
907 | 907 |
908 bool QuicStreamFactory::CanUseExistingSession(const QuicServerId& server_id, | 908 bool QuicStreamFactory::CanUseExistingSession(const QuicServerId& server_id, |
909 const HostPortPair& destination) { | 909 const HostPortPair& destination) { |
910 // TODO(zhongyi): delete active_sessions_.empty() checks once the | 910 // TODO(zhongyi): delete active_sessions_.empty() checks once the |
911 // android crash issue(crbug.com/498823) is resolved. | 911 // android crash issue(crbug.com/498823) is resolved. |
912 if (active_sessions_.empty()) | 912 if (active_sessions_.empty()) |
913 return false; | 913 return false; |
914 | 914 |
915 if (ContainsKey(active_sessions_, server_id)) | 915 if (base::ContainsKey(active_sessions_, server_id)) |
916 return true; | 916 return true; |
917 | 917 |
918 for (const auto& key_value : active_sessions_) { | 918 for (const auto& key_value : active_sessions_) { |
919 QuicChromiumClientSession* session = key_value.second; | 919 QuicChromiumClientSession* session = key_value.second; |
920 if (destination.Equals(all_sessions_[session].destination()) && | 920 if (destination.Equals(all_sessions_[session].destination()) && |
921 session->CanPool(server_id.host(), server_id.privacy_mode())) { | 921 session->CanPool(server_id.host(), server_id.privacy_mode())) { |
922 return true; | 922 return true; |
923 } | 923 } |
924 } | 924 } |
925 | 925 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
984 | 984 |
985 // TODO(rtenneti): |task_runner_| is used by the Job. Initialize task_runner_ | 985 // TODO(rtenneti): |task_runner_| is used by the Job. Initialize task_runner_ |
986 // in the constructor after WebRequestActionWithThreadsTest.* tests are fixed. | 986 // in the constructor after WebRequestActionWithThreadsTest.* tests are fixed. |
987 if (!task_runner_) | 987 if (!task_runner_) |
988 task_runner_ = base::ThreadTaskRunnerHandle::Get().get(); | 988 task_runner_ = base::ThreadTaskRunnerHandle::Get().get(); |
989 | 989 |
990 QuicServerInfo* quic_server_info = nullptr; | 990 QuicServerInfo* quic_server_info = nullptr; |
991 if (quic_server_info_factory_.get()) { | 991 if (quic_server_info_factory_.get()) { |
992 bool load_from_disk_cache = !disable_disk_cache_; | 992 bool load_from_disk_cache = !disable_disk_cache_; |
993 MaybeInitialize(); | 993 MaybeInitialize(); |
994 if (!ContainsKey(quic_supported_servers_at_startup_, destination)) { | 994 if (!base::ContainsKey(quic_supported_servers_at_startup_, destination)) { |
995 // If there is no entry for QUIC, consider that as a new server and | 995 // If there is no entry for QUIC, consider that as a new server and |
996 // don't wait for Cache thread to load the data for that server. | 996 // don't wait for Cache thread to load the data for that server. |
997 load_from_disk_cache = false; | 997 load_from_disk_cache = false; |
998 } | 998 } |
999 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) | 999 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) |
1000 quic_server_info = quic_server_info_factory_->GetForServer(server_id); | 1000 quic_server_info = quic_server_info_factory_->GetForServer(server_id); |
1001 } | 1001 } |
1002 | 1002 |
1003 ignore_result(StartCertVerifyJob(server_id, cert_verify_flags, net_log)); | 1003 ignore_result(StartCertVerifyJob(server_id, cert_verify_flags, net_log)); |
1004 | 1004 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1058 aux_job->GetWeakPtr())); | 1058 aux_job->GetWeakPtr())); |
1059 } | 1059 } |
1060 | 1060 |
1061 bool QuicStreamFactory::OnResolution(const QuicSessionKey& key, | 1061 bool QuicStreamFactory::OnResolution(const QuicSessionKey& key, |
1062 const AddressList& address_list) { | 1062 const AddressList& address_list) { |
1063 const QuicServerId& server_id(key.server_id()); | 1063 const QuicServerId& server_id(key.server_id()); |
1064 DCHECK(!HasActiveSession(server_id)); | 1064 DCHECK(!HasActiveSession(server_id)); |
1065 if (disable_connection_pooling_) | 1065 if (disable_connection_pooling_) |
1066 return false; | 1066 return false; |
1067 for (const IPEndPoint& address : address_list) { | 1067 for (const IPEndPoint& address : address_list) { |
1068 if (!ContainsKey(ip_aliases_, address)) | 1068 if (!base::ContainsKey(ip_aliases_, address)) |
1069 continue; | 1069 continue; |
1070 | 1070 |
1071 const SessionSet& sessions = ip_aliases_[address]; | 1071 const SessionSet& sessions = ip_aliases_[address]; |
1072 for (QuicChromiumClientSession* session : sessions) { | 1072 for (QuicChromiumClientSession* session : sessions) { |
1073 if (!session->CanPool(server_id.host(), server_id.privacy_mode())) | 1073 if (!session->CanPool(server_id.host(), server_id.privacy_mode())) |
1074 continue; | 1074 continue; |
1075 active_sessions_[server_id] = session; | 1075 active_sessions_[server_id] = session; |
1076 session_aliases_[session].insert(key); | 1076 session_aliases_[session].insert(key); |
1077 return true; | 1077 return true; |
1078 } | 1078 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 // about |this| being deleted, because the factory is owned by the | 1121 // about |this| being deleted, because the factory is owned by the |
1122 // profile which can not be deleted via callbacks. | 1122 // profile which can not be deleted via callbacks. |
1123 request->OnRequestComplete(rv); | 1123 request->OnRequestComplete(rv); |
1124 } | 1124 } |
1125 | 1125 |
1126 for (Job* other_job : active_jobs_[server_id]) { | 1126 for (Job* other_job : active_jobs_[server_id]) { |
1127 if (other_job != job) | 1127 if (other_job != job) |
1128 other_job->Cancel(); | 1128 other_job->Cancel(); |
1129 } | 1129 } |
1130 | 1130 |
1131 STLDeleteElements(&(active_jobs_[server_id])); | 1131 base::STLDeleteElements(&(active_jobs_[server_id])); |
1132 active_jobs_.erase(server_id); | 1132 active_jobs_.erase(server_id); |
1133 job_requests_map_.erase(server_id); | 1133 job_requests_map_.erase(server_id); |
1134 } | 1134 } |
1135 | 1135 |
1136 void QuicStreamFactory::OnCertVerifyJobComplete(CertVerifierJob* job, int rv) { | 1136 void QuicStreamFactory::OnCertVerifyJobComplete(CertVerifierJob* job, int rv) { |
1137 active_cert_verifier_jobs_.erase(job->server_id()); | 1137 active_cert_verifier_jobs_.erase(job->server_id()); |
1138 } | 1138 } |
1139 | 1139 |
1140 std::unique_ptr<QuicHttpStream> QuicStreamFactory::CreateFromSession( | 1140 std::unique_ptr<QuicHttpStream> QuicStreamFactory::CreateFromSession( |
1141 QuicChromiumClientSession* session) { | 1141 QuicChromiumClientSession* session) { |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1674 // Since the OnCACertChanged method doesn't tell us what | 1674 // Since the OnCACertChanged method doesn't tell us what |
1675 // kind of change it is, we have to flush the socket | 1675 // kind of change it is, we have to flush the socket |
1676 // pools to be safe. | 1676 // pools to be safe. |
1677 CloseAllSessions(ERR_CERT_DATABASE_CHANGED, QUIC_CONNECTION_CANCELLED); | 1677 CloseAllSessions(ERR_CERT_DATABASE_CHANGED, QUIC_CONNECTION_CANCELLED); |
1678 } | 1678 } |
1679 | 1679 |
1680 bool QuicStreamFactory::HasActiveSession(const QuicServerId& server_id) const { | 1680 bool QuicStreamFactory::HasActiveSession(const QuicServerId& server_id) const { |
1681 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() check. | 1681 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() check. |
1682 if (active_sessions_.empty()) | 1682 if (active_sessions_.empty()) |
1683 return false; | 1683 return false; |
1684 return ContainsKey(active_sessions_, server_id); | 1684 return base::ContainsKey(active_sessions_, server_id); |
1685 } | 1685 } |
1686 | 1686 |
1687 bool QuicStreamFactory::HasActiveJob(const QuicServerId& server_id) const { | 1687 bool QuicStreamFactory::HasActiveJob(const QuicServerId& server_id) const { |
1688 return ContainsKey(active_jobs_, server_id); | 1688 return base::ContainsKey(active_jobs_, server_id); |
1689 } | 1689 } |
1690 | 1690 |
1691 bool QuicStreamFactory::HasActiveCertVerifierJob( | 1691 bool QuicStreamFactory::HasActiveCertVerifierJob( |
1692 const QuicServerId& server_id) const { | 1692 const QuicServerId& server_id) const { |
1693 return ContainsKey(active_cert_verifier_jobs_, server_id); | 1693 return base::ContainsKey(active_cert_verifier_jobs_, server_id); |
1694 } | 1694 } |
1695 | 1695 |
1696 int QuicStreamFactory::ConfigureSocket(DatagramClientSocket* socket, | 1696 int QuicStreamFactory::ConfigureSocket(DatagramClientSocket* socket, |
1697 IPEndPoint addr, | 1697 IPEndPoint addr, |
1698 NetworkHandle network) { | 1698 NetworkHandle network) { |
1699 if (enable_non_blocking_io_ && | 1699 if (enable_non_blocking_io_ && |
1700 client_socket_factory_ == ClientSocketFactory::GetDefaultFactory()) { | 1700 client_socket_factory_ == ClientSocketFactory::GetDefaultFactory()) { |
1701 #if defined(OS_WIN) | 1701 #if defined(OS_WIN) |
1702 static_cast<UDPClientSocket*>(socket)->UseNonBlockingIO(); | 1702 static_cast<UDPClientSocket*>(socket)->UseNonBlockingIO(); |
1703 #endif | 1703 #endif |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1751 const QuicSessionKey& key, | 1751 const QuicSessionKey& key, |
1752 int cert_verify_flags, | 1752 int cert_verify_flags, |
1753 std::unique_ptr<QuicServerInfo> server_info, | 1753 std::unique_ptr<QuicServerInfo> server_info, |
1754 const AddressList& address_list, | 1754 const AddressList& address_list, |
1755 base::TimeTicks dns_resolution_end_time, | 1755 base::TimeTicks dns_resolution_end_time, |
1756 const BoundNetLog& net_log, | 1756 const BoundNetLog& net_log, |
1757 QuicChromiumClientSession** session) { | 1757 QuicChromiumClientSession** session) { |
1758 TRACE_EVENT0("net", "QuicStreamFactory::CreateSession"); | 1758 TRACE_EVENT0("net", "QuicStreamFactory::CreateSession"); |
1759 IPEndPoint addr = *address_list.begin(); | 1759 IPEndPoint addr = *address_list.begin(); |
1760 bool enable_port_selection = enable_port_selection_; | 1760 bool enable_port_selection = enable_port_selection_; |
1761 if (enable_port_selection && ContainsKey(gone_away_aliases_, key)) { | 1761 if (enable_port_selection && base::ContainsKey(gone_away_aliases_, key)) { |
1762 // Disable port selection when the server is going away. | 1762 // Disable port selection when the server is going away. |
1763 // There is no point in trying to return to the same server, if | 1763 // There is no point in trying to return to the same server, if |
1764 // that server is no longer handling requests. | 1764 // that server is no longer handling requests. |
1765 enable_port_selection = false; | 1765 enable_port_selection = false; |
1766 gone_away_aliases_.erase(key); | 1766 gone_away_aliases_.erase(key); |
1767 } | 1767 } |
1768 const QuicServerId& server_id = key.server_id(); | 1768 const QuicServerId& server_id = key.server_id(); |
1769 scoped_refptr<PortSuggester> port_suggester = | 1769 scoped_refptr<PortSuggester> port_suggester = |
1770 new PortSuggester(server_id.host_port_pair(), port_seed_); | 1770 new PortSuggester(server_id.host_port_pair(), port_seed_); |
1771 DatagramSocket::BindType bind_type = | 1771 DatagramSocket::BindType bind_type = |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1844 server_id, yield_after_packets_, yield_after_duration_, cert_verify_flags, | 1844 server_id, yield_after_packets_, yield_after_duration_, cert_verify_flags, |
1845 config, &crypto_config_, network_connection_.GetDescription(), | 1845 config, &crypto_config_, network_connection_.GetDescription(), |
1846 dns_resolution_end_time, &push_promise_index_, | 1846 dns_resolution_end_time, &push_promise_index_, |
1847 base::ThreadTaskRunnerHandle::Get().get(), | 1847 base::ThreadTaskRunnerHandle::Get().get(), |
1848 std::move(socket_performance_watcher), net_log.net_log()); | 1848 std::move(socket_performance_watcher), net_log.net_log()); |
1849 | 1849 |
1850 all_sessions_[*session] = key; // owning pointer | 1850 all_sessions_[*session] = key; // owning pointer |
1851 writer->Initialize(*session, connection); | 1851 writer->Initialize(*session, connection); |
1852 | 1852 |
1853 (*session)->Initialize(); | 1853 (*session)->Initialize(); |
1854 bool closed_during_initialize = !ContainsKey(all_sessions_, *session) || | 1854 bool closed_during_initialize = !base::ContainsKey(all_sessions_, *session) || |
1855 !(*session)->connection()->connected(); | 1855 !(*session)->connection()->connected(); |
1856 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.ClosedDuringInitializeSession", | 1856 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.ClosedDuringInitializeSession", |
1857 closed_during_initialize); | 1857 closed_during_initialize); |
1858 if (closed_during_initialize) { | 1858 if (closed_during_initialize) { |
1859 DLOG(DFATAL) << "Session closed during initialize"; | 1859 DLOG(DFATAL) << "Session closed during initialize"; |
1860 *session = nullptr; | 1860 *session = nullptr; |
1861 return ERR_CONNECTION_CLOSED; | 1861 return ERR_CONNECTION_CLOSED; |
1862 } | 1862 } |
1863 return OK; | 1863 return OK; |
1864 } | 1864 } |
1865 | 1865 |
1866 void QuicStreamFactory::ActivateSession(const QuicSessionKey& key, | 1866 void QuicStreamFactory::ActivateSession(const QuicSessionKey& key, |
1867 QuicChromiumClientSession* session) { | 1867 QuicChromiumClientSession* session) { |
1868 const QuicServerId& server_id(key.server_id()); | 1868 const QuicServerId& server_id(key.server_id()); |
1869 DCHECK(!HasActiveSession(server_id)); | 1869 DCHECK(!HasActiveSession(server_id)); |
1870 UMA_HISTOGRAM_COUNTS("Net.QuicActiveSessions", active_sessions_.size()); | 1870 UMA_HISTOGRAM_COUNTS("Net.QuicActiveSessions", active_sessions_.size()); |
1871 active_sessions_[server_id] = session; | 1871 active_sessions_[server_id] = session; |
1872 session_aliases_[session].insert(key); | 1872 session_aliases_[session].insert(key); |
1873 const IPEndPoint peer_address = session->connection()->peer_address(); | 1873 const IPEndPoint peer_address = session->connection()->peer_address(); |
1874 DCHECK(!ContainsKey(ip_aliases_[peer_address], session)); | 1874 DCHECK(!base::ContainsKey(ip_aliases_[peer_address], session)); |
1875 ip_aliases_[peer_address].insert(session); | 1875 ip_aliases_[peer_address].insert(session); |
1876 } | 1876 } |
1877 | 1877 |
1878 int64_t QuicStreamFactory::GetServerNetworkStatsSmoothedRttInMicroseconds( | 1878 int64_t QuicStreamFactory::GetServerNetworkStatsSmoothedRttInMicroseconds( |
1879 const QuicServerId& server_id) const { | 1879 const QuicServerId& server_id) const { |
1880 url::SchemeHostPort server("https", server_id.host_port_pair().host(), | 1880 url::SchemeHostPort server("https", server_id.host_port_pair().host(), |
1881 server_id.host_port_pair().port()); | 1881 server_id.host_port_pair().port()); |
1882 const ServerNetworkStats* stats = | 1882 const ServerNetworkStats* stats = |
1883 http_server_properties_->GetServerNetworkStats(server); | 1883 http_server_properties_->GetServerNetworkStats(server); |
1884 if (stats == nullptr) | 1884 if (stats == nullptr) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1937 return; | 1937 return; |
1938 | 1938 |
1939 // |server_info| will be NULL, if a non-empty server config already exists in | 1939 // |server_info| will be NULL, if a non-empty server config already exists in |
1940 // the memory cache. | 1940 // the memory cache. |
1941 if (!server_info) | 1941 if (!server_info) |
1942 return; | 1942 return; |
1943 | 1943 |
1944 // TODO(rtenneti): Delete the following histogram after collecting stats. | 1944 // TODO(rtenneti): Delete the following histogram after collecting stats. |
1945 // If the AlternativeServiceMap contained an entry for this host, check if | 1945 // If the AlternativeServiceMap contained an entry for this host, check if |
1946 // the disk cache contained an entry for it. | 1946 // the disk cache contained an entry for it. |
1947 if (ContainsKey(quic_supported_servers_at_startup_, | 1947 if (base::ContainsKey(quic_supported_servers_at_startup_, |
1948 server_id.host_port_pair())) { | 1948 server_id.host_port_pair())) { |
1949 UMA_HISTOGRAM_BOOLEAN("Net.QuicServerInfo.ExpectConfigMissingFromDiskCache", | 1949 UMA_HISTOGRAM_BOOLEAN("Net.QuicServerInfo.ExpectConfigMissingFromDiskCache", |
1950 server_info->state().server_config.empty()); | 1950 server_info->state().server_config.empty()); |
1951 } | 1951 } |
1952 | 1952 |
1953 cached->Initialize(server_info->state().server_config, | 1953 cached->Initialize(server_info->state().server_config, |
1954 server_info->state().source_address_token, | 1954 server_info->state().source_address_token, |
1955 server_info->state().certs, server_info->state().cert_sct, | 1955 server_info->state().certs, server_info->state().cert_sct, |
1956 server_info->state().chlo_hash, | 1956 server_info->state().chlo_hash, |
1957 server_info->state().server_config_sig, clock_->WallNow()); | 1957 server_info->state().server_config_sig, clock_->WallNow()); |
1958 } | 1958 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2038 // Since the session was active, there's no longer an | 2038 // Since the session was active, there's no longer an |
2039 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP | 2039 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP |
2040 // job also fails. So to avoid not using QUIC when we otherwise could, we mark | 2040 // job also fails. So to avoid not using QUIC when we otherwise could, we mark |
2041 // it as recently broken, which means that 0-RTT will be disabled but we'll | 2041 // it as recently broken, which means that 0-RTT will be disabled but we'll |
2042 // still race. | 2042 // still race. |
2043 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 2043 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
2044 alternative_service); | 2044 alternative_service); |
2045 } | 2045 } |
2046 | 2046 |
2047 } // namespace net | 2047 } // namespace net |
OLD | NEW |