| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/metrics/persistent_sample_map.h" | 5 #include "base/metrics/persistent_sample_map.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ptr_util.h" |
| 8 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 9 | 10 |
| 10 namespace base { | 11 namespace base { |
| 11 | 12 |
| 12 typedef HistogramBase::Count Count; | 13 typedef HistogramBase::Count Count; |
| 13 typedef HistogramBase::Sample Sample; | 14 typedef HistogramBase::Sample Sample; |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 // An iterator for going through a PersistentSampleMap. The logic here is | 18 // An iterator for going through a PersistentSampleMap. The logic here is |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // loaded before trying to iterate over the map. | 129 // loaded before trying to iterate over the map. |
| 129 const_cast<PersistentSampleMap*>(this)->ImportSamples(kAllSamples); | 130 const_cast<PersistentSampleMap*>(this)->ImportSamples(kAllSamples); |
| 130 | 131 |
| 131 Count count = 0; | 132 Count count = 0; |
| 132 for (const auto& entry : sample_counts_) { | 133 for (const auto& entry : sample_counts_) { |
| 133 count += *entry.second; | 134 count += *entry.second; |
| 134 } | 135 } |
| 135 return count; | 136 return count; |
| 136 } | 137 } |
| 137 | 138 |
| 138 scoped_ptr<SampleCountIterator> PersistentSampleMap::Iterator() const { | 139 std::unique_ptr<SampleCountIterator> PersistentSampleMap::Iterator() const { |
| 139 // Have to override "const" in order to make sure all samples have been | 140 // Have to override "const" in order to make sure all samples have been |
| 140 // loaded before trying to iterate over the map. | 141 // loaded before trying to iterate over the map. |
| 141 const_cast<PersistentSampleMap*>(this)->ImportSamples(kAllSamples); | 142 const_cast<PersistentSampleMap*>(this)->ImportSamples(kAllSamples); |
| 142 return make_scoped_ptr(new PersistentSampleMapIterator(sample_counts_)); | 143 return base::WrapUnique(new PersistentSampleMapIterator(sample_counts_)); |
| 143 } | 144 } |
| 144 | 145 |
| 145 bool PersistentSampleMap::AddSubtractImpl(SampleCountIterator* iter, | 146 bool PersistentSampleMap::AddSubtractImpl(SampleCountIterator* iter, |
| 146 Operator op) { | 147 Operator op) { |
| 147 Sample min; | 148 Sample min; |
| 148 Sample max; | 149 Sample max; |
| 149 Count count; | 150 Count count; |
| 150 for (; !iter->Done(); iter->Next()) { | 151 for (; !iter->Done(); iter->Next()) { |
| 151 iter->Get(&min, &max, &count); | 152 iter->Get(&min, &max, &count); |
| 152 if (min + 1 != max) | 153 if (min + 1 != max) |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 // Stop if it's the value being searched for. | 259 // Stop if it's the value being searched for. |
| 259 if (record->value == until_value) | 260 if (record->value == until_value) |
| 260 return &record->count; | 261 return &record->count; |
| 261 } | 262 } |
| 262 } | 263 } |
| 263 | 264 |
| 264 return nullptr; | 265 return nullptr; |
| 265 } | 266 } |
| 266 | 267 |
| 267 } // namespace base | 268 } // namespace base |
| OLD | NEW |