Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1999)

Unified Diff: net/ssl/ssl_client_session_cache.cc

Issue 2625883002: SSLClientSessionCache: Log number of times Lookup is called per Session. (Closed)
Patch Set: reply to comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/ssl/ssl_client_session_cache.h ('k') | net/ssl/ssl_client_session_cache_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ff945cc47ec95a58a6f03fbc0e0e790d34575334..4cb6c9ae02527995ec209818b9a192aad24c40c3 100644
--- a/net/ssl/ssl_client_session_cache.cc
+++ b/net/ssl/ssl_client_session_cache.cc
@@ -37,7 +37,8 @@ size_t SSLClientSessionCache::size() const {
}
bssl::UniquePtr<SSL_SESSION> SSLClientSessionCache::Lookup(
- const std::string& cache_key) {
+ const std::string& cache_key,
+ int* count) {
base::AutoLock lock(lock_);
// Expire stale sessions.
@@ -47,26 +48,49 @@ bssl::UniquePtr<SSL_SESSION> SSLClientSessionCache::Lookup(
FlushExpiredSessions();
}
+ // Set count to 0 if there's no session in the cache.
+ if (count != nullptr)
+ *count = 0;
+
auto iter = cache_.Get(cache_key);
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.lookups++;
+ if (count != nullptr) {
+ *count = iter->second.lookups;
+ }
+
SSL_SESSION_up_ref(session);
return bssl::UniquePtr<SSL_SESSION>(session);
}
+void SSLClientSessionCache::ResetLookupCount(const std::string& cache_key) {
+ base::AutoLock lock(lock_);
+
+ // It's possible that the cached session for this key was deleted after the
+ // Lookup. If that's the case, don't do anything.
+ auto iter = cache_.Get(cache_key);
+ if (iter == cache_.end())
+ return;
+
+ iter->second.lookups = 0;
+}
+
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 +125,7 @@ void SSLClientSessionCache::DumpMemoryStats(
size_t total_serialized_cert_size = 0;
size_t total_cert_count = 0;
for (const auto& pair : cache_) {
- const SSL_SESSION* session = pair.second.get();
+ const SSL_SESSION* session = pair.second.session.get();
size_t cert_count = sk_CRYPTO_BUFFER_num(session->certs);
total_cert_count += cert_count;
for (size_t i = 0; i < cert_count; ++i) {
@@ -123,11 +147,15 @@ void SSLClientSessionCache::DumpMemoryStats(
total_serialized_cert_size);
}
+SSLClientSessionCache::Entry::Entry() : lookups(0) {}
+SSLClientSessionCache::Entry::Entry(Entry&&) = default;
+SSLClientSessionCache::Entry::~Entry() = default;
+
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;
« no previous file with comments | « net/ssl/ssl_client_session_cache.h ('k') | net/ssl/ssl_client_session_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698