| 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; |
| 102 int total_cert_count = 0; |
| 101 for (const auto& pair : cache_) { | 103 for (const auto& pair : cache_) { |
| 102 auto entry = pair.second.get(); | 104 auto entry = pair.second.get(); |
| 103 auto cert_chain = entry->x509_chain; | 105 auto cert_chain = entry->x509_chain; |
| 104 size_t cert_count = sk_X509_num(cert_chain); | 106 size_t cert_count = sk_X509_num(cert_chain); |
| 105 base::trace_event::MemoryAllocatorDump* entry_dump = | 107 total_cert_count += cert_count; |
| 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) { | 108 for (size_t i = 0; i < cert_count; ++i) { |
| 110 X509* cert = sk_X509_value(cert_chain, i); | 109 X509* cert = sk_X509_value(cert_chain, i); |
| 111 cert_size += i2d_X509(cert, nullptr); | 110 total_serialized_cert_size += i2d_X509(cert, nullptr); |
| 112 } | 111 } |
| 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 } | 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 cache_dump->AddScalar("serialized_cert_size", |
| 117 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 118 total_serialized_cert_size); |
| 119 cache_dump->AddScalar("cert_count", |
| 120 base::trace_event::MemoryAllocatorDump::kUnitsObjects, |
| 121 total_cert_count); |
| 122 cache_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 123 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 124 total_serialized_cert_size); |
| 126 } | 125 } |
| 127 | 126 |
| 128 void SSLClientSessionCache::FlushExpiredSessions() { | 127 void SSLClientSessionCache::FlushExpiredSessions() { |
| 129 time_t now = clock_->Now().ToTimeT(); | 128 time_t now = clock_->Now().ToTimeT(); |
| 130 auto iter = cache_.begin(); | 129 auto iter = cache_.begin(); |
| 131 while (iter != cache_.end()) { | 130 while (iter != cache_.end()) { |
| 132 if (IsExpired(iter->second.get(), now)) { | 131 if (IsExpired(iter->second.get(), now)) { |
| 133 iter = cache_.Erase(iter); | 132 iter = cache_.Erase(iter); |
| 134 } else { | 133 } else { |
| 135 ++iter; | 134 ++iter; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 163 break; | 162 break; |
| 164 case base::MemoryState::SUSPENDED: | 163 case base::MemoryState::SUSPENDED: |
| 165 // Note: Not supported at present. Fall through. | 164 // Note: Not supported at present. Fall through. |
| 166 case base::MemoryState::UNKNOWN: | 165 case base::MemoryState::UNKNOWN: |
| 167 NOTREACHED(); | 166 NOTREACHED(); |
| 168 break; | 167 break; |
| 169 } | 168 } |
| 170 } | 169 } |
| 171 | 170 |
| 172 } // namespace net | 171 } // namespace net |
| OLD | NEW |