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_openssl.h" | 5 #include "net/ssl/ssl_client_session_cache_openssl.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" |
(...skipping 22 matching lines...) Expand all Loading... |
33 // Expire stale sessions. | 33 // Expire stale sessions. |
34 lookups_since_flush_++; | 34 lookups_since_flush_++; |
35 if (lookups_since_flush_ >= config_.expiration_check_count) { | 35 if (lookups_since_flush_ >= config_.expiration_check_count) { |
36 lookups_since_flush_ = 0; | 36 lookups_since_flush_ = 0; |
37 FlushExpiredSessions(); | 37 FlushExpiredSessions(); |
38 } | 38 } |
39 | 39 |
40 CacheEntryMap::iterator iter = cache_.Get(cache_key); | 40 CacheEntryMap::iterator iter = cache_.Get(cache_key); |
41 if (iter == cache_.end()) | 41 if (iter == cache_.end()) |
42 return nullptr; | 42 return nullptr; |
43 if (IsExpired(iter->second, clock_->Now())) { | 43 if (IsExpired(iter->second.get(), clock_->Now())) { |
44 cache_.Erase(iter); | 44 cache_.Erase(iter); |
45 return nullptr; | 45 return nullptr; |
46 } | 46 } |
47 return ScopedSSL_SESSION(SSL_SESSION_up_ref(iter->second->session.get())); | 47 return ScopedSSL_SESSION(SSL_SESSION_up_ref(iter->second->session.get())); |
48 } | 48 } |
49 | 49 |
50 void SSLClientSessionCacheOpenSSL::Insert(const std::string& cache_key, | 50 void SSLClientSessionCacheOpenSSL::Insert(const std::string& cache_key, |
51 SSL_SESSION* session) { | 51 SSL_SESSION* session) { |
52 base::AutoLock lock(lock_); | 52 base::AutoLock lock(lock_); |
53 | 53 |
54 // Make a new entry. | 54 // Make a new entry. |
55 CacheEntry* entry = new CacheEntry; | 55 scoped_ptr<CacheEntry> entry(new CacheEntry); |
56 entry->session.reset(SSL_SESSION_up_ref(session)); | 56 entry->session.reset(SSL_SESSION_up_ref(session)); |
57 entry->creation_time = clock_->Now(); | 57 entry->creation_time = clock_->Now(); |
58 | 58 |
59 // Takes ownership. | 59 // Takes ownership. |
60 cache_.Put(cache_key, entry); | 60 cache_.Put(cache_key, std::move(entry)); |
61 } | 61 } |
62 | 62 |
63 void SSLClientSessionCacheOpenSSL::Flush() { | 63 void SSLClientSessionCacheOpenSSL::Flush() { |
64 base::AutoLock lock(lock_); | 64 base::AutoLock lock(lock_); |
65 | 65 |
66 cache_.Clear(); | 66 cache_.Clear(); |
67 } | 67 } |
68 | 68 |
69 void SSLClientSessionCacheOpenSSL::SetClockForTesting( | 69 void SSLClientSessionCacheOpenSSL::SetClockForTesting( |
70 scoped_ptr<base::Clock> clock) { | 70 scoped_ptr<base::Clock> clock) { |
(...skipping 10 matching lines...) Expand all Loading... |
81 SSLClientSessionCacheOpenSSL::CacheEntry* entry, | 81 SSLClientSessionCacheOpenSSL::CacheEntry* entry, |
82 const base::Time& now) { | 82 const base::Time& now) { |
83 return now < entry->creation_time || | 83 return now < entry->creation_time || |
84 entry->creation_time + config_.timeout < now; | 84 entry->creation_time + config_.timeout < now; |
85 } | 85 } |
86 | 86 |
87 void SSLClientSessionCacheOpenSSL::FlushExpiredSessions() { | 87 void SSLClientSessionCacheOpenSSL::FlushExpiredSessions() { |
88 base::Time now = clock_->Now(); | 88 base::Time now = clock_->Now(); |
89 CacheEntryMap::iterator iter = cache_.begin(); | 89 CacheEntryMap::iterator iter = cache_.begin(); |
90 while (iter != cache_.end()) { | 90 while (iter != cache_.end()) { |
91 if (IsExpired(iter->second, now)) { | 91 if (IsExpired(iter->second.get(), now)) { |
92 iter = cache_.Erase(iter); | 92 iter = cache_.Erase(iter); |
93 } else { | 93 } else { |
94 ++iter; | 94 ++iter; |
95 } | 95 } |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 } // namespace net | 99 } // namespace net |
OLD | NEW |