| Index: net/ssl/ssl_client_session_cache.cc
|
| diff --git a/net/ssl/ssl_client_session_cache.cc b/net/ssl/ssl_client_session_cache.cc
|
| index 19b9d556a13c9c0c2f9d15f00a835f44254ba2e1..52e7ac26369ac4688e95f1660e74ca64d6b0cba2 100644
|
| --- a/net/ssl/ssl_client_session_cache.cc
|
| +++ b/net/ssl/ssl_client_session_cache.cc
|
| @@ -7,6 +7,7 @@
|
| #include <utility>
|
|
|
| #include "base/memory/memory_coordinator_client_registry.h"
|
| +#include "base/metrics/histogram_macros.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "base/time/clock.h"
|
| #include "base/time/default_clock.h"
|
| @@ -17,6 +18,11 @@
|
|
|
| namespace net {
|
|
|
| +SSLClientSessionCache::Entry::Entry()
|
| + : active_lookups(0), max_lookups(0), should_log(false) {}
|
| +SSLClientSessionCache::Entry::Entry(Entry&&) = default;
|
| +SSLClientSessionCache::Entry::~Entry() = default;
|
| +
|
| SSLClientSessionCache::SSLClientSessionCache(const Config& config)
|
| : clock_(new base::DefaultClock),
|
| config_(config),
|
| @@ -51,22 +57,53 @@ bssl::UniquePtr<SSL_SESSION> SSLClientSessionCache::Lookup(
|
| if (iter == cache_.end())
|
| return nullptr;
|
|
|
| - SSL_SESSION* session = iter->second.get();
|
| + SSL_SESSION* session = iter->second.session.get();
|
| if (IsExpired(session, clock_->Now().ToTimeT())) {
|
| cache_.Erase(iter);
|
| return nullptr;
|
| }
|
|
|
| + iter->second.active_lookups++;
|
| + if (iter->second.active_lookups > iter->second.max_lookups)
|
| + iter->second.max_lookups = iter->second.active_lookups;
|
| +
|
| SSL_SESSION_up_ref(session);
|
| return bssl::UniquePtr<SSL_SESSION>(session);
|
| }
|
|
|
| +void SSLClientSessionCache::DecrementLookupCount(const std::string& cache_key,
|
| + bool should_log) {
|
| + base::AutoLock lock(lock_);
|
| +
|
| + // It's possible that the cached session for this key was deleted after the
|
| + // Lookup, and also possible that it has been replaced by a new Entry. If
|
| + // that's the case, don't do anything.
|
| + auto iter = cache_.Get(cache_key);
|
| + if (iter == cache_.end() || iter->second.active_lookups == 0)
|
| + return;
|
| +
|
| + iter->second.active_lookups--;
|
| + if (should_log)
|
| + iter->second.should_log = true;
|
| +
|
| + if (iter->second.active_lookups == 0) {
|
| + if (iter->second.should_log) {
|
| + UMA_HISTOGRAM_EXACT_LINEAR("Net.SSLSessionConcurrentLookupCount",
|
| + iter->second.max_lookups, 20);
|
| + }
|
| + iter->second.max_lookups = 0;
|
| + iter->second.should_log = false;
|
| + }
|
| +}
|
| +
|
| void SSLClientSessionCache::Insert(const std::string& cache_key,
|
| SSL_SESSION* session) {
|
| base::AutoLock lock(lock_);
|
|
|
| SSL_SESSION_up_ref(session);
|
| - cache_.Put(cache_key, bssl::UniquePtr<SSL_SESSION>(session));
|
| + Entry entry;
|
| + entry.session = bssl::UniquePtr<SSL_SESSION>(session);
|
| + cache_.Put(cache_key, std::move(entry));
|
| }
|
|
|
| void SSLClientSessionCache::Flush() {
|
| @@ -101,7 +138,7 @@ void SSLClientSessionCache::DumpMemoryStats(
|
| int total_serialized_cert_size = 0;
|
| int total_cert_count = 0;
|
| for (const auto& pair : cache_) {
|
| - auto entry = pair.second.get();
|
| + auto entry = pair.second.session.get();
|
| auto cert_chain = entry->x509_chain;
|
| size_t cert_count = sk_X509_num(cert_chain);
|
| total_cert_count += cert_count;
|
| @@ -128,7 +165,7 @@ void SSLClientSessionCache::FlushExpiredSessions() {
|
| time_t now = clock_->Now().ToTimeT();
|
| auto iter = cache_.begin();
|
| while (iter != cache_.end()) {
|
| - if (IsExpired(iter->second.get(), now)) {
|
| + if (IsExpired(iter->second.session.get(), now)) {
|
| iter = cache_.Erase(iter);
|
| } else {
|
| ++iter;
|
|
|