diff options
author | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-06 00:09:37 +0000 |
---|---|---|
committer | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-06 00:09:37 +0000 |
commit | e8829a1981a2d9d849c377c28f9444fdefee0f44 (patch) | |
tree | 3cfe522cf76d308dec9fca773d3f9495e12abc5e /net/disk_cache/stats_histogram.cc | |
parent | 4f3b65a30cad88c1f1e482f7bda69ef50f8e1364 (diff) | |
download | chromium_src-e8829a1981a2d9d849c377c28f9444fdefee0f44.zip chromium_src-e8829a1981a2d9d849c377c28f9444fdefee0f44.tar.gz chromium_src-e8829a1981a2d9d849c377c28f9444fdefee0f44.tar.bz2 |
Use factory to create histograms, and refcounts to track lifetimes
This is CL patch 377028 by Raman Tenneti, with minor changes to
make the try-bots happier.
It is cleanup that better ensures lifetimes of histograms (making it harder
for users to abuse them).
bug=16495 (repairs leak induced by the first landing)
bug=18840 (should make leaks less possible)
tbr=raman.tenneti
Review URL: http://codereview.chromium.org/462027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33933 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/stats_histogram.cc')
-rw-r--r-- | net/disk_cache/stats_histogram.cc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/net/disk_cache/stats_histogram.cc b/net/disk_cache/stats_histogram.cc index f605934..e6eaf90 100644 --- a/net/disk_cache/stats_histogram.cc +++ b/net/disk_cache/stats_histogram.cc @@ -12,6 +12,37 @@ namespace disk_cache { // Static. const Stats* StatsHistogram::stats_ = NULL; +scoped_refptr<StatsHistogram> StatsHistogram::StatsHistogramFactoryGet( + const std::string& name) { + scoped_refptr<Histogram> histogram(NULL); + + Sample minimum = 1; + Sample maximum = disk_cache::Stats::kDataSizesLength - 1; + size_t bucket_count = disk_cache::Stats::kDataSizesLength; + + if (StatisticsRecorder::FindHistogram(name, &histogram)) { + DCHECK(histogram.get() != NULL); + } else { + histogram = new StatsHistogram(name, minimum, maximum, bucket_count); + scoped_refptr<Histogram> registered_histogram(NULL); + StatisticsRecorder::FindHistogram(name, ®istered_histogram); + if (registered_histogram.get() != NULL && + registered_histogram.get() != histogram.get()) + histogram = registered_histogram; + } + + DCHECK(HISTOGRAM == histogram->histogram_type()); + DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count)); + + // We're preparing for an otherwise unsafe upcast by ensuring we have the + // proper class type. + Histogram* temp_histogram = histogram.get(); + StatsHistogram* temp_stats_histogram = + static_cast<StatsHistogram*>(temp_histogram); + scoped_refptr<StatsHistogram> return_histogram = temp_stats_histogram; + return return_histogram; +} + bool StatsHistogram::Init(const Stats* stats) { DCHECK(stats); if (stats_) |