Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(525)

Side by Side Diff: net/ssl/ssl_client_session_cache.cc

Issue 2400033005: Use BoringSSL scopers in //net. (Closed)
Patch Set: eroman comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/ssl/ssl_client_session_cache.h ('k') | net/ssl/ssl_client_session_cache_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <openssl/ssl.h>
8
7 #include <utility> 9 #include <utility>
8 10
9 #include "base/memory/memory_coordinator_client_registry.h" 11 #include "base/memory/memory_coordinator_client_registry.h"
10 #include "base/time/clock.h" 12 #include "base/time/clock.h"
11 #include "base/time/default_clock.h" 13 #include "base/time/default_clock.h"
12 14
13 namespace net { 15 namespace net {
14 16
15 SSLClientSessionCache::SSLClientSessionCache(const Config& config) 17 SSLClientSessionCache::SSLClientSessionCache(const Config& config)
16 : clock_(new base::DefaultClock), 18 : clock_(new base::DefaultClock),
17 config_(config), 19 config_(config),
18 cache_(config.max_entries), 20 cache_(config.max_entries),
19 lookups_since_flush_(0) { 21 lookups_since_flush_(0) {
20 memory_pressure_listener_.reset(new base::MemoryPressureListener(base::Bind( 22 memory_pressure_listener_.reset(new base::MemoryPressureListener(base::Bind(
21 &SSLClientSessionCache::OnMemoryPressure, base::Unretained(this)))); 23 &SSLClientSessionCache::OnMemoryPressure, base::Unretained(this))));
22 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); 24 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this);
23 } 25 }
24 26
25 SSLClientSessionCache::~SSLClientSessionCache() { 27 SSLClientSessionCache::~SSLClientSessionCache() {
26 Flush(); 28 Flush();
27 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this); 29 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this);
28 } 30 }
29 31
30 size_t SSLClientSessionCache::size() const { 32 size_t SSLClientSessionCache::size() const {
31 return cache_.size(); 33 return cache_.size();
32 } 34 }
33 35
34 ScopedSSL_SESSION SSLClientSessionCache::Lookup(const std::string& cache_key) { 36 bssl::UniquePtr<SSL_SESSION> SSLClientSessionCache::Lookup(
37 const std::string& cache_key) {
35 base::AutoLock lock(lock_); 38 base::AutoLock lock(lock_);
36 39
37 // Expire stale sessions. 40 // Expire stale sessions.
38 lookups_since_flush_++; 41 lookups_since_flush_++;
39 if (lookups_since_flush_ >= config_.expiration_check_count) { 42 if (lookups_since_flush_ >= config_.expiration_check_count) {
40 lookups_since_flush_ = 0; 43 lookups_since_flush_ = 0;
41 FlushExpiredSessions(); 44 FlushExpiredSessions();
42 } 45 }
43 46
44 CacheEntryMap::iterator iter = cache_.Get(cache_key); 47 CacheEntryMap::iterator iter = cache_.Get(cache_key);
45 if (iter == cache_.end()) 48 if (iter == cache_.end())
46 return nullptr; 49 return nullptr;
47 if (IsExpired(iter->second.get(), clock_->Now())) { 50 if (IsExpired(iter->second.get(), clock_->Now())) {
48 cache_.Erase(iter); 51 cache_.Erase(iter);
49 return nullptr; 52 return nullptr;
50 } 53 }
51 54
52 SSL_SESSION* session = iter->second->session.get(); 55 SSL_SESSION* session = iter->second->session.get();
53 SSL_SESSION_up_ref(session); 56 SSL_SESSION_up_ref(session);
54 return ScopedSSL_SESSION(session); 57 return bssl::UniquePtr<SSL_SESSION>(session);
55 } 58 }
56 59
57 void SSLClientSessionCache::Insert(const std::string& cache_key, 60 void SSLClientSessionCache::Insert(const std::string& cache_key,
58 SSL_SESSION* session) { 61 SSL_SESSION* session) {
59 base::AutoLock lock(lock_); 62 base::AutoLock lock(lock_);
60 63
61 // Make a new entry. 64 // Make a new entry.
62 std::unique_ptr<CacheEntry> entry(new CacheEntry); 65 std::unique_ptr<CacheEntry> entry(new CacheEntry);
63 SSL_SESSION_up_ref(session); 66 SSL_SESSION_up_ref(session);
64 entry->session.reset(session); 67 entry->session.reset(session);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 break; 130 break;
128 case base::MemoryState::SUSPENDED: 131 case base::MemoryState::SUSPENDED:
129 // Note: Not supported at present. Fall through. 132 // Note: Not supported at present. Fall through.
130 case base::MemoryState::UNKNOWN: 133 case base::MemoryState::UNKNOWN:
131 NOTREACHED(); 134 NOTREACHED();
132 break; 135 break;
133 } 136 }
134 } 137 }
135 138
136 } // namespace net 139 } // namespace net
OLDNEW
« no previous file with comments | « net/ssl/ssl_client_session_cache.h ('k') | net/ssl/ssl_client_session_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698