OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/rappor/sampler.h" | |
6 | |
7 #include <map> | |
8 #include <string> | |
9 | |
10 #include "base/rand_util.h" | |
11 | |
12 namespace rappor { | |
13 | |
14 Sampler::Sampler() {} | |
15 | |
16 Sampler::~Sampler() {} | |
17 | |
18 void Sampler::AddSample(const std::string& metric_name, | |
19 scoped_ptr<Sample> sample) { | |
20 ++sample_counts_[metric_name]; | |
21 // Replace the previous sample with a 1 in sample_count_ chance so that each | |
22 // sample has equal probability of being reported. | |
23 if (base::RandGenerator(sample_counts_[metric_name]) == 0) { | |
24 samples_.set(metric_name, sample.Pass()); | |
25 } | |
26 } | |
27 | |
28 void Sampler::ExportMetrics(const std::string& secret, RapporReports* reports) { | |
29 for (auto it = samples_.begin(); it != samples_.end(); ++it) { | |
Alexei Svitkine (slow)
2015/04/16 15:09:43
Nit: Use C++11 for loop syntax, i.e.
for (const a
Steven Holte
2015/04/22 19:24:28
Done.
| |
30 it->second->ExportMetrics(secret, it->first, reports); | |
31 } | |
32 samples_.clear(); | |
33 sample_counts_.clear(); | |
34 } | |
35 | |
36 } // namespace rappor | |
OLD | NEW |