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

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: 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 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
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