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

Unified Diff: chromecast/base/metrics/grouped_histogram.cc

Issue 1689833002: Add ownership-transfer to histogram management calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/metrics/statistics_recorder_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromecast/base/metrics/grouped_histogram.cc
diff --git a/chromecast/base/metrics/grouped_histogram.cc b/chromecast/base/metrics/grouped_histogram.cc
index 1101a7992c55f6f25658d743d992404087298065..34bf5382e161f6b5c223aab6aa7f17cb5636e9ec 100644
--- a/chromecast/base/metrics/grouped_histogram.cc
+++ b/chromecast/base/metrics/grouped_histogram.cc
@@ -143,20 +143,23 @@ void PreregisterHistogram(const std::string& name,
DCHECK(!base::StatisticsRecorder::FindHistogram(name))
<< "Failed to preregister " << name << ", Histogram already exists.";
- // To avoid racy destruction at shutdown, the following will be leaked.
- base::BucketRanges* ranges = new base::BucketRanges(bucket_count + 1);
- base::Histogram::InitializeBucketRanges(minimum, maximum, ranges);
+ scoped_ptr<base::BucketRanges> ranges(
+ new base::BucketRanges(bucket_count + 1));
+ base::Histogram::InitializeBucketRanges(minimum, maximum, ranges.get());
const base::BucketRanges* registered_ranges =
- base::StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges);
+ base::StatisticsRecorder::RegisterOrDeleteDuplicateRanges(
+ std::move(ranges));
- GroupedHistogram* tentative_histogram =
- new GroupedHistogram(name, minimum, maximum, registered_ranges);
+ scoped_ptr<GroupedHistogram> tentative_histogram(
+ new GroupedHistogram(name, minimum, maximum, registered_ranges));
tentative_histogram->SetFlags(flags);
+ const void* allocated_histogram = tentative_histogram.get();
base::HistogramBase* histogram =
- base::StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram);
+ base::StatisticsRecorder::RegisterOrDeleteDuplicate(
+ std::move(tentative_histogram));
- DCHECK_EQ(histogram, tentative_histogram);
+ DCHECK_EQ(histogram, allocated_histogram);
DCHECK_EQ(base::HISTOGRAM, histogram->GetHistogramType());
DCHECK(histogram->HasConstructionArguments(minimum, maximum, bucket_count));
}
« no previous file with comments | « base/metrics/statistics_recorder_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698