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/time/clock.h" | 9 #include "base/time/clock.h" |
10 #include "base/time/default_clock.h" | 10 #include "base/time/default_clock.h" |
11 | 11 |
12 namespace net { | 12 namespace net { |
13 | 13 |
14 SSLClientSessionCache::SSLClientSessionCache(const Config& config) | 14 SSLClientSessionCache::SSLClientSessionCache(const Config& config) |
15 : clock_(new base::DefaultClock), | 15 : clock_(new base::DefaultClock), |
16 config_(config), | 16 config_(config), |
17 cache_(config.max_entries), | 17 cache_(config.max_entries), |
18 lookups_since_flush_(0) {} | 18 lookups_since_flush_(0) { |
| 19 memory_pressure_listener_.reset(new base::MemoryPressureListener(base::Bind( |
| 20 &SSLClientSessionCache::OnMemoryPressure, base::Unretained(this)))); |
| 21 } |
19 | 22 |
20 SSLClientSessionCache::~SSLClientSessionCache() { | 23 SSLClientSessionCache::~SSLClientSessionCache() { |
21 Flush(); | 24 Flush(); |
22 } | 25 } |
23 | 26 |
24 size_t SSLClientSessionCache::size() const { | 27 size_t SSLClientSessionCache::size() const { |
25 return cache_.size(); | 28 return cache_.size(); |
26 } | 29 } |
27 | 30 |
28 ScopedSSL_SESSION SSLClientSessionCache::Lookup(const std::string& cache_key) { | 31 ScopedSSL_SESSION SSLClientSessionCache::Lookup(const std::string& cache_key) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 CacheEntryMap::iterator iter = cache_.begin(); | 87 CacheEntryMap::iterator iter = cache_.begin(); |
85 while (iter != cache_.end()) { | 88 while (iter != cache_.end()) { |
86 if (IsExpired(iter->second.get(), now)) { | 89 if (IsExpired(iter->second.get(), now)) { |
87 iter = cache_.Erase(iter); | 90 iter = cache_.Erase(iter); |
88 } else { | 91 } else { |
89 ++iter; | 92 ++iter; |
90 } | 93 } |
91 } | 94 } |
92 } | 95 } |
93 | 96 |
| 97 void SSLClientSessionCache::OnMemoryPressure( |
| 98 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| 99 switch (memory_pressure_level) { |
| 100 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE: |
| 101 break; |
| 102 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE: |
| 103 FlushExpiredSessions(); |
| 104 break; |
| 105 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL: |
| 106 Flush(); |
| 107 break; |
| 108 } |
| 109 } |
| 110 |
94 } // namespace net | 111 } // namespace net |
OLD | NEW |