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

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
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..73186b876a195d7fef80eb27a0e6a2c710e00fb2 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 21:56:12 Oh, I meant order relative to the other methods. I
nharper 2017/01/19 22:09:07 I moved them so the ordering in the .cc is closer
+
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,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 +129,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) {
@@ -127,7 +155,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