| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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. |
| 50 bssl::UniquePtr<SSL_SESSION> Lookup(const std::string& cache_key); | 50 bssl::UniquePtr<SSL_SESSION> Lookup(const std::string& cache_key); |
| 51 | 51 |
| 52 // If Lookup returns a non-null pointer, this method must be called once the |
| 53 // TLS handshake done with the session from Lookup has completed. If |
| 54 // |should_log| is true, the number of concurrent lookups will be logged to |
| 55 // UMA once the count has reached 0. |
| 56 void DecrementLookupCount(const std::string& cache_key, bool should_log); |
| 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 public: |
| 75 Entry(); |
| 76 Entry(Entry&&); |
| 77 ~Entry(); |
| 78 |
| 79 size_t active_lookups; |
| 80 size_t max_lookups; |
| 81 bool should_log; |
| 82 bssl::UniquePtr<SSL_SESSION> session; |
| 83 }; |
| 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 |