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

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

Powered by Google App Engine
This is Rietveld 408576698