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

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
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,
53 size_t* count);
davidben 2017/01/19 21:56:12 size_t => int to match
nharper 2017/01/19 22:09:07 Done.
54
55 // Resets the count returned by Lookup to 0 for the session associated with
56 // |cache_key|.
57 void ResetLookupCount(const std::string& cache_key);
51 58
52 // Inserts |session| into the cache at |cache_key|. If there is an existing 59 // 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 60 // one, it is released. Every |expiration_check_count| calls, the cache is
54 // checked for stale entries. 61 // checked for stale entries.
55 void Insert(const std::string& cache_key, SSL_SESSION* session); 62 void Insert(const std::string& cache_key, SSL_SESSION* session);
56 63
57 // Removes all entries from the cache. 64 // Removes all entries from the cache.
58 void Flush(); 65 void Flush();
59 66
60 void SetClockForTesting(std::unique_ptr<base::Clock> clock); 67 void SetClockForTesting(std::unique_ptr<base::Clock> clock);
61 68
62 // Dumps memory allocation stats. |pmd| is the ProcessMemoryDump of the 69 // Dumps memory allocation stats. |pmd| is the ProcessMemoryDump of the
63 // browser process. 70 // browser process.
64 void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd); 71 void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd);
65 72
66 private: 73 private:
74 struct Entry {
75 Entry();
76 Entry(Entry&&);
77 ~Entry();
78
79 int lookups;
80 bssl::UniquePtr<SSL_SESSION> session;
81 };
82
67 // base::MemoryCoordinatorClient implementation: 83 // base::MemoryCoordinatorClient implementation:
68 void OnMemoryStateChange(base::MemoryState state) override; 84 void OnMemoryStateChange(base::MemoryState state) override;
69 85
70 // Returns true if |entry| is expired as of |now|. 86 // Returns true if |entry| is expired as of |now|.
71 bool IsExpired(SSL_SESSION* session, time_t now); 87 bool IsExpired(SSL_SESSION* session, time_t now);
72 88
73 // Removes all expired sessions from the cache. 89 // Removes all expired sessions from the cache.
74 void FlushExpiredSessions(); 90 void FlushExpiredSessions();
75 91
76 // Clear cache on low memory notifications callback. 92 // Clear cache on low memory notifications callback.
77 void OnMemoryPressure( 93 void OnMemoryPressure(
78 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); 94 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level);
79 95
80 std::unique_ptr<base::Clock> clock_; 96 std::unique_ptr<base::Clock> clock_;
81 Config config_; 97 Config config_;
82 base::HashingMRUCache<std::string, bssl::UniquePtr<SSL_SESSION>> cache_; 98 base::HashingMRUCache<std::string, Entry> cache_;
83 size_t lookups_since_flush_; 99 size_t lookups_since_flush_;
84 100
85 // TODO(davidben): After https://crbug.com/458365 is fixed, replace this with 101 // TODO(davidben): After https://crbug.com/458365 is fixed, replace this with
86 // a ThreadChecker. The session cache should be single-threaded like other 102 // a ThreadChecker. The session cache should be single-threaded like other
87 // classes in net. 103 // classes in net.
88 base::Lock lock_; 104 base::Lock lock_;
89 105
90 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; 106 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_;
91 107
92 DISALLOW_COPY_AND_ASSIGN(SSLClientSessionCache); 108 DISALLOW_COPY_AND_ASSIGN(SSLClientSessionCache);
93 }; 109 };
94 110
95 } // namespace net 111 } // namespace net
96 112
97 #endif // NET_SSL_SSL_CLIENT_SESSION_CACHE_H_ 113 #endif // NET_SSL_SSL_CLIENT_SESSION_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698