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

Unified 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 side-by-side diff with in-line comments
Download patch
« components/rappor/sampler.h ('K') | « components/rappor/sampler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/rappor/sampler.cc
diff --git a/components/rappor/sampler.cc b/components/rappor/sampler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6273288b362fcfd09503f1311d799f7564187c62
--- /dev/null
+++ b/components/rappor/sampler.cc
@@ -0,0 +1,36 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/rappor/sampler.h"
+
+#include <map>
+#include <string>
+
+#include "base/rand_util.h"
+
+namespace rappor {
+
+Sampler::Sampler() {}
+
+Sampler::~Sampler() {}
+
+void Sampler::AddSample(const std::string& metric_name,
+ scoped_ptr<Sample> sample) {
+ ++sample_counts_[metric_name];
+ // Replace the previous sample with a 1 in sample_count_ chance so that each
+ // sample has equal probability of being reported.
+ if (base::RandGenerator(sample_counts_[metric_name]) == 0) {
+ samples_.set(metric_name, sample.Pass());
+ }
+}
+
+void Sampler::ExportMetrics(const std::string& secret, RapporReports* reports) {
+ 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.
+ it->second->ExportMetrics(secret, it->first, reports);
+ }
+ samples_.clear();
+ sample_counts_.clear();
+}
+
+} // namespace rappor
« 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