Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ssl/ssl_client_session_cache.h" | 5 #include "net/ssl/ssl_client_session_cache.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/containers/flat_set.h" | |
| 9 #include "base/memory/memory_coordinator_client_registry.h" | 10 #include "base/memory/memory_coordinator_client_registry.h" |
| 10 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 11 #include "base/time/clock.h" | 12 #include "base/time/clock.h" |
| 12 #include "base/time/default_clock.h" | 13 #include "base/time/default_clock.h" |
| 13 #include "base/trace_event/process_memory_dump.h" | 14 #include "base/trace_event/process_memory_dump.h" |
| 14 #include "net/cert/x509_util_openssl.h" | 15 #include "net/cert/x509_util_openssl.h" |
| 15 #include "third_party/boringssl/src/include/openssl/ssl.h" | 16 #include "third_party/boringssl/src/include/openssl/ssl.h" |
| 16 #include "third_party/boringssl/src/include/openssl/x509.h" | 17 #include "third_party/boringssl/src/include/openssl/x509.h" |
| 17 | 18 |
| 18 namespace net { | 19 namespace net { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 std::string absolute_name = "net/ssl_session_cache"; | 116 std::string absolute_name = "net/ssl_session_cache"; |
| 116 base::trace_event::MemoryAllocatorDump* cache_dump = | 117 base::trace_event::MemoryAllocatorDump* cache_dump = |
| 117 pmd->GetAllocatorDump(absolute_name); | 118 pmd->GetAllocatorDump(absolute_name); |
| 118 // This method can be reached from different URLRequestContexts. Since this is | 119 // This method can be reached from different URLRequestContexts. Since this is |
| 119 // a singleton, only log memory stats once. | 120 // a singleton, only log memory stats once. |
| 120 // TODO(xunjieli): Change this once crbug.com/458365 is fixed. | 121 // TODO(xunjieli): Change this once crbug.com/458365 is fixed. |
| 121 if (cache_dump) | 122 if (cache_dump) |
| 122 return; | 123 return; |
| 123 cache_dump = pmd->CreateAllocatorDump(absolute_name); | 124 cache_dump = pmd->CreateAllocatorDump(absolute_name); |
| 124 base::AutoLock lock(lock_); | 125 base::AutoLock lock(lock_); |
| 125 size_t total_serialized_cert_size = 0; | 126 size_t total_cert_size = 0; |
| 127 size_t undeduped_cert_size = 0; | |
| 126 size_t total_cert_count = 0; | 128 size_t total_cert_count = 0; |
| 129 // Use a flat_set here to avoid malloc upon insertion. | |
| 130 base::flat_set<const CRYPTO_BUFFER*> crypto_buffer_set; | |
|
DmitrySkiba
2017/02/21 22:08:25
Two things:
1. We need to resize crypto_buffer_se
| |
| 127 for (const auto& pair : cache_) { | 131 for (const auto& pair : cache_) { |
| 128 const SSL_SESSION* session = pair.second.session.get(); | 132 const SSL_SESSION* session = pair.second.session.get(); |
| 129 size_t cert_count = sk_CRYPTO_BUFFER_num(session->certs); | 133 size_t cert_count = sk_CRYPTO_BUFFER_num(session->certs); |
| 130 total_cert_count += cert_count; | 134 total_cert_count += cert_count; |
| 131 for (size_t i = 0; i < cert_count; ++i) { | 135 for (size_t i = 0; i < cert_count; ++i) { |
| 132 const CRYPTO_BUFFER* cert = sk_CRYPTO_BUFFER_value(session->certs, i); | 136 const CRYPTO_BUFFER* cert = sk_CRYPTO_BUFFER_value(session->certs, i); |
| 133 total_serialized_cert_size += CRYPTO_BUFFER_len(cert); | 137 // TODO(xunjieli): The multipler is added to account for the difference |
| 138 // between the serialized form and real cert allocation. Remove after | |
| 139 // crbug.com/671420 is done. | |
| 140 size_t cert_size = 4 * CRYPTO_BUFFER_len(cert); | |
| 141 undeduped_cert_size += cert_size; | |
| 142 if (crypto_buffer_set.find(cert) != crypto_buffer_set.end()) | |
| 143 continue; | |
| 144 total_cert_size += cert_size; | |
| 145 crypto_buffer_set.insert(cert); | |
| 134 } | 146 } |
| 135 } | 147 } |
| 136 // This measures the lower bound of the serialized certificate. It doesn't | 148 // This measures the lower bound of the serialized certificate. It doesn't |
| 137 // measure the actual memory used, which is 4x this amount (see | 149 // measure the actual memory used, which is 4x this amount (see |
| 138 // crbug.com/671420 for more details). | 150 // crbug.com/671420 for more details). |
| 139 cache_dump->AddScalar("serialized_cert_size", | 151 cache_dump->AddScalar("cert_size", |
| 140 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 152 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 141 total_serialized_cert_size); | 153 total_cert_size); |
| 154 cache_dump->AddScalar("undeduped_cert_size", | |
| 155 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
| 156 undeduped_cert_size); | |
| 142 cache_dump->AddScalar("cert_count", | 157 cache_dump->AddScalar("cert_count", |
| 143 base::trace_event::MemoryAllocatorDump::kUnitsObjects, | 158 base::trace_event::MemoryAllocatorDump::kUnitsObjects, |
| 144 total_cert_count); | 159 total_cert_count); |
| 145 cache_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 160 cache_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 146 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 161 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 147 total_serialized_cert_size); | 162 total_cert_size); |
| 148 } | 163 } |
| 149 | 164 |
| 150 SSLClientSessionCache::Entry::Entry() : lookups(0) {} | 165 SSLClientSessionCache::Entry::Entry() : lookups(0) {} |
| 151 SSLClientSessionCache::Entry::Entry(Entry&&) = default; | 166 SSLClientSessionCache::Entry::Entry(Entry&&) = default; |
| 152 SSLClientSessionCache::Entry::~Entry() = default; | 167 SSLClientSessionCache::Entry::~Entry() = default; |
| 153 | 168 |
| 154 void SSLClientSessionCache::FlushExpiredSessions() { | 169 void SSLClientSessionCache::FlushExpiredSessions() { |
| 155 time_t now = clock_->Now().ToTimeT(); | 170 time_t now = clock_->Now().ToTimeT(); |
| 156 auto iter = cache_.begin(); | 171 auto iter = cache_.begin(); |
| 157 while (iter != cache_.end()) { | 172 while (iter != cache_.end()) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 175 Flush(); | 190 Flush(); |
| 176 break; | 191 break; |
| 177 } | 192 } |
| 178 } | 193 } |
| 179 | 194 |
| 180 void SSLClientSessionCache::OnPurgeMemory() { | 195 void SSLClientSessionCache::OnPurgeMemory() { |
| 181 Flush(); | 196 Flush(); |
| 182 } | 197 } |
| 183 | 198 |
| 184 } // namespace net | 199 } // namespace net |
| OLD | NEW |