Index: base/metrics/sparse_histogram.cc |
diff --git a/base/metrics/sparse_histogram.cc b/base/metrics/sparse_histogram.cc |
index c64f7cb1c649dff13de20a8a9ed04e3a320a1973..295267335a4efd6fb595c895ffdc93706a06500f 100644 |
--- a/base/metrics/sparse_histogram.cc |
+++ b/base/metrics/sparse_histogram.cc |
@@ -19,9 +19,16 @@ typedef HistogramBase::Sample Sample; |
// static |
HistogramBase* SparseHistogram::FactoryGet(const string& name, int32 flags) { |
- // TODO(kaiwang): Register and get SparseHistogram with StatisticsRecorder. |
- HistogramBase* histogram = new SparseHistogram(name); |
- histogram->SetFlags(flags); |
+ HistogramBase* histogram = StatisticsRecorder::FindHistogram(name); |
+ |
+ if (!histogram) { |
+ // To avoid racy destruction at shutdown, the following will be leaked. |
+ HistogramBase* tentative_histogram = new SparseHistogram(name); |
+ tentative_histogram->SetFlags(flags); |
+ histogram = |
+ StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
+ } |
+ DCHECK_EQ(SPARSE_HISTOGRAM, histogram->GetHistogramType()); |
return histogram; |
} |