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

Side by Side Diff: net/ssl/ssl_client_session_cache.h

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 unified diff | Download patch
« no previous file with comments | « net/socket/ssl_client_socket_impl.cc ('k') | net/ssl/ssl_client_session_cache.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_SSL_SSL_CLIENT_SESSION_CACHE_H_ 5 #ifndef NET_SSL_SSL_CLIENT_SESSION_CACHE_H_
6 #define NET_SSL_SSL_CLIENT_SESSION_CACHE_H_ 6 #define NET_SSL_SSL_CLIENT_SESSION_CACHE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <time.h> 9 #include <time.h>
10 10
(...skipping 28 matching lines...) Expand all
39 // The number of calls to Lookup before a new check for expired sessions. 39 // The number of calls to Lookup before a new check for expired sessions.
40 size_t expiration_check_count = 256; 40 size_t expiration_check_count = 256;
41 }; 41 };
42 42
43 explicit SSLClientSessionCache(const Config& config); 43 explicit SSLClientSessionCache(const Config& config);
44 ~SSLClientSessionCache() override; 44 ~SSLClientSessionCache() override;
45 45
46 size_t size() const; 46 size_t size() const;
47 47
48 // Returns the session associated with |cache_key| and moves it to the front 48 // Returns the session associated with |cache_key| and moves it to the front
49 // of the MRU list. Returns nullptr if there is none. 49 // of the MRU list. Returns nullptr if there is none. If |count| is non-null,
50 bssl::UniquePtr<SSL_SESSION> Lookup(const std::string& cache_key); 50 // |*count| will contain the number of times this session has been looked up
51 // (including this call).
52 bssl::UniquePtr<SSL_SESSION> Lookup(const std::string& cache_key, int* count);
53
54 // Resets the count returned by Lookup to 0 for the session associated with
55 // |cache_key|.
56 void ResetLookupCount(const std::string& cache_key);
51 57
52 // Inserts |session| into the cache at |cache_key|. If there is an existing 58 // Inserts |session| into the cache at |cache_key|. If there is an existing
53 // one, it is released. Every |expiration_check_count| calls, the cache is 59 // one, it is released. Every |expiration_check_count| calls, the cache is
54 // checked for stale entries. 60 // checked for stale entries.
55 void Insert(const std::string& cache_key, SSL_SESSION* session); 61 void Insert(const std::string& cache_key, SSL_SESSION* session);
56 62
57 // Removes all entries from the cache. 63 // Removes all entries from the cache.
58 void Flush(); 64 void Flush();
59 65
60 void SetClockForTesting(std::unique_ptr<base::Clock> clock); 66 void SetClockForTesting(std::unique_ptr<base::Clock> clock);
61 67
62 // Dumps memory allocation stats. |pmd| is the ProcessMemoryDump of the 68 // Dumps memory allocation stats. |pmd| is the ProcessMemoryDump of the
63 // browser process. 69 // browser process.
64 void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd); 70 void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd);
65 71
66 private: 72 private:
73 struct Entry {
74 Entry();
75 Entry(Entry&&);
76 ~Entry();
77
78 int lookups;
79 bssl::UniquePtr<SSL_SESSION> session;
80 };
81
67 // base::MemoryCoordinatorClient implementation: 82 // base::MemoryCoordinatorClient implementation:
68 void OnMemoryStateChange(base::MemoryState state) override; 83 void OnMemoryStateChange(base::MemoryState state) override;
69 84
70 // Returns true if |entry| is expired as of |now|. 85 // Returns true if |entry| is expired as of |now|.
71 bool IsExpired(SSL_SESSION* session, time_t now); 86 bool IsExpired(SSL_SESSION* session, time_t now);
72 87
73 // Removes all expired sessions from the cache. 88 // Removes all expired sessions from the cache.
74 void FlushExpiredSessions(); 89 void FlushExpiredSessions();
75 90
76 // Clear cache on low memory notifications callback. 91 // Clear cache on low memory notifications callback.
77 void OnMemoryPressure( 92 void OnMemoryPressure(
78 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); 93 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level);
79 94
80 std::unique_ptr<base::Clock> clock_; 95 std::unique_ptr<base::Clock> clock_;
81 Config config_; 96 Config config_;
82 base::HashingMRUCache<std::string, bssl::UniquePtr<SSL_SESSION>> cache_; 97 base::HashingMRUCache<std::string, Entry> cache_;
83 size_t lookups_since_flush_; 98 size_t lookups_since_flush_;
84 99
85 // TODO(davidben): After https://crbug.com/458365 is fixed, replace this with 100 // TODO(davidben): After https://crbug.com/458365 is fixed, replace this with
86 // a ThreadChecker. The session cache should be single-threaded like other 101 // a ThreadChecker. The session cache should be single-threaded like other
87 // classes in net. 102 // classes in net.
88 base::Lock lock_; 103 base::Lock lock_;
89 104
90 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; 105 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_;
91 106
92 DISALLOW_COPY_AND_ASSIGN(SSLClientSessionCache); 107 DISALLOW_COPY_AND_ASSIGN(SSLClientSessionCache);
93 }; 108 };
94 109
95 } // namespace net 110 } // namespace net
96 111
97 #endif // NET_SSL_SSL_CLIENT_SESSION_CACHE_H_ 112 #endif // NET_SSL_SSL_CLIENT_SESSION_CACHE_H_
OLDNEW
« no previous file with comments | « net/socket/ssl_client_socket_impl.cc ('k') | net/ssl/ssl_client_session_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698