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

Unified Diff: base/metrics/statistics_recorder.cc

Issue 1779503002: Fix StatisticsRecorder to handle re-entry during tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« base/metrics/statistics_recorder.h ('K') | « base/metrics/statistics_recorder.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« base/metrics/statistics_recorder.h ('K') | « base/metrics/statistics_recorder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698