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

Side by Side Diff: components/rappor/sampler.cc

Issue 1921923002: Convert //components/[o-t]* from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . 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 | « components/rappor/sampler.h ('k') | components/rappor/sampler_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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/rappor/sampler.h" 5 #include "components/rappor/sampler.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/rand_util.h" 11 #include "base/rand_util.h"
12 12
13 namespace rappor { 13 namespace rappor {
14 14
15 namespace internal { 15 namespace internal {
16 16
17 Sampler::Sampler() {} 17 Sampler::Sampler() {}
18 18
19 Sampler::~Sampler() {} 19 Sampler::~Sampler() {}
20 20
21 void Sampler::AddSample(const std::string& metric_name, 21 void Sampler::AddSample(const std::string& metric_name,
22 scoped_ptr<Sample> sample) { 22 std::unique_ptr<Sample> sample) {
23 ++sample_counts_[metric_name]; 23 ++sample_counts_[metric_name];
24 // Replace the previous sample with a 1 in sample_count_ chance so that each 24 // Replace the previous sample with a 1 in sample_count_ chance so that each
25 // sample has equal probability of being reported. 25 // sample has equal probability of being reported.
26 if (base::RandGenerator(sample_counts_[metric_name]) == 0) 26 if (base::RandGenerator(sample_counts_[metric_name]) == 0)
27 samples_.set(metric_name, std::move(sample)); 27 samples_.set(metric_name, std::move(sample));
28 } 28 }
29 29
30 void Sampler::ExportMetrics(const std::string& secret, RapporReports* reports) { 30 void Sampler::ExportMetrics(const std::string& secret, RapporReports* reports) {
31 for (const auto& kv : samples_) { 31 for (const auto& kv : samples_) {
32 kv.second->ExportMetrics(secret, kv.first, reports); 32 kv.second->ExportMetrics(secret, kv.first, reports);
33 } 33 }
34 samples_.clear(); 34 samples_.clear();
35 sample_counts_.clear(); 35 sample_counts_.clear();
36 } 36 }
37 37
38 } // namespace internal 38 } // namespace internal
39 39
40 } // namespace rappor 40 } // namespace rappor
OLDNEW
« no previous file with comments | « components/rappor/sampler.h ('k') | components/rappor/sampler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698