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

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: use base::MRUCache (hah, that would have saved me some time...) 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 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 "base/containers/mru_cache.h"
9 #include "base/macros.h"
10 #include "base/threading/non_thread_safe.h"
11 #include "base/time/time.h"
12 #include "net/base/net_export.h"
13 #include "net/ssl/scoped_openssl_types.h"
14
15 namespace net {
16
17 class NET_EXPORT SSLClientSessionCacheOpenSSL : public base::NonThreadSafe {
Ryan Sleevi 2015/03/17 00:50:33 grumblenit: I dislike inheritance from traits clas
davidben 2015/03/20 22:41:27 Done.
18 public:
19 struct Config {
20 Config();
Ryan Sleevi 2015/03/17 00:50:34 http://google-styleguide.googlecode.com/svn/trunk/
davidben 2015/03/20 22:41:27 Done, although I'm unclear... the syntax I went wi
21
22 // The maximum number of entries in the cache.
23 size_t max_entries;
24 // The number of calls to Lookup before a new check for expired sessions.
25 size_t expiration_check_count;
26 // How long each session should last.
27 base::TimeDelta timeout;
28 };
29
30 explicit SSLClientSessionCacheOpenSSL(const Config& config);
31 ~SSLClientSessionCacheOpenSSL();
Ryan Sleevi 2015/03/17 00:50:34 If you have virtual methods, you should have a vir
davidben 2015/03/20 22:41:27 Done.
32
33 size_t size() { return cache_.size(); }
Ryan Sleevi 2015/03/17 00:50:34 1) const 2) Don't inline this; you have no idea wh
davidben 2015/03/20 22:41:27 Done.
34
35 // Returns the entry associated with |cache_key| or null if there is none. The
36 // caller is responsible for taking a reference to the pointer if the cache is
37 // destroyed or a call to Insert is made.
38 SSL_SESSION* Lookup(const std::string& cache_key);
Ryan Sleevi 2015/03/17 00:50:34 const? non-const?
davidben 2015/03/20 22:41:27 Non-const. It updates the MRU. base::MRUCache is t
39
40 // Inserts |session| into the cache at |cache_key|. If there is an existing
41 // one, it is released. Every |expiration_check_count| calls, the cache is
42 // checked for stale entries.
43 void Insert(const std::string& cache_key, SSL_SESSION* session);
44
45 // Removes all entries from the cache.
46 void Flush();
47
48 protected:
49 // Overridable base::Time::Now wrapper for testing.
50 virtual base::Time Now();
Ryan Sleevi 2015/03/17 00:50:34 Rather than inheritance for testing, why not use a
davidben 2015/03/20 22:41:27 Done.
51
52 private:
53 struct CacheEntry {
54 CacheEntry();
55 ~CacheEntry();
56
57 ScopedSSL_SESSION session;
58 // The time at which this entry expires.
59 base::Time expiration;
Ryan Sleevi 2015/03/17 00:50:34 base::TimeTicks, I would presume; otherwise, if th
davidben 2015/03/20 22:41:27 I used that initially, but I think it actually doe
60 };
61 using CacheEntryMap =
Ryan Sleevi 2015/03/17 00:50:34 newline
davidben 2015/03/20 22:41:27 Done.
62 base::MRUCacheBase<std::string,
63 CacheEntry*,
64 base::MRUCachePointerDeletor<CacheEntry*>,
65 base::MRUCacheHashMap>;
66
67 // Removes all expired sessions from the cache.
68 void FlushExpiredSessions();
69
70 Config config_;
71 CacheEntryMap cache_;
72 size_t lookups_since_flush_;
73
74 DISALLOW_COPY_AND_ASSIGN(SSLClientSessionCacheOpenSSL);
75 };
76
77 } // namespace net
78
79 #endif // NET_SSL_SSL_CLIENT_SESSION_CACHE_OPENSSL_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698