| Index: base/metrics/histogram_snapshot_manager.cc
|
| diff --git a/base/metrics/histogram_snapshot_manager.cc b/base/metrics/histogram_snapshot_manager.cc
|
| index f641d44f1154bff8d15930b94f93caa93b1298d0..7778ca09ce5330458f7b8399eb50cdfb02809339 100644
|
| --- a/base/metrics/histogram_snapshot_manager.cc
|
| +++ b/base/metrics/histogram_snapshot_manager.cc
|
| @@ -31,6 +31,8 @@ void HistogramSnapshotManager::StartDeltas() {
|
| DCHECK(!preparing_deltas_);
|
| preparing_deltas_ = true;
|
|
|
| + DCHECK(owned_histograms_.empty());
|
| +
|
| #ifdef DEBUG
|
| for (auto iter : known_histograms) {
|
| CHECK(!iter->second.histogram);
|
| @@ -41,26 +43,46 @@ void HistogramSnapshotManager::StartDeltas() {
|
| }
|
|
|
| void HistogramSnapshotManager::PrepareDelta(HistogramBase* histogram) {
|
| - PrepareSamples(histogram, histogram->SnapshotDelta());
|
| + PrepareSamples(histogram, histogram->SnapshotDelta(), false);
|
| +}
|
| +
|
| +void HistogramSnapshotManager::PrepareDeltaTakingOwnership(
|
| + HistogramBase* histogram) {
|
| + PrepareSamples(histogram, histogram->SnapshotDelta(), true);
|
| }
|
|
|
| void HistogramSnapshotManager::PrepareOnce(const HistogramBase* histogram) {
|
| - PrepareSamples(histogram, histogram->SnapshotSamples());
|
| + PrepareSamples(histogram, histogram->SnapshotSamples(), false);
|
| +}
|
| +
|
| +void HistogramSnapshotManager::PrepareOnceTakingOwnership(
|
| + const HistogramBase* histogram) {
|
| + PrepareSamples(histogram, histogram->SnapshotSamples(), true);
|
| }
|
|
|
| void HistogramSnapshotManager::PrepareSamples(
|
| const HistogramBase* histogram,
|
| - scoped_ptr<HistogramSamples> samples) {
|
| + scoped_ptr<HistogramSamples> samples,
|
| + bool take_ownership) {
|
| DCHECK(histogram_flattener_);
|
| + scoped_ptr<const HistogramBase> owned_histogram;
|
|
|
| // Get information known about this histogram.
|
| SampleInfo* sample_info = &known_histograms_[histogram->name_hash()];
|
| if (sample_info->histogram) {
|
| DCHECK_EQ(sample_info->histogram->histogram_name(),
|
| histogram->histogram_name()) << "hash collision";
|
| + // Passed histogram won't be needed past end of this method so store
|
| + // it in a scoped_ptr that will release it when returning.
|
| + if (take_ownership)
|
| + owned_histogram.reset(histogram);
|
| } else {
|
| // First time this histogram has been seen; datafill.
|
| sample_info->histogram = histogram;
|
| + // The histogram data will be needed up until "finished" so store
|
| + // in member vector for releasing when that is done.
|
| + if (take_ownership)
|
| + owned_histograms_.push_back(histogram);
|
| }
|
|
|
| // Crash if we detect that our histograms have been overwritten. This may be
|
| @@ -131,6 +153,10 @@ void HistogramSnapshotManager::FinishDeltas() {
|
| sample_info->histogram = nullptr;
|
| }
|
|
|
| + STLDeleteContainerPointers(owned_histograms_.begin(),
|
| + owned_histograms_.end());
|
| + owned_histograms_.clear();
|
| +
|
| preparing_deltas_ = false;
|
| }
|
|
|
|
|