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/memory/memory_coordinator_client_registry.h" | 9 #include "base/memory/memory_coordinator_client_registry.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 std::string absolute_name = "net/ssl_session_cache"; | 91 std::string absolute_name = "net/ssl_session_cache"; |
92 base::trace_event::MemoryAllocatorDump* cache_dump = | 92 base::trace_event::MemoryAllocatorDump* cache_dump = |
93 pmd->GetAllocatorDump(absolute_name); | 93 pmd->GetAllocatorDump(absolute_name); |
94 // This method can be reached from different URLRequestContexts. Since this is | 94 // This method can be reached from different URLRequestContexts. Since this is |
95 // a singleton, only log memory stats once. | 95 // a singleton, only log memory stats once. |
96 // TODO(xunjieli): Change this once crbug.com/458365 is fixed. | 96 // TODO(xunjieli): Change this once crbug.com/458365 is fixed. |
97 if (cache_dump) | 97 if (cache_dump) |
98 return; | 98 return; |
99 cache_dump = pmd->CreateAllocatorDump(absolute_name); | 99 cache_dump = pmd->CreateAllocatorDump(absolute_name); |
100 base::AutoLock lock(lock_); | 100 base::AutoLock lock(lock_); |
101 int total_serialized_cert_size = 0; | 101 size_t total_serialized_cert_size = 0; |
102 int total_cert_count = 0; | 102 size_t total_cert_count = 0; |
103 for (const auto& pair : cache_) { | 103 for (const auto& pair : cache_) { |
104 auto entry = pair.second.get(); | 104 const SSL_SESSION* session = pair.second.get(); |
105 auto cert_chain = entry->x509_chain; | 105 size_t cert_count = sk_CRYPTO_BUFFER_num(session->certs); |
106 size_t cert_count = sk_X509_num(cert_chain); | |
107 total_cert_count += cert_count; | 106 total_cert_count += cert_count; |
108 for (size_t i = 0; i < cert_count; ++i) { | 107 for (size_t i = 0; i < cert_count; ++i) { |
109 X509* cert = sk_X509_value(cert_chain, i); | 108 const CRYPTO_BUFFER* cert = sk_CRYPTO_BUFFER_value(session->certs, i); |
110 total_serialized_cert_size += i2d_X509(cert, nullptr); | 109 total_serialized_cert_size += CRYPTO_BUFFER_len(cert); |
111 } | 110 } |
112 } | 111 } |
113 // This measures the lower bound of the serialized certificate. It doesn't | 112 // This measures the lower bound of the serialized certificate. It doesn't |
114 // measure the actual memory used, which is 4x this amount (see | 113 // measure the actual memory used, which is 4x this amount (see |
115 // crbug.com/671420 for more details). | 114 // crbug.com/671420 for more details). |
116 cache_dump->AddScalar("serialized_cert_size", | 115 cache_dump->AddScalar("serialized_cert_size", |
117 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 116 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
118 total_serialized_cert_size); | 117 total_serialized_cert_size); |
119 cache_dump->AddScalar("cert_count", | 118 cache_dump->AddScalar("cert_count", |
120 base::trace_event::MemoryAllocatorDump::kUnitsObjects, | 119 base::trace_event::MemoryAllocatorDump::kUnitsObjects, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 break; | 161 break; |
163 case base::MemoryState::SUSPENDED: | 162 case base::MemoryState::SUSPENDED: |
164 // Note: Not supported at present. Fall through. | 163 // Note: Not supported at present. Fall through. |
165 case base::MemoryState::UNKNOWN: | 164 case base::MemoryState::UNKNOWN: |
166 NOTREACHED(); | 165 NOTREACHED(); |
167 break; | 166 break; |
168 } | 167 } |
169 } | 168 } |
170 | 169 |
171 } // namespace net | 170 } // namespace net |
OLD | NEW |