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

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

Issue 1090683003: Alternative Multi-dimensional Rappor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Exporting and Test Created 5 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
« components/rappor/sampler.h ('K') | « components/rappor/sampler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
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 namespace internal {
15
16 Sampler::Sampler() {}
17
18 Sampler::~Sampler() {}
19
20 void Sampler::AddSample(const std::string& metric_name,
21 scoped_ptr<Sample> sample) {
22 ++sample_counts_[metric_name];
23 // Replace the previous sample with a 1 in sample_count_ chance so that each
24 // sample has equal probability of being reported.
25 if (base::RandGenerator(sample_counts_[metric_name]) == 0) {
Alexei Svitkine (slow) 2015/04/22 21:00:13 Nit: No {}
Steven Holte 2015/04/22 21:59:32 Done.
26 samples_.set(metric_name, sample.Pass());
27 }
28 }
29
30 void Sampler::ExportMetrics(const std::string& secret, RapporReports* reports) {
31 for (const auto& kv : samples_) {
32 kv.second->ExportMetrics(secret, kv.first, reports);
33 }
34 samples_.clear();
35 sample_counts_.clear();
36 }
37
38 } // namespace internal
39
40 } // namespace rappor
OLDNEW
« components/rappor/sampler.h ('K') | « components/rappor/sampler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698