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

Unified Diff: components/rappor/sampler.h

Issue 1090683003: Alternative Multi-dimensional Rappor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use 64-bit shift 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
« no previous file with comments | « components/rappor/sample.cc ('k') | components/rappor/sampler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/rappor/sampler.h
diff --git a/components/rappor/sampler.h b/components/rappor/sampler.h
new file mode 100644
index 0000000000000000000000000000000000000000..c2b13e105b0936762b7034a62309a5a90855c5ae
--- /dev/null
+++ b/components/rappor/sampler.h
@@ -0,0 +1,53 @@
+// Copyright 2015 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.
+
+#ifndef COMPONENTS_RAPPOR_SAMPLER_H_
+#define COMPONENTS_RAPPOR_SAMPLER_H_
+
+#include <map>
+#include <string>
+
+#include "base/containers/scoped_ptr_hash_map.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "components/rappor/rappor_parameters.h"
+#include "components/rappor/sample.h"
+
+namespace rappor {
+
+class RapporReports;
+
+namespace internal {
+
+// Sampler manages the collection and storage of Sample objects.
+// For each metric name, it will randomly select one Sample to store and
+// use when generating RapporReports.
+class Sampler {
+ public:
+ Sampler();
+ ~Sampler();
+
+ // Store this sample for metric name, randomly selecting a sample if
+ // others have already been recorded.
+ void AddSample(const std::string& metric_name, scoped_ptr<Sample> sample);
+
+ // Generate randomized reports for all stored samples and store them
+ // in |reports|, then discard the samples.
+ void ExportMetrics(const std::string& secret, RapporReports* reports);
+
+ private:
+ // The number of samples recorded for each metric since the last export.
+ std::map<std::string, int> sample_counts_;
+
+ // Stores a Sample for each metric, by metric name.
+ base::ScopedPtrHashMap<std::string, Sample> samples_;
+
+ DISALLOW_COPY_AND_ASSIGN(Sampler);
+};
+
+} // namespace internal
+
+} // namespace rappor
+
+#endif // COMPONENTS_RAPPOR_SAMPLER_H_
« no previous file with comments | « components/rappor/sample.cc ('k') | components/rappor/sampler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698