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

Unified Diff: base/metrics/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/histogram.h ('k') | base/metrics/histogram_persistence.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/histogram.cc
diff --git a/base/metrics/histogram.cc b/base/metrics/histogram.cc
index ea4f8167fa28cc7098ce233cddbd7ed77fd23a77..40ae9c116fd18e1d353d5333631b762f778f7ef1 100644
--- a/base/metrics/histogram.cc
+++ b/base/metrics/histogram.cc
@@ -156,9 +156,10 @@ HistogramBase* Histogram::Factory::Build() {
HistogramBase* histogram = StatisticsRecorder::FindHistogram(name_);
if (!histogram) {
// To avoid racy destruction at shutdown, the following will be leaked.
- const BucketRanges* created_ranges = CreateRanges();
+ scoped_ptr<const BucketRanges> created_ranges(CreateRanges());
const BucketRanges* registered_ranges =
- StatisticsRecorder::RegisterOrDeleteDuplicateRanges(created_ranges);
+ StatisticsRecorder::RegisterOrDeleteDuplicateRanges(
+ std::move(created_ranges));
// In most cases, the bucket-count, minimum, and maximum values are known
// when the code is written and so are passed in explicitly. In other
@@ -177,7 +178,7 @@ HistogramBase* Histogram::Factory::Build() {
// allocating from it fails, code below will allocate the histogram from
// the process heap.
PersistentMemoryAllocator::Reference histogram_ref = 0;
- HistogramBase* tentative_histogram = nullptr;
+ scoped_ptr<HistogramBase> tentative_histogram;
PersistentMemoryAllocator* allocator =
GetPersistentHistogramMemoryAllocator();
if (allocator) {
@@ -199,17 +200,18 @@ HistogramBase* Histogram::Factory::Build() {
DCHECK(!histogram_ref); // Should never have been set.
DCHECK(!allocator); // Shouldn't have failed.
flags_ &= ~HistogramBase::kIsPersistent;
- tentative_histogram = HeapAlloc(registered_ranges);
+ tentative_histogram.reset(HeapAlloc(registered_ranges));
}
- FillHistogram(tentative_histogram);
- histogram =
- StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram);
+ FillHistogram(tentative_histogram.get());
+ const void* allocated_histogram = tentative_histogram.get();
+ histogram = StatisticsRecorder::RegisterOrDeleteDuplicate(
+ std::move(tentative_histogram));
// Persistent histograms need some follow-up processing.
if (histogram_ref) {
FinalizePersistentHistogram(histogram_ref,
- histogram == tentative_histogram);
+ histogram == allocated_histogram);
}
}
« no previous file with comments | « base/metrics/histogram.h ('k') | base/metrics/histogram_persistence.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698