| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "base/metrics/histogram_persistence.h" | 5 #include "base/metrics/histogram_persistence.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 NOTREACHED(); | 237 NOTREACHED(); |
| 238 return nullptr; | 238 return nullptr; |
| 239 } | 239 } |
| 240 | 240 |
| 241 // Copy the histogram_data to local storage because anything in persistent | 241 // Copy the histogram_data to local storage because anything in persistent |
| 242 // memory cannot be trusted as it could be changed at any moment by a | 242 // memory cannot be trusted as it could be changed at any moment by a |
| 243 // malicious actor that shares access. The contents of histogram_data are | 243 // malicious actor that shares access. The contents of histogram_data are |
| 244 // validated below; the local copy is to ensure that the contents cannot | 244 // validated below; the local copy is to ensure that the contents cannot |
| 245 // be externally changed between validation and use. | 245 // be externally changed between validation and use. |
| 246 PersistentHistogramData histogram_data = *histogram_data_ptr; | 246 PersistentHistogramData histogram_data = *histogram_data_ptr; |
| 247 CHECK_EQ(histogram_data.histogram_type, histogram_data_ptr->histogram_type); | |
| 248 CHECK_EQ(histogram_data.flags, histogram_data_ptr->flags); | |
| 249 CHECK_EQ(histogram_data.minimum, histogram_data_ptr->minimum); | |
| 250 CHECK_EQ(histogram_data.maximum, histogram_data_ptr->maximum); | |
| 251 CHECK_EQ(histogram_data.bucket_count, histogram_data_ptr->bucket_count); | |
| 252 CHECK_EQ(histogram_data.ranges_checksum, histogram_data_ptr->ranges_checksum); | |
| 253 | 247 |
| 254 HistogramBase::Sample* ranges_data = | 248 HistogramBase::Sample* ranges_data = |
| 255 allocator->GetAsObject<HistogramBase::Sample>(histogram_data.ranges_ref, | 249 allocator->GetAsObject<HistogramBase::Sample>(histogram_data.ranges_ref, |
| 256 kTypeIdRangesArray); | 250 kTypeIdRangesArray); |
| 257 if (!ranges_data || histogram_data.bucket_count < 2 || | 251 if (!ranges_data || histogram_data.bucket_count < 2 || |
| 258 histogram_data.bucket_count + 1 > | 252 histogram_data.bucket_count + 1 > |
| 259 std::numeric_limits<uint32_t>::max() / | 253 std::numeric_limits<uint32_t>::max() / |
| 260 sizeof(HistogramBase::Sample) || | 254 sizeof(HistogramBase::Sample) || |
| 261 allocator->GetAllocSize(histogram_data.ranges_ref) < | 255 allocator->GetAllocSize(histogram_data.ranges_ref) < |
| 262 (histogram_data.bucket_count + 1) * sizeof(HistogramBase::Sample)) { | 256 (histogram_data.bucket_count + 1) * sizeof(HistogramBase::Sample)) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 287 NOTREACHED(); | 281 NOTREACHED(); |
| 288 return nullptr; | 282 return nullptr; |
| 289 } | 283 } |
| 290 | 284 |
| 291 // After the main "counts" array is a second array using for storing what | 285 // After the main "counts" array is a second array using for storing what |
| 292 // was previously logged. This is used to calculate the "delta" during | 286 // was previously logged. This is used to calculate the "delta" during |
| 293 // snapshot operations. | 287 // snapshot operations. |
| 294 HistogramBase::AtomicCount* logged_data = | 288 HistogramBase::AtomicCount* logged_data = |
| 295 counts_data + histogram_data.bucket_count; | 289 counts_data + histogram_data.bucket_count; |
| 296 | 290 |
| 297 CHECK_LT(0, histogram_data.minimum); | |
| 298 CHECK_LT(0, histogram_data.maximum); | |
| 299 std::string name(histogram_data_ptr->name); | 291 std::string name(histogram_data_ptr->name); |
| 300 HistogramBase* histogram = nullptr; | 292 HistogramBase* histogram = nullptr; |
| 301 switch (histogram_data.histogram_type) { | 293 switch (histogram_data.histogram_type) { |
| 302 case HISTOGRAM: | 294 case HISTOGRAM: |
| 303 histogram = Histogram::PersistentGet( | 295 histogram = Histogram::PersistentGet( |
| 304 name, | 296 name, |
| 305 histogram_data.minimum, | 297 histogram_data.minimum, |
| 306 histogram_data.maximum, | 298 histogram_data.maximum, |
| 307 ranges, | 299 ranges, |
| 308 counts_data, | 300 counts_data, |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 while (true) { | 507 while (true) { |
| 516 HistogramBase* histogram = GetNextPersistentHistogram(g_allocator, &iter); | 508 HistogramBase* histogram = GetNextPersistentHistogram(g_allocator, &iter); |
| 517 if (!histogram) | 509 if (!histogram) |
| 518 break; | 510 break; |
| 519 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram); | 511 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram); |
| 520 } | 512 } |
| 521 } | 513 } |
| 522 } | 514 } |
| 523 | 515 |
| 524 } // namespace base | 516 } // namespace base |
| OLD | NEW |