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 #include "net/ssl/ssl_client_session_cache.h" | 5 #include "net/ssl/ssl_client_session_cache.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
| 9 #include "base/memory/memory_coordinator_client_registry.h" |
9 #include "base/time/clock.h" | 10 #include "base/time/clock.h" |
10 #include "base/time/default_clock.h" | 11 #include "base/time/default_clock.h" |
11 | 12 |
12 namespace net { | 13 namespace net { |
13 | 14 |
14 SSLClientSessionCache::SSLClientSessionCache(const Config& config) | 15 SSLClientSessionCache::SSLClientSessionCache(const Config& config) |
15 : clock_(new base::DefaultClock), | 16 : clock_(new base::DefaultClock), |
16 config_(config), | 17 config_(config), |
17 cache_(config.max_entries), | 18 cache_(config.max_entries), |
18 lookups_since_flush_(0) { | 19 lookups_since_flush_(0) { |
19 memory_pressure_listener_.reset(new base::MemoryPressureListener(base::Bind( | 20 memory_pressure_listener_.reset(new base::MemoryPressureListener(base::Bind( |
20 &SSLClientSessionCache::OnMemoryPressure, base::Unretained(this)))); | 21 &SSLClientSessionCache::OnMemoryPressure, base::Unretained(this)))); |
| 22 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); |
21 } | 23 } |
22 | 24 |
23 SSLClientSessionCache::~SSLClientSessionCache() { | 25 SSLClientSessionCache::~SSLClientSessionCache() { |
24 Flush(); | 26 Flush(); |
| 27 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this); |
25 } | 28 } |
26 | 29 |
27 size_t SSLClientSessionCache::size() const { | 30 size_t SSLClientSessionCache::size() const { |
28 return cache_.size(); | 31 return cache_.size(); |
29 } | 32 } |
30 | 33 |
31 ScopedSSL_SESSION SSLClientSessionCache::Lookup(const std::string& cache_key) { | 34 ScopedSSL_SESSION SSLClientSessionCache::Lookup(const std::string& cache_key) { |
32 base::AutoLock lock(lock_); | 35 base::AutoLock lock(lock_); |
33 | 36 |
34 // Expire stale sessions. | 37 // Expire stale sessions. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 break; | 108 break; |
106 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE: | 109 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE: |
107 FlushExpiredSessions(); | 110 FlushExpiredSessions(); |
108 break; | 111 break; |
109 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL: | 112 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL: |
110 Flush(); | 113 Flush(); |
111 break; | 114 break; |
112 } | 115 } |
113 } | 116 } |
114 | 117 |
| 118 void SSLClientSessionCache::OnMemoryStateChange(base::MemoryState state) { |
| 119 // TODO(hajimehoshi): When the state changes, adjust the sizes of the caches |
| 120 // to reduce the limits. SSLClientSessionCache doesn't have the ability to |
| 121 // limit at present. |
| 122 switch (state) { |
| 123 case base::MemoryState::NORMAL: |
| 124 break; |
| 125 case base::MemoryState::THROTTLED: |
| 126 Flush(); |
| 127 break; |
| 128 case base::MemoryState::SUSPENDED: |
| 129 // Note: Not supported at present. Fall through. |
| 130 case base::MemoryState::UNKNOWN: |
| 131 NOTREACHED(); |
| 132 break; |
| 133 } |
| 134 } |
| 135 |
115 } // namespace net | 136 } // namespace net |
OLD | NEW |