| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/disk_cache/stats.h" | 5 #include "net/disk_cache/stats.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "net/disk_cache/backend_impl.h" | 9 #include "net/disk_cache/backend_impl.h" |
| 10 | 10 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 if (!LoadStats(backend, address, &stats)) | 116 if (!LoadStats(backend, address, &stats)) |
| 117 return false; | 117 return false; |
| 118 } else { | 118 } else { |
| 119 if (!CreateStats(backend, &address, &stats)) | 119 if (!CreateStats(backend, &address, &stats)) |
| 120 return false; | 120 return false; |
| 121 *storage_addr = address.value(); | 121 *storage_addr = address.value(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 storage_addr_ = address.value(); | 124 storage_addr_ = address.value(); |
| 125 backend_ = backend; | 125 backend_ = backend; |
| 126 if (!size_histogram_.get()) { | |
| 127 // Stats may be reused when the cache is re-created, but we want only one | |
| 128 // histogram at any given time. | |
| 129 size_histogram_.reset(new StatsHistogram("DiskCache.SizeStats")); | |
| 130 size_histogram_->Init(this); | |
| 131 } | |
| 132 | 126 |
| 133 memcpy(data_sizes_, stats.data_sizes, sizeof(data_sizes_)); | 127 memcpy(data_sizes_, stats.data_sizes, sizeof(data_sizes_)); |
| 134 memcpy(counters_, stats.counters, sizeof(counters_)); | 128 memcpy(counters_, stats.counters, sizeof(counters_)); |
| 135 | 129 |
| 130 // It seems impossible to support this histogram for more than one |
| 131 // simultaneous objects with the current infrastructure. |
| 132 static bool first_time = true; |
| 133 if (first_time) { |
| 134 first_time = false; |
| 135 // ShouldReportAgain() will re-enter this object. |
| 136 if (!size_histogram_.get() && backend->cache_type() == net::DISK_CACHE && |
| 137 backend->ShouldReportAgain()) { |
| 138 // Stats may be reused when the cache is re-created, but we want only one |
| 139 // histogram at any given time. |
| 140 size_histogram_.reset(new StatsHistogram("DiskCache.SizeStats")); |
| 141 size_histogram_->Init(this); |
| 142 } |
| 143 } |
| 144 |
| 136 return true; | 145 return true; |
| 137 } | 146 } |
| 138 | 147 |
| 139 Stats::~Stats() { | 148 Stats::~Stats() { |
| 140 Store(); | 149 Store(); |
| 141 } | 150 } |
| 142 | 151 |
| 143 // The array will be filled this way: | 152 // The array will be filled this way: |
| 144 // index size | 153 // index size |
| 145 // 0 [0, 1024) | 154 // 0 [0, 1024) |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 stats.signature = kDiskSignature; | 310 stats.signature = kDiskSignature; |
| 302 stats.size = sizeof(stats); | 311 stats.size = sizeof(stats); |
| 303 memcpy(stats.data_sizes, data_sizes_, sizeof(data_sizes_)); | 312 memcpy(stats.data_sizes, data_sizes_, sizeof(data_sizes_)); |
| 304 memcpy(stats.counters, counters_, sizeof(counters_)); | 313 memcpy(stats.counters, counters_, sizeof(counters_)); |
| 305 | 314 |
| 306 Addr address(storage_addr_); | 315 Addr address(storage_addr_); |
| 307 StoreStats(backend_, address, &stats); | 316 StoreStats(backend_, address, &stats); |
| 308 } | 317 } |
| 309 | 318 |
| 310 } // namespace disk_cache | 319 } // namespace disk_cache |
| OLD | NEW |