Index: base/metrics/statistics_recorder.cc |
diff --git a/base/metrics/statistics_recorder.cc b/base/metrics/statistics_recorder.cc |
index d0fa2add3603b3f574dfa9ef9e5ee2e6b152aafc..9b3ad2643cfb7986e1f9fc657c53b242422c9835 100644 |
--- a/base/metrics/statistics_recorder.cc |
+++ b/base/metrics/statistics_recorder.cc |
@@ -369,12 +369,6 @@ StatisticsRecorder::OnSampleCallback StatisticsRecorder::FindCallback( |
} |
// static |
-void StatisticsRecorder::ResetForTesting() { |
- // Just call the private version that is used also by the destructor. |
- Reset(); |
-} |
- |
-// static |
void StatisticsRecorder::ForgetHistogramForTesting(base::StringPiece name) { |
if (histograms_) |
histograms_->erase(HashMetricName(name.as_string())); |
@@ -384,7 +378,6 @@ void StatisticsRecorder::ForgetHistogramForTesting(base::StringPiece name) { |
// of main(), and hence it is not thread safe. It initializes globals to |
// provide support for all future calls. |
StatisticsRecorder::StatisticsRecorder() { |
- DCHECK(!histograms_); |
if (lock_ == NULL) { |
// This will leak on purpose. It's the only way to make sure we won't race |
// against the static uninitialization of the module while one of our |
@@ -394,7 +387,13 @@ StatisticsRecorder::StatisticsRecorder() { |
// during static initialization and released only on process termination. |
lock_ = new base::Lock; |
} |
+ |
base::AutoLock auto_lock(*lock_); |
+ |
+ existing_histograms_.reset(histograms_); |
+ existing_callbacks_.reset(callbacks_); |
+ existing_ranges_.reset(ranges_); |
+ |
histograms_ = new HistogramMap; |
callbacks_ = new CallbackMap; |
ranges_ = new RangesMap; |
@@ -406,8 +405,12 @@ StatisticsRecorder::StatisticsRecorder() { |
StatisticsRecorder::~StatisticsRecorder() { |
DCHECK(histograms_ && ranges_ && lock_); |
- // Global clean up. |
+ // Clean out what this object created and then restore what existed before. |
Reset(); |
+ base::AutoLock auto_lock(*lock_); |
+ histograms_ = existing_histograms_.release(); |
+ callbacks_ = existing_callbacks_.release(); |
+ ranges_ = existing_ranges_.release(); |
} |
// static |