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

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

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

Powered by Google App Engine
This is Rietveld 408576698