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

Side by Side 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: sleevi comments Created 5 years, 8 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef NET_SSL_SSL_CLIENT_SESSION_CACHE_OPENSSL_H
6 #define NET_SSL_SSL_CLIENT_SESSION_CACHE_OPENSSL_H
7
8 #include <openssl/ssl.h>
9
10 #include <string>
11
12 #include "base/containers/mru_cache.h"
13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/threading/thread_checker.h"
16 #include "base/time/time.h"
17 #include "net/base/net_export.h"
18
19 namespace base {
20 class Clock;
21 }
22
23 namespace net {
24
25 class NET_EXPORT SSLClientSessionCacheOpenSSL {
26 public:
27 struct Config {
28 // The maximum number of entries in the cache.
29 size_t max_entries = 1024;
30 // The number of calls to Lookup before a new check for expired sessions.
31 size_t expiration_check_count = 256;
32 // How long each session should last.
33 base::TimeDelta timeout = base::TimeDelta::FromHours(1);
34 };
35
36 explicit SSLClientSessionCacheOpenSSL(const Config& config);
37 ~SSLClientSessionCacheOpenSSL();
38
39 size_t size() const;
40
41 // Returns the session associated with |cache_key| and moves it to the front
42 // of the MRU list. Returns null if there is none. The caller is responsible
43 // for taking a reference to the pointer if the cache is destroyed or a call
44 // to Insert is made.
45 SSL_SESSION* Lookup(const std::string& cache_key);
46
47 // Inserts |session| into the cache at |cache_key|. If there is an existing
48 // one, it is released. Every |expiration_check_count| calls, the cache is
49 // checked for stale entries.
50 void Insert(const std::string& cache_key, SSL_SESSION* session);
51
52 // Removes all entries from the cache.
53 void Flush();
54
55 void SetClockForTesting(scoped_ptr<base::Clock> clock);
56
57 private:
58 struct CacheEntry;
59
60 using CacheEntryMap =
61 base::MRUCacheBase<std::string,
62 CacheEntry*,
63 base::MRUCachePointerDeletor<CacheEntry*>,
64 base::MRUCacheHashMap>;
65
66 // Returns true if |entry| is expired as of |now|.
67 bool IsExpired(CacheEntry* entry, base::Time now);
68
69 // Removes all expired sessions from the cache.
70 void FlushExpiredSessions();
71
72 scoped_ptr<base::Clock> clock_;
73 Config config_;
74 CacheEntryMap cache_;
75 size_t lookups_since_flush_;
76
77 base::ThreadChecker thread_checker_;
78
79 DISALLOW_COPY_AND_ASSIGN(SSLClientSessionCacheOpenSSL);
80 };
81
82 } // namespace net
83
84 #endif // NET_SSL_SSL_CLIENT_SESSION_CACHE_OPENSSL_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698