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

Unified Diff: net/ssl/ssl_client_session_cache.cc

Issue 2625883002: SSLClientSessionCache: Log number of times Lookup is called per Session. (Closed)
Patch Set: reset count on handshake completion; log count from lookup 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
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..36cde1a88b34b05e7d6777949678ea7b90afaf78 100644
--- a/net/ssl/ssl_client_session_cache.cc
+++ b/net/ssl/ssl_client_session_cache.cc
@@ -17,6 +17,10 @@
namespace net {
+SSLClientSessionCache::Entry::Entry() : lookups(0) {}
+SSLClientSessionCache::Entry::Entry(Entry&&) = default;
+SSLClientSessionCache::Entry::~Entry() = default;
davidben 2017/01/19 20:29:34 Nit: Order these matching the header.
nharper 2017/01/19 21:50:35 They're both in the same order (c'tor, move c'tor,
+
SSLClientSessionCache::SSLClientSessionCache(const Config& config)
: clock_(new base::DefaultClock),
config_(config),
@@ -37,7 +41,8 @@ size_t SSLClientSessionCache::size() const {
}
bssl::UniquePtr<SSL_SESSION> SSLClientSessionCache::Lookup(
- const std::string& cache_key) {
+ const std::string& cache_key,
+ size_t* count) {
base::AutoLock lock(lock_);
// Expire stale sessions.
@@ -47,26 +52,51 @@ 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,
+ SSL_SESSION* session) {
+ 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.session.get() != session)
+ 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 +131,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 +158,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;

Powered by Google App Engine
This is Rietveld 408576698