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

Unified Diff: base/metrics/statistics_recorder.h

Issue 1779503002: Fix StatisticsRecorder to handle re-entry during tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: always do global UninitializeForTesting when uninitializing Created 4 years, 8 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/sparse_histogram_unittest.cc ('k') | base/metrics/statistics_recorder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/statistics_recorder.h
diff --git a/base/metrics/statistics_recorder.h b/base/metrics/statistics_recorder.h
index 12543b8d91e35b3b98dbf609195caefbcb0759d6..2fa03f9b2f14664653b5ff6ce62d4626f91eca5b 100644
--- a/base/metrics/statistics_recorder.h
+++ b/base/metrics/statistics_recorder.h
@@ -14,6 +14,7 @@
#include <list>
#include <map>
+#include <memory>
#include <string>
#include <vector>
@@ -164,15 +165,15 @@ class BASE_EXPORT StatisticsRecorder {
// Returns the number of known histograms.
static size_t GetHistogramCount();
- // Clears all of the known histograms and resets static variables to a
- // state that allows a new initialization.
- static void ResetForTesting();
-
// Removes a histogram from the internal set of known ones. This can be
// necessary during testing persistent histograms where the underlying
// memory is being released.
static void ForgetHistogramForTesting(base::StringPiece name);
+ // Reset any global instance of the statistics-recorder that was created
+ // by a call to Initialize().
+ static void UninitializeForTesting();
+
private:
// We keep a map of callbacks to histograms, so that as histograms are
// created, we can set the callback properly.
@@ -199,6 +200,13 @@ class BASE_EXPORT StatisticsRecorder {
// call the constructor to get a clean StatisticsRecorder.
StatisticsRecorder();
+ // These are copies of everything that existed when the (test) Statistics-
+ // Recorder was created. The global ones have to be moved aside to create a
+ // clean environment.
+ std::unique_ptr<HistogramMap> existing_histograms_;
+ std::unique_ptr<CallbackMap> existing_callbacks_;
+ std::unique_ptr<RangesMap> existing_ranges_;
+
static void Reset();
static void DumpHistogramsToVlog(void* instance);
« no previous file with comments | « base/metrics/sparse_histogram_unittest.cc ('k') | base/metrics/statistics_recorder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698