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

Side by Side Diff: base/metrics/sample_map.cc

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 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 unified diff | Download patch
« no previous file with comments | « base/metrics/sample_map.h ('k') | base/metrics/sample_map_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/sample_map.h" 5 #include "base/metrics/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 SampleMap. The logic here is identical 18 // An iterator for going through a SampleMap. The logic here is identical
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 96 }
96 97
97 Count SampleMap::TotalCount() const { 98 Count SampleMap::TotalCount() const {
98 Count count = 0; 99 Count count = 0;
99 for (const auto& entry : sample_counts_) { 100 for (const auto& entry : sample_counts_) {
100 count += entry.second; 101 count += entry.second;
101 } 102 }
102 return count; 103 return count;
103 } 104 }
104 105
105 scoped_ptr<SampleCountIterator> SampleMap::Iterator() const { 106 std::unique_ptr<SampleCountIterator> SampleMap::Iterator() const {
106 return make_scoped_ptr(new SampleMapIterator(sample_counts_)); 107 return WrapUnique(new SampleMapIterator(sample_counts_));
107 } 108 }
108 109
109 bool SampleMap::AddSubtractImpl(SampleCountIterator* iter, Operator op) { 110 bool SampleMap::AddSubtractImpl(SampleCountIterator* iter, Operator op) {
110 Sample min; 111 Sample min;
111 Sample max; 112 Sample max;
112 Count count; 113 Count count;
113 for (; !iter->Done(); iter->Next()) { 114 for (; !iter->Done(); iter->Next()) {
114 iter->Get(&min, &max, &count); 115 iter->Get(&min, &max, &count);
115 if (min + 1 != max) 116 if (min + 1 != max)
116 return false; // SparseHistogram only supports bucket with size 1. 117 return false; // SparseHistogram only supports bucket with size 1.
117 118
118 sample_counts_[min] += (op == HistogramSamples::ADD) ? count : -count; 119 sample_counts_[min] += (op == HistogramSamples::ADD) ? count : -count;
119 } 120 }
120 return true; 121 return true;
121 } 122 }
122 123
123 } // namespace base 124 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/sample_map.h ('k') | base/metrics/sample_map_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698