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

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

Issue 2541093003: Instrument SSL sockets using MemoryDumpProvider (Closed)
Patch Set: Fix flaky test Created 4 years 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 <utility> 7 #include <utility>
8 8
9 #include "base/memory/memory_coordinator_client_registry.h" 9 #include "base/memory/memory_coordinator_client_registry.h"
10 #include "base/strings/stringprintf.h"
10 #include "base/time/clock.h" 11 #include "base/time/clock.h"
11 #include "base/time/default_clock.h" 12 #include "base/time/default_clock.h"
13 #include "base/trace_event/process_memory_dump.h"
14 #include "net/cert/x509_util_openssl.h"
12 #include "third_party/boringssl/src/include/openssl/ssl.h" 15 #include "third_party/boringssl/src/include/openssl/ssl.h"
16 #include "third_party/boringssl/src/include/openssl/x509.h"
13 17
14 namespace net { 18 namespace net {
15 19
16 SSLClientSessionCache::SSLClientSessionCache(const Config& config) 20 SSLClientSessionCache::SSLClientSessionCache(const Config& config)
17 : clock_(new base::DefaultClock), 21 : clock_(new base::DefaultClock),
18 config_(config), 22 config_(config),
19 cache_(config.max_entries), 23 cache_(config.max_entries),
20 lookups_since_flush_(0) { 24 lookups_since_flush_(0) {
21 memory_pressure_listener_.reset(new base::MemoryPressureListener(base::Bind( 25 memory_pressure_listener_.reset(new base::MemoryPressureListener(base::Bind(
22 &SSLClientSessionCache::OnMemoryPressure, base::Unretained(this)))); 26 &SSLClientSessionCache::OnMemoryPressure, base::Unretained(this))));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 std::unique_ptr<base::Clock> clock) { 79 std::unique_ptr<base::Clock> clock) {
76 clock_ = std::move(clock); 80 clock_ = std::move(clock);
77 } 81 }
78 82
79 bool SSLClientSessionCache::IsExpired(SSL_SESSION* session, time_t now) { 83 bool SSLClientSessionCache::IsExpired(SSL_SESSION* session, time_t now) {
80 return now < SSL_SESSION_get_time(session) || 84 return now < SSL_SESSION_get_time(session) ||
81 now >= 85 now >=
82 SSL_SESSION_get_time(session) + SSL_SESSION_get_timeout(session); 86 SSL_SESSION_get_time(session) + SSL_SESSION_get_timeout(session);
83 } 87 }
84 88
89 void SSLClientSessionCache::DumpMemoryStats(
90 base::trace_event::ProcessMemoryDump* pmd) {
91 std::string absolute_name = "net/ssl_session_cache";
92 base::trace_event::MemoryAllocatorDump* cache_dump =
93 pmd->GetAllocatorDump(absolute_name);
94 // This method can be reached from different URLRequestContexts. Since this is
95 // a singleton, only log memory stats once.
96 // TODO(xunjieli): Change this once crbug.com/458365 is fixed.
97 if (cache_dump)
98 return;
99 cache_dump = pmd->CreateAllocatorDump(absolute_name);
100 base::AutoLock lock(lock_);
101 for (const auto& pair : cache_) {
102 auto entry = pair.second.get();
103 auto cert_chain = entry->x509_chain;
104 size_t cert_count = sk_X509_num(cert_chain);
105 base::trace_event::MemoryAllocatorDump* entry_dump =
106 pmd->CreateAllocatorDump(
107 base::StringPrintf("%s/entry_%p", absolute_name.c_str(), entry));
108 int cert_size = 0;
109 for (size_t i = 0; i < cert_count; ++i) {
110 X509* cert = sk_X509_value(cert_chain, i);
111 cert_size += i2d_X509(cert, nullptr);
112 }
113 // This measures the lower bound of the serialized certificate. It doesn't
114 // measure the actual memory used, which is 4x this amount (see
115 // crbug.com/671420 for more details).
116 entry_dump->AddScalar("cert_size",
117 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
118 cert_size);
119 entry_dump->AddScalar("serialized_cert_count",
120 base::trace_event::MemoryAllocatorDump::kUnitsObjects,
121 cert_count);
122 entry_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
123 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
124 cert_size);
125 }
126 }
127
85 void SSLClientSessionCache::FlushExpiredSessions() { 128 void SSLClientSessionCache::FlushExpiredSessions() {
86 time_t now = clock_->Now().ToTimeT(); 129 time_t now = clock_->Now().ToTimeT();
87 auto iter = cache_.begin(); 130 auto iter = cache_.begin();
88 while (iter != cache_.end()) { 131 while (iter != cache_.end()) {
89 if (IsExpired(iter->second.get(), now)) { 132 if (IsExpired(iter->second.get(), now)) {
90 iter = cache_.Erase(iter); 133 iter = cache_.Erase(iter);
91 } else { 134 } else {
92 ++iter; 135 ++iter;
93 } 136 }
94 } 137 }
(...skipping 25 matching lines...) Expand all
120 break; 163 break;
121 case base::MemoryState::SUSPENDED: 164 case base::MemoryState::SUSPENDED:
122 // Note: Not supported at present. Fall through. 165 // Note: Not supported at present. Fall through.
123 case base::MemoryState::UNKNOWN: 166 case base::MemoryState::UNKNOWN:
124 NOTREACHED(); 167 NOTREACHED();
125 break; 168 break;
126 } 169 }
127 } 170 }
128 171
129 } // namespace net 172 } // 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