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

Unified Diff: base/metrics/histogram_persistence.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_persistence.h ('k') | base/metrics/histogram_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/histogram_persistence.cc
diff --git a/base/metrics/histogram_persistence.cc b/base/metrics/histogram_persistence.cc
index bd250ec888a62a1998a4e762576b6bac388408b2..16b76d8fca3a5c403838e69ece65ffc22186e39c 100644
--- a/base/metrics/histogram_persistence.cc
+++ b/base/metrics/histogram_persistence.cc
@@ -228,7 +228,7 @@ ReleasePersistentHistogramMemoryAllocatorForTesting() {
return allocator;
};
-HistogramBase* CreatePersistentHistogram(
+scoped_ptr<HistogramBase> CreatePersistentHistogram(
PersistentMemoryAllocator* allocator,
PersistentHistogramData* histogram_data_ptr) {
if (!histogram_data_ptr) {
@@ -257,17 +257,19 @@ HistogramBase* CreatePersistentHistogram(
NOTREACHED();
return nullptr;
}
- // To avoid racy destruction at shutdown, the following will be leaked.
- const BucketRanges* ranges = CreateRangesFromData(
+
+ scoped_ptr<const BucketRanges> created_ranges(CreateRangesFromData(
ranges_data,
histogram_data.ranges_checksum,
- histogram_data.bucket_count + 1);
- if (!ranges) {
+ histogram_data.bucket_count + 1));
+ if (!created_ranges) {
RecordCreateHistogramResult(CREATE_HISTOGRAM_INVALID_RANGES_ARRAY);
NOTREACHED();
return nullptr;
}
- ranges = StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges);
+ const BucketRanges* ranges =
+ StatisticsRecorder::RegisterOrDeleteDuplicateRanges(
+ std::move(created_ranges));
HistogramBase::AtomicCount* counts_data =
allocator->GetAsObject<HistogramBase::AtomicCount>(
@@ -288,10 +290,10 @@ HistogramBase* CreatePersistentHistogram(
counts_data + histogram_data.bucket_count;
std::string name(histogram_data_ptr->name);
- HistogramBase* histogram = nullptr;
+ scoped_ptr<HistogramBase> histogram;
switch (histogram_data.histogram_type) {
case HISTOGRAM:
- histogram = Histogram::PersistentGet(
+ histogram.reset(Histogram::PersistentGet(
name,
histogram_data.minimum,
histogram_data.maximum,
@@ -300,11 +302,11 @@ HistogramBase* CreatePersistentHistogram(
logged_data,
histogram_data.bucket_count,
&histogram_data_ptr->samples_metadata,
- &histogram_data_ptr->logged_metadata);
+ &histogram_data_ptr->logged_metadata));
DCHECK(histogram);
break;
case LINEAR_HISTOGRAM:
- histogram = LinearHistogram::PersistentGet(
+ histogram.reset(LinearHistogram::PersistentGet(
name,
histogram_data.minimum,
histogram_data.maximum,
@@ -313,28 +315,28 @@ HistogramBase* CreatePersistentHistogram(
logged_data,
histogram_data.bucket_count,
&histogram_data_ptr->samples_metadata,
- &histogram_data_ptr->logged_metadata);
+ &histogram_data_ptr->logged_metadata));
DCHECK(histogram);
break;
case BOOLEAN_HISTOGRAM:
- histogram = BooleanHistogram::PersistentGet(
+ histogram.reset(BooleanHistogram::PersistentGet(
name,
ranges,
counts_data,
logged_data,
&histogram_data_ptr->samples_metadata,
- &histogram_data_ptr->logged_metadata);
+ &histogram_data_ptr->logged_metadata));
DCHECK(histogram);
break;
case CUSTOM_HISTOGRAM:
- histogram = CustomHistogram::PersistentGet(
+ histogram.reset(CustomHistogram::PersistentGet(
name,
ranges,
counts_data,
logged_data,
histogram_data.bucket_count,
&histogram_data_ptr->samples_metadata,
- &histogram_data_ptr->logged_metadata);
+ &histogram_data_ptr->logged_metadata));
DCHECK(histogram);
break;
default:
@@ -352,7 +354,7 @@ HistogramBase* CreatePersistentHistogram(
return histogram;
}
-HistogramBase* GetPersistentHistogram(
+scoped_ptr<HistogramBase> GetPersistentHistogram(
PersistentMemoryAllocator* allocator,
int32_t ref) {
// Unfortunately, the above "pickle" methods cannot be used as part of the
@@ -372,7 +374,7 @@ HistogramBase* GetPersistentHistogram(
return CreatePersistentHistogram(allocator, histogram_data);
}
-HistogramBase* GetNextPersistentHistogram(
+scoped_ptr<HistogramBase> GetNextPersistentHistogram(
PersistentMemoryAllocator* allocator,
PersistentMemoryAllocator::Iterator* iter) {
PersistentMemoryAllocator::Reference ref;
@@ -397,7 +399,7 @@ void FinalizePersistentHistogram(PersistentMemoryAllocator::Reference ref,
GetPersistentHistogramMemoryAllocator()->SetType(ref, 0);
}
-HistogramBase* AllocatePersistentHistogram(
+scoped_ptr<HistogramBase> AllocatePersistentHistogram(
PersistentMemoryAllocator* allocator,
HistogramType histogram_type,
const std::string& name,
@@ -465,8 +467,8 @@ HistogramBase* AllocatePersistentHistogram(
// using what is already known above but avoids duplicating the switch
// statement here and serves as a double-check that everything is
// correct before commiting the new histogram to persistent space.
- HistogramBase* histogram =
- CreatePersistentHistogram(allocator, histogram_data);
+ scoped_ptr<HistogramBase> histogram(
+ CreatePersistentHistogram(allocator, histogram_data));
DCHECK(histogram);
if (ref_ptr != nullptr)
*ref_ptr = histogram_ref;
@@ -504,10 +506,11 @@ void ImportPersistentHistograms() {
g_allocator->CreateIterator(&iter);
while (true) {
- HistogramBase* histogram = GetNextPersistentHistogram(g_allocator, &iter);
+ scoped_ptr<HistogramBase> histogram(
+ GetNextPersistentHistogram(g_allocator, &iter));
if (!histogram)
break;
- StatisticsRecorder::RegisterOrDeleteDuplicate(histogram);
+ StatisticsRecorder::RegisterOrDeleteDuplicate(std::move(histogram));
}
}
}
« no previous file with comments | « base/metrics/histogram_persistence.h ('k') | base/metrics/histogram_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698