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

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

Issue 462027: Use factory to create histograms, and refcounts to track lifetimes... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years 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
« no previous file with comments | « net/disk_cache/stats_histogram.h ('k') | net/ftp/ftp_network_transaction.cc » ('j') | 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 {
11 11
12 // Static. 12 // Static.
13 const Stats* StatsHistogram::stats_ = NULL; 13 const Stats* StatsHistogram::stats_ = NULL;
14 14
15 scoped_refptr<StatsHistogram> StatsHistogram::StatsHistogramFactoryGet(
16 const std::string& name) {
17 scoped_refptr<Histogram> histogram(NULL);
18
19 Sample minimum = 1;
20 Sample maximum = disk_cache::Stats::kDataSizesLength - 1;
21 size_t bucket_count = disk_cache::Stats::kDataSizesLength;
22
23 if (StatisticsRecorder::FindHistogram(name, &histogram)) {
24 DCHECK(histogram.get() != NULL);
25 } else {
26 histogram = new StatsHistogram(name, minimum, maximum, bucket_count);
27 scoped_refptr<Histogram> registered_histogram(NULL);
28 StatisticsRecorder::FindHistogram(name, &registered_histogram);
29 if (registered_histogram.get() != NULL &&
30 registered_histogram.get() != histogram.get())
31 histogram = registered_histogram;
32 }
33
34 DCHECK(HISTOGRAM == histogram->histogram_type());
35 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count));
36
37 // We're preparing for an otherwise unsafe upcast by ensuring we have the
38 // proper class type.
39 Histogram* temp_histogram = histogram.get();
40 StatsHistogram* temp_stats_histogram =
41 static_cast<StatsHistogram*>(temp_histogram);
42 scoped_refptr<StatsHistogram> return_histogram = temp_stats_histogram;
43 return return_histogram;
44 }
45
15 bool StatsHistogram::Init(const Stats* stats) { 46 bool StatsHistogram::Init(const Stats* stats) {
16 DCHECK(stats); 47 DCHECK(stats);
17 if (stats_) 48 if (stats_)
18 return false; 49 return false;
19 50
20 SetFlags(kUmaTargetedHistogramFlag); 51 SetFlags(kUmaTargetedHistogramFlag);
21 52
22 // We support statistics report for only one cache. 53 // We support statistics report for only one cache.
23 init_ = true; 54 init_ = true;
24 stats_ = stats; 55 stats_ = stats;
(...skipping 21 matching lines...) Expand all
46 stats_->Snapshot(&my_sample); 77 stats_->Snapshot(&my_sample);
47 78
48 *sample = my_sample; 79 *sample = my_sample;
49 80
50 // Only report UMA data once. 81 // Only report UMA data once.
51 StatsHistogram* mutable_me = const_cast<StatsHistogram*>(this); 82 StatsHistogram* mutable_me = const_cast<StatsHistogram*>(this);
52 mutable_me->ClearFlags(kUmaTargetedHistogramFlag); 83 mutable_me->ClearFlags(kUmaTargetedHistogramFlag);
53 } 84 }
54 85
55 } // namespace disk_cache 86 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/stats_histogram.h ('k') | net/ftp/ftp_network_transaction.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698