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

Unified Diff: net/ssl/ssl_client_session_cache_openssl.h

Issue 994263002: Rewrite session cache in OpenSSL ports. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rsleevi comments (buh, also a rebase, sorry) Created 5 years, 9 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_openssl.h
diff --git a/net/ssl/ssl_client_session_cache_openssl.h b/net/ssl/ssl_client_session_cache_openssl.h
new file mode 100644
index 0000000000000000000000000000000000000000..dccce8e31842fcc344f4078428796a1a103e707f
--- /dev/null
+++ b/net/ssl/ssl_client_session_cache_openssl.h
@@ -0,0 +1,88 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_SSL_SSL_CLIENT_SESSION_CACHE_OPENSSL_H
+#define NET_SSL_SSL_CLIENT_SESSION_CACHE_OPENSSL_H
+
+#include "base/containers/mru_cache.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/threading/thread_checker.h"
+#include "base/time/time.h"
+#include "net/base/net_export.h"
+#include "net/ssl/scoped_openssl_types.h"
+
+namespace base {
+class Clock;
+}
+
+namespace net {
+
+class NET_EXPORT SSLClientSessionCacheOpenSSL {
+ public:
+ struct Config {
+ // The maximum number of entries in the cache.
+ size_t max_entries = 1024;
+ // The number of calls to Lookup before a new check for expired sessions.
+ size_t expiration_check_count = 256;
+ // How long each session should last.
+ base::TimeDelta timeout = base::TimeDelta::FromHours(1);
+ };
+
+ explicit SSLClientSessionCacheOpenSSL(const Config& config);
+ virtual ~SSLClientSessionCacheOpenSSL();
Ryan Sleevi 2015/04/02 06:53:15 This doesn't need to be virtual, does it? No vtabl
davidben 2015/04/02 19:05:10 Done. (Remnant of virtual Now method)
+
+ size_t size() const;
+
+ // Returns the session associated with |cache_key| and moves it to the front
+ // of the MRU list. Returns null if there is none. The caller is responsible
+ // for taking a reference to the pointer if the cache is destroyed or a call
+ // to Insert is made.
+ SSL_SESSION* Lookup(const std::string& cache_key);
+
+ // Inserts |session| into the cache at |cache_key|. If there is an existing
+ // one, it is released. Every |expiration_check_count| calls, the cache is
+ // checked for stale entries.
+ void Insert(const std::string& cache_key, SSL_SESSION* session);
+
+ // Removes all entries from the cache.
+ void Flush();
+
+ void SetClockForTesting(scoped_ptr<base::Clock> clock);
+
+ private:
+ struct CacheEntry {
Ryan Sleevi 2015/04/02 06:53:15 I probably asked this earlier, but since you're st
davidben 2015/04/02 19:05:10 I believe you're right. Done. (I had to break head
davidben 2015/04/03 00:37:11 This seems to upset win8_chromium_rel. I've moved
+ CacheEntry();
+ ~CacheEntry();
+
+ // Returns true if the cache entry is expired as of |now|.
+ bool IsExpired(base::Time now);
+
+ ScopedSSL_SESSION session;
+ // The time at which this entry expires.
+ base::Time expiration;
+ };
+
+ using CacheEntryMap =
+ base::MRUCacheBase<std::string,
+ CacheEntry*,
+ base::MRUCachePointerDeletor<CacheEntry*>,
+ base::MRUCacheHashMap>;
+
+ // Removes all expired sessions from the cache.
+ void FlushExpiredSessions();
+
+ scoped_ptr<base::Clock> clock_;
+ Config config_;
+ CacheEntryMap cache_;
+ size_t lookups_since_flush_;
+
+ base::ThreadChecker thread_checker_;
+
+ DISALLOW_COPY_AND_ASSIGN(SSLClientSessionCacheOpenSSL);
+};
+
+} // namespace net
+
+#endif // NET_SSL_SSL_CLIENT_SESSION_CACHE_OPENSSL_H

Powered by Google App Engine
This is Rietveld 408576698