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

Side by Side Diff: net/disk_cache/stats_histogram.cc

Issue 6577013: Crash when we notice a corruption of the histogram range-vector... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 months 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 | Annotate | Revision Log
« base/metrics/histogram.h ('K') | « net/disk_cache/stats_histogram.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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_histogram.h" 5 #include "net/disk_cache/stats_histogram.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "net/disk_cache/stats.h" 8 #include "net/disk_cache/stats.h"
9 9
10 namespace disk_cache { 10 namespace disk_cache {
(...skipping 14 matching lines...) Expand all
25 const std::string& name) { 25 const std::string& name) {
26 scoped_refptr<Histogram> histogram(NULL); 26 scoped_refptr<Histogram> histogram(NULL);
27 27
28 Sample minimum = 1; 28 Sample minimum = 1;
29 Sample maximum = disk_cache::Stats::kDataSizesLength - 1; 29 Sample maximum = disk_cache::Stats::kDataSizesLength - 1;
30 size_t bucket_count = disk_cache::Stats::kDataSizesLength; 30 size_t bucket_count = disk_cache::Stats::kDataSizesLength;
31 31
32 if (StatisticsRecorder::FindHistogram(name, &histogram)) { 32 if (StatisticsRecorder::FindHistogram(name, &histogram)) {
33 DCHECK(histogram.get() != NULL); 33 DCHECK(histogram.get() != NULL);
34 } else { 34 } else {
35 histogram = new StatsHistogram(name, minimum, maximum, bucket_count); 35 StatsHistogram* stats_histogram = new StatsHistogram(name, minimum, maximum,
rvargas (doing something else) 2011/02/28 19:50:53 Why use a temp variable at all?
jar (doing other things) 2011/02/28 22:11:44 This is subtle, and perchance worth a comment. If
rvargas (doing something else) 2011/02/28 23:05:33 Thanks for the explanation. Wouldn't it be better
jar (doing other things) 2011/03/01 00:21:18 You're code was fairly special (starting around li
36 scoped_refptr<Histogram> registered_histogram(NULL); 36 bucket_count);
37 StatisticsRecorder::FindHistogram(name, &registered_histogram); 37 stats_histogram->InitializeBucketRange();
38 if (registered_histogram.get() != NULL && 38 histogram = stats_histogram;
39 registered_histogram.get() != histogram.get()) 39 StatisticsRecorder::Register(&histogram);
40 histogram = registered_histogram;
41 } 40 }
42 41
43 DCHECK(HISTOGRAM == histogram->histogram_type()); 42 DCHECK(HISTOGRAM == histogram->histogram_type());
44 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count)); 43 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count));
45 44
46 // We're preparing for an otherwise unsafe upcast by ensuring we have the 45 // We're preparing for an otherwise unsafe upcast by ensuring we have the
47 // proper class type. 46 // proper class type.
48 Histogram* temp_histogram = histogram.get(); 47 Histogram* temp_histogram = histogram.get();
49 StatsHistogram* temp_stats_histogram = 48 StatsHistogram* temp_stats_histogram =
50 static_cast<StatsHistogram*>(temp_histogram); 49 static_cast<StatsHistogram*>(temp_histogram);
50 // Validate upcast by seeing that we're probably providing the checksum.
51 CHECK_EQ(temp_stats_histogram->StatsHistogram::CalculateRangeChecksum(),
52 temp_stats_histogram->CalculateRangeChecksum());
51 scoped_refptr<StatsHistogram> return_histogram(temp_stats_histogram); 53 scoped_refptr<StatsHistogram> return_histogram(temp_stats_histogram);
52 return return_histogram; 54 return return_histogram;
53 } 55 }
54 56
55 bool StatsHistogram::Init(const Stats* stats) { 57 bool StatsHistogram::Init(const Stats* stats) {
56 DCHECK(stats); 58 DCHECK(stats);
57 if (stats_) 59 if (stats_)
58 return false; 60 return false;
59 61
60 SetFlags(kUmaTargetedHistogramFlag); 62 SetFlags(kUmaTargetedHistogramFlag);
(...skipping 23 matching lines...) Expand all
84 // Only report UMA data once. 86 // Only report UMA data once.
85 StatsHistogram* mutable_me = const_cast<StatsHistogram*>(this); 87 StatsHistogram* mutable_me = const_cast<StatsHistogram*>(this);
86 mutable_me->ClearFlags(kUmaTargetedHistogramFlag); 88 mutable_me->ClearFlags(kUmaTargetedHistogramFlag);
87 } 89 }
88 90
89 Histogram::Inconsistencies StatsHistogram::FindCorruption( 91 Histogram::Inconsistencies StatsHistogram::FindCorruption(
90 const SampleSet& snapshot) const { 92 const SampleSet& snapshot) const {
91 return NO_INCONSISTENCIES; // This class won't monitor inconsistencies. 93 return NO_INCONSISTENCIES; // This class won't monitor inconsistencies.
92 } 94 }
93 95
96 uint32 StatsHistogram::CalculateRangeChecksum() const {
97 // We don't calculate checksums, so at least establish a unique constant.
98 const uint32 kStatsHistogramChecksum = 0x0cecce;
99 return kStatsHistogramChecksum;
100 }
94 101
95 } // namespace disk_cache 102 } // namespace disk_cache
OLDNEW
« base/metrics/histogram.h ('K') | « net/disk_cache/stats_histogram.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698