| 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 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/containers/mru_cache.h" | 15 #include "base/containers/mru_cache.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/memory_coordinator_client.h" | 17 #include "base/memory/memory_coordinator_client.h" |
| 18 #include "base/memory/memory_pressure_monitor.h" | 18 #include "base/memory/memory_pressure_monitor.h" |
| 19 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
| 20 #include "base/threading/thread_checker.h" | 20 #include "base/threading/thread_checker.h" |
| 21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "net/base/net_export.h" | 22 #include "net/base/net_export.h" |
| 23 #include "third_party/boringssl/src/include/openssl/base.h" | 23 #include "third_party/boringssl/src/include/openssl/base.h" |
| 24 | 24 |
| 25 namespace base { | 25 namespace base { |
| 26 class Clock; | 26 class Clock; |
| 27 namespace trace_event { |
| 28 class MemoryAllocatorDump; |
| 29 } |
| 27 } | 30 } |
| 28 | 31 |
| 29 namespace net { | 32 namespace net { |
| 30 | 33 |
| 31 class NET_EXPORT SSLClientSessionCache : public base::MemoryCoordinatorClient { | 34 class NET_EXPORT SSLClientSessionCache : public base::MemoryCoordinatorClient { |
| 32 public: | 35 public: |
| 33 struct Config { | 36 struct Config { |
| 34 // The maximum number of entries in the cache. | 37 // The maximum number of entries in the cache. |
| 35 size_t max_entries = 1024; | 38 size_t max_entries = 1024; |
| 36 // 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. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 49 // Inserts |session| into the cache at |cache_key|. If there is an existing | 52 // Inserts |session| into the cache at |cache_key|. If there is an existing |
| 50 // one, it is released. Every |expiration_check_count| calls, the cache is | 53 // one, it is released. Every |expiration_check_count| calls, the cache is |
| 51 // checked for stale entries. | 54 // checked for stale entries. |
| 52 void Insert(const std::string& cache_key, SSL_SESSION* session); | 55 void Insert(const std::string& cache_key, SSL_SESSION* session); |
| 53 | 56 |
| 54 // Removes all entries from the cache. | 57 // Removes all entries from the cache. |
| 55 void Flush(); | 58 void Flush(); |
| 56 | 59 |
| 57 void SetClockForTesting(std::unique_ptr<base::Clock> clock); | 60 void SetClockForTesting(std::unique_ptr<base::Clock> clock); |
| 58 | 61 |
| 62 void PopulateAllocatorDump( |
| 63 base::trace_event::MemoryAllocatorDump* dump) const ; |
| 59 private: | 64 private: |
| 60 // base::MemoryCoordinatorClient implementation: | 65 // base::MemoryCoordinatorClient implementation: |
| 61 void OnMemoryStateChange(base::MemoryState state) override; | 66 void OnMemoryStateChange(base::MemoryState state) override; |
| 62 | 67 |
| 63 // Returns true if |entry| is expired as of |now|. | 68 // Returns true if |entry| is expired as of |now|. |
| 64 bool IsExpired(SSL_SESSION* session, time_t now); | 69 bool IsExpired(SSL_SESSION* session, time_t now); |
| 65 | 70 |
| 66 // Removes all expired sessions from the cache. | 71 // Removes all expired sessions from the cache. |
| 67 void FlushExpiredSessions(); | 72 void FlushExpiredSessions(); |
| 68 | 73 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 81 base::Lock lock_; | 86 base::Lock lock_; |
| 82 | 87 |
| 83 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; | 88 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; |
| 84 | 89 |
| 85 DISALLOW_COPY_AND_ASSIGN(SSLClientSessionCache); | 90 DISALLOW_COPY_AND_ASSIGN(SSLClientSessionCache); |
| 86 }; | 91 }; |
| 87 | 92 |
| 88 } // namespace net | 93 } // namespace net |
| 89 | 94 |
| 90 #endif // NET_SSL_SSL_CLIENT_SESSION_CACHE_H | 95 #endif // NET_SSL_SSL_CLIENT_SESSION_CACHE_H |
| OLD | NEW |