Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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); | |
| 54 | |
| 55 // Resets the count returned by Lookup to 0. The SSL_SESSION returned by | |
| 56 // Lookup must be passed in, and the count will only be reset if the sessions | |
| 57 // are the same. This should be called when Lookup returns a non-null session | |
| 58 // and that session is used in a handshake. | |
| 59 void ResetLookupCount(const std::string& cache_key, SSL_SESSION* session); | |
| 51 | 60 |
| 52 // Inserts |session| into the cache at |cache_key|. If there is an existing | 61 // 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 | 62 // one, it is released. Every |expiration_check_count| calls, the cache is |
| 54 // checked for stale entries. | 63 // checked for stale entries. |
| 55 void Insert(const std::string& cache_key, SSL_SESSION* session); | 64 void Insert(const std::string& cache_key, SSL_SESSION* session); |
| 56 | 65 |
| 57 // Removes all entries from the cache. | 66 // Removes all entries from the cache. |
| 58 void Flush(); | 67 void Flush(); |
| 59 | 68 |
| 60 void SetClockForTesting(std::unique_ptr<base::Clock> clock); | 69 void SetClockForTesting(std::unique_ptr<base::Clock> clock); |
| 61 | 70 |
| 62 // Dumps memory allocation stats. |pmd| is the ProcessMemoryDump of the | 71 // Dumps memory allocation stats. |pmd| is the ProcessMemoryDump of the |
| 63 // browser process. | 72 // browser process. |
| 64 void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd); | 73 void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd); |
| 65 | 74 |
| 66 private: | 75 private: |
| 76 struct Entry { | |
| 77 Entry(); | |
| 78 Entry(Entry&&); | |
| 79 ~Entry(); | |
| 80 | |
| 81 size_t lookups; | |
|
davidben
2017/01/19 20:29:34
size_t is a little odd here. This is a count of th
nharper
2017/01/19 21:50:35
I'm fine with int. I'm only logging up to 20, and
| |
| 82 bssl::UniquePtr<SSL_SESSION> session; | |
| 83 }; | |
|
davidben
2017/01/19 20:29:34
[Does it work to just do:
struct Entry {
si
nharper
2017/01/19 21:50:35
That (with int instead of size_t) still trips up t
| |
| 84 | |
| 67 // base::MemoryCoordinatorClient implementation: | 85 // base::MemoryCoordinatorClient implementation: |
| 68 void OnMemoryStateChange(base::MemoryState state) override; | 86 void OnMemoryStateChange(base::MemoryState state) override; |
| 69 | 87 |
| 70 // Returns true if |entry| is expired as of |now|. | 88 // Returns true if |entry| is expired as of |now|. |
| 71 bool IsExpired(SSL_SESSION* session, time_t now); | 89 bool IsExpired(SSL_SESSION* session, time_t now); |
| 72 | 90 |
| 73 // Removes all expired sessions from the cache. | 91 // Removes all expired sessions from the cache. |
| 74 void FlushExpiredSessions(); | 92 void FlushExpiredSessions(); |
| 75 | 93 |
| 76 // Clear cache on low memory notifications callback. | 94 // Clear cache on low memory notifications callback. |
| 77 void OnMemoryPressure( | 95 void OnMemoryPressure( |
| 78 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); | 96 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); |
| 79 | 97 |
| 80 std::unique_ptr<base::Clock> clock_; | 98 std::unique_ptr<base::Clock> clock_; |
| 81 Config config_; | 99 Config config_; |
| 82 base::HashingMRUCache<std::string, bssl::UniquePtr<SSL_SESSION>> cache_; | 100 base::HashingMRUCache<std::string, Entry> cache_; |
| 83 size_t lookups_since_flush_; | 101 size_t lookups_since_flush_; |
| 84 | 102 |
| 85 // TODO(davidben): After https://crbug.com/458365 is fixed, replace this with | 103 // TODO(davidben): After https://crbug.com/458365 is fixed, replace this with |
| 86 // a ThreadChecker. The session cache should be single-threaded like other | 104 // a ThreadChecker. The session cache should be single-threaded like other |
| 87 // classes in net. | 105 // classes in net. |
| 88 base::Lock lock_; | 106 base::Lock lock_; |
| 89 | 107 |
| 90 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; | 108 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; |
| 91 | 109 |
| 92 DISALLOW_COPY_AND_ASSIGN(SSLClientSessionCache); | 110 DISALLOW_COPY_AND_ASSIGN(SSLClientSessionCache); |
| 93 }; | 111 }; |
| 94 | 112 |
| 95 } // namespace net | 113 } // namespace net |
| 96 | 114 |
| 97 #endif // NET_SSL_SSL_CLIENT_SESSION_CACHE_H_ | 115 #endif // NET_SSL_SSL_CLIENT_SESSION_CACHE_H_ |
| OLD | NEW |