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

Unified Diff: base/metrics/statistics_recorder.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.h ('k') | base/metrics/statistics_recorder_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/statistics_recorder.cc
diff --git a/base/metrics/statistics_recorder.cc b/base/metrics/statistics_recorder.cc
index d0fa2add3603b3f574dfa9ef9e5ee2e6b152aafc..3d8504baa1ef5ddf68585080652c5a6adf1fb19e 100644
--- a/base/metrics/statistics_recorder.cc
+++ b/base/metrics/statistics_recorder.cc
@@ -83,7 +83,11 @@ bool StatisticsRecorder::IsActive() {
// static
HistogramBase* StatisticsRecorder::RegisterOrDeleteDuplicate(
- HistogramBase* histogram) {
+ scoped_ptr<HistogramBase> histogram_ptr) {
+ // Ownership is managed outside of scoped_ptr, the use of which is only to
+ // explicitly document the transfer of ownership during the call.
+ HistogramBase* histogram = histogram_ptr.release();
+
// As per crbug.com/79322 the histograms are intentionally leaked, so we need
// to annotate them. Because ANNOTATE_LEAKING_OBJECT_PTR may be used only once
// for an object, the duplicates should not be annotated.
@@ -119,7 +123,9 @@ HistogramBase* StatisticsRecorder::RegisterOrDeleteDuplicate(
}
histogram_to_return = histogram;
} else if (histogram == it->second) {
- // The histogram was registered before.
+ // The histogram was registered before. This should never happen since
+ // the method signature ensures moving of the histogram pointer.
+ NOTREACHED();
histogram_to_return = histogram;
} else {
// We already have one histogram with this name.
@@ -136,7 +142,11 @@ HistogramBase* StatisticsRecorder::RegisterOrDeleteDuplicate(
// static
const BucketRanges* StatisticsRecorder::RegisterOrDeleteDuplicateRanges(
- const BucketRanges* ranges) {
+ scoped_ptr<const BucketRanges> ranges_ptr) {
+ // Ownership is managed outside of scoped_ptr, the use of which is only to
+ // explicitly document the transfer of ownership during the call.
+ const BucketRanges* ranges = ranges_ptr.release();
+
DCHECK(ranges->HasValidChecksum());
scoped_ptr<const BucketRanges> ranges_deleter;
« no previous file with comments | « base/metrics/statistics_recorder.h ('k') | base/metrics/statistics_recorder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698