| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <tuple> | 8 #include <tuple> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/metrics/field_trial.h" | 13 #include "base/metrics/field_trial.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/metrics/sparse_histogram.h" | 15 #include "base/metrics/sparse_histogram.h" |
| 16 #include "base/rand_util.h" | 16 #include "base/rand_util.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 21 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "base/trace_event/memory_allocator_dump.h" |
| 23 #include "base/trace_event/memory_usage_estimator.h" |
| 24 #include "base/trace_event/process_memory_dump.h" |
| 22 #include "base/trace_event/trace_event.h" | 25 #include "base/trace_event/trace_event.h" |
| 23 #include "base/values.h" | 26 #include "base/values.h" |
| 24 #include "crypto/openssl_util.h" | 27 #include "crypto/openssl_util.h" |
| 25 #include "net/base/ip_address.h" | 28 #include "net/base/ip_address.h" |
| 26 #include "net/base/net_errors.h" | 29 #include "net/base/net_errors.h" |
| 27 #include "net/base/proxy_delegate.h" | 30 #include "net/base/proxy_delegate.h" |
| 28 #include "net/base/trace_constants.h" | 31 #include "net/base/trace_constants.h" |
| 29 #include "net/cert/cert_verifier.h" | 32 #include "net/cert/cert_verifier.h" |
| 30 #include "net/cert/ct_verifier.h" | 33 #include "net/cert/ct_verifier.h" |
| 31 #include "net/dns/host_resolver.h" | 34 #include "net/dns/host_resolver.h" |
| (...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 if (!srtt) | 893 if (!srtt) |
| 891 srtt = kDefaultRTT; | 894 srtt = kDefaultRTT; |
| 892 return base::TimeDelta::FromMicroseconds(srtt); | 895 return base::TimeDelta::FromMicroseconds(srtt); |
| 893 } | 896 } |
| 894 | 897 |
| 895 void QuicStreamFactory::set_quic_server_info_factory( | 898 void QuicStreamFactory::set_quic_server_info_factory( |
| 896 QuicServerInfoFactory* quic_server_info_factory) { | 899 QuicServerInfoFactory* quic_server_info_factory) { |
| 897 quic_server_info_factory_.reset(quic_server_info_factory); | 900 quic_server_info_factory_.reset(quic_server_info_factory); |
| 898 } | 901 } |
| 899 | 902 |
| 903 void QuicStreamFactory::DumpMemoryStats( |
| 904 base::trace_event::ProcessMemoryDump* pmd, |
| 905 const std::string& parent_absolute_name) const { |
| 906 if (all_sessions_.empty()) |
| 907 return; |
| 908 base::trace_event::MemoryAllocatorDump* factory_dump = |
| 909 pmd->CreateAllocatorDump(parent_absolute_name + "/quic_stream_factory"); |
| 910 size_t memory_estimate = |
| 911 base::trace_event::EstimateMemoryUsage(all_sessions_); |
| 912 factory_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 913 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 914 memory_estimate); |
| 915 factory_dump->AddScalar( |
| 916 base::trace_event::MemoryAllocatorDump::kNameObjectCount, |
| 917 base::trace_event::MemoryAllocatorDump::kUnitsObjects, |
| 918 all_sessions_.size()); |
| 919 } |
| 920 |
| 900 bool QuicStreamFactory::CanUseExistingSession(const QuicServerId& server_id, | 921 bool QuicStreamFactory::CanUseExistingSession(const QuicServerId& server_id, |
| 901 const HostPortPair& destination) { | 922 const HostPortPair& destination) { |
| 902 // TODO(zhongyi): delete active_sessions_.empty() checks once the | 923 // TODO(zhongyi): delete active_sessions_.empty() checks once the |
| 903 // android crash issue(crbug.com/498823) is resolved. | 924 // android crash issue(crbug.com/498823) is resolved. |
| 904 if (active_sessions_.empty()) | 925 if (active_sessions_.empty()) |
| 905 return false; | 926 return false; |
| 906 | 927 |
| 907 if (base::ContainsKey(active_sessions_, server_id)) | 928 if (base::ContainsKey(active_sessions_, server_id)) |
| 908 return true; | 929 return true; |
| 909 | 930 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1040 return std::tie(destination_, server_id_) < | 1061 return std::tie(destination_, server_id_) < |
| 1041 std::tie(other.destination_, other.server_id_); | 1062 std::tie(other.destination_, other.server_id_); |
| 1042 } | 1063 } |
| 1043 | 1064 |
| 1044 bool QuicStreamFactory::QuicSessionKey::operator==( | 1065 bool QuicStreamFactory::QuicSessionKey::operator==( |
| 1045 const QuicSessionKey& other) const { | 1066 const QuicSessionKey& other) const { |
| 1046 return destination_.Equals(other.destination_) && | 1067 return destination_.Equals(other.destination_) && |
| 1047 server_id_ == other.server_id_; | 1068 server_id_ == other.server_id_; |
| 1048 } | 1069 } |
| 1049 | 1070 |
| 1071 size_t QuicStreamFactory::QuicSessionKey::EstimateMemoryUsage() const { |
| 1072 // Return 0 because QuicSessionKey is very small. |
| 1073 return 0; |
| 1074 } |
| 1075 |
| 1050 void QuicStreamFactory::CreateAuxilaryJob(const QuicSessionKey& key, | 1076 void QuicStreamFactory::CreateAuxilaryJob(const QuicSessionKey& key, |
| 1051 int cert_verify_flags, | 1077 int cert_verify_flags, |
| 1052 const NetLogWithSource& net_log) { | 1078 const NetLogWithSource& net_log) { |
| 1053 Job* aux_job = | 1079 Job* aux_job = |
| 1054 new Job(this, host_resolver_, key, WasQuicRecentlyBroken(key.server_id()), | 1080 new Job(this, host_resolver_, key, WasQuicRecentlyBroken(key.server_id()), |
| 1055 cert_verify_flags, nullptr, net_log); | 1081 cert_verify_flags, nullptr, net_log); |
| 1056 active_jobs_[key.server_id()][aux_job] = base::WrapUnique(aux_job); | 1082 active_jobs_[key.server_id()][aux_job] = base::WrapUnique(aux_job); |
| 1057 task_runner_->PostTask(FROM_HERE, | 1083 task_runner_->PostTask(FROM_HERE, |
| 1058 base::Bind(&QuicStreamFactory::Job::RunAuxilaryJob, | 1084 base::Bind(&QuicStreamFactory::Job::RunAuxilaryJob, |
| 1059 aux_job->GetWeakPtr())); | 1085 aux_job->GetWeakPtr())); |
| (...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1902 void QuicStreamFactory::OpenFactory() { | 1928 void QuicStreamFactory::OpenFactory() { |
| 1903 status_ = OPEN; | 1929 status_ = OPEN; |
| 1904 } | 1930 } |
| 1905 | 1931 |
| 1906 void QuicStreamFactory::MaybeClearConsecutiveDisabledCount() { | 1932 void QuicStreamFactory::MaybeClearConsecutiveDisabledCount() { |
| 1907 if (status_ == OPEN) | 1933 if (status_ == OPEN) |
| 1908 consecutive_disabled_count_ = 0; | 1934 consecutive_disabled_count_ = 0; |
| 1909 } | 1935 } |
| 1910 | 1936 |
| 1911 } // namespace net | 1937 } // namespace net |
| OLD | NEW |