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)); |
} |
} |
} |