Chromium Code Reviews| Index: base/metrics/histogram_snapshot_manager.h |
| diff --git a/base/metrics/histogram_snapshot_manager.h b/base/metrics/histogram_snapshot_manager.h |
| index c105e8a1d3e7f9ef042debba39d8ce2fdcda3bba..46cf2417d8effaaf446d76d4a12e822c545ae290 100644 |
| --- a/base/metrics/histogram_snapshot_manager.h |
| +++ b/base/metrics/histogram_snapshot_manager.h |
| @@ -9,6 +9,7 @@ |
| #include <map> |
| #include <string> |
| +#include <vector> |
| #include "base/gtest_prod_util.h" |
| #include "base/macros.h" |
| @@ -61,9 +62,14 @@ class BASE_EXPORT HistogramSnapshotManager { |
| // until FinishDeltas() completes. PrepareAbsolute() works the same |
| // but assumes there were no previous logged values and no future deltas |
| // will be created (and thus can work on read-only histograms). |
| + // Use Prepare*TakingOwnership() if it is desireable to have this class |
| + // automatically delete the histogram once it is "finished". |
| void StartDeltas(); |
| void PrepareDelta(HistogramBase* histogram); |
| + void PrepareDeltaTakingOwnership(scoped_ptr<HistogramBase> histogram); |
| void PrepareAbsolute(const HistogramBase* histogram); |
| + void PrepareAbsoluteTakingOwnership( |
| + scoped_ptr<const HistogramBase> histogram); |
| void FinishDeltas(); |
| private: |
| @@ -75,30 +81,27 @@ class BASE_EXPORT HistogramSnapshotManager { |
| // information that must persist from one report to the next, such as |
| // the "inconsistencies". |
| struct SampleInfo { |
| - SampleInfo() : histogram(nullptr), |
| - accumulated_samples(nullptr), |
| - inconsistencies(0) {} |
| - |
| // A histogram associated with this sample; it may be one of many if |
| // several have been aggregated into the same "accumulated" sample set. |
| // Ownership of the histogram remains elsewhere and this pointer is |
| // cleared by FinishDeltas(). |
| - const HistogramBase* histogram; |
| + const HistogramBase* histogram = nullptr; |
| // The current snapshot-delta values being accumulated. |
| // TODO(bcwhite): Change this to a scoped_ptr once all build architectures |
| // support such as the value of a std::map. |
| - HistogramSamples* accumulated_samples; |
| + HistogramSamples* accumulated_samples = nullptr; |
| // The set of inconsistencies (flags) already seen for the histogram. |
| // See HistogramBase::Inconsistency for values. |
| - unsigned inconsistencies; |
| + unsigned inconsistencies = 0; |
|
grt (UTC plus 2)
2016/02/18 16:44:07
this should explicitly be uint3_t or another sized
bcwhite
2016/02/18 19:35:01
Done.
|
| }; |
| // Capture and hold samples from a histogram. This does all the heavy |
| // lifting for PrepareDelta() and PrepareAbsolute(). |
| void PrepareSamples(const HistogramBase* histogram, |
| - scoped_ptr<HistogramSamples> samples); |
| + scoped_ptr<HistogramSamples> samples, |
| + bool take_ownership); |
| // Try to detect and fix count inconsistency of logged samples. |
| void InspectLoggedSamplesInconsistency( |
| @@ -109,6 +112,10 @@ class BASE_EXPORT HistogramSnapshotManager { |
| // by the hash of the histogram name. |
| std::map<uint64_t, SampleInfo> known_histograms_; |
| + // Collection of histograms of which ownership has been passed to this |
| + // object. They will be deleted by FinishDeltas(). |
| + std::vector<scoped_ptr<const HistogramBase>> owned_histograms_; |
| + |
| // Indicates if deltas are currently being prepared. |
| bool preparing_deltas_; |