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

Unified Diff: components/rappor/rappor_metric.h

Issue 49753002: RAPPOR implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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/proto/rappor_metric.proto ('k') | components/rappor/rappor_metric.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/rappor/rappor_metric.h
diff --git a/components/rappor/rappor_metric.h b/components/rappor/rappor_metric.h
new file mode 100644
index 0000000000000000000000000000000000000000..30147c406851fabfc95aba5eb502da05d454784e
--- /dev/null
+++ b/components/rappor/rappor_metric.h
@@ -0,0 +1,56 @@
+// 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.
+
+#ifndef COMPONENTS_RAPPOR_RAPPOR_H_
+#define COMPONENTS_RAPPOR_RAPPOR_H_
+
+#include <string>
+
+#include "components/rappor/bloom_filter.h"
+#include "components/rappor/byte_vector_utils.h"
+#include "components/rappor/rappor_parameters.h"
+
+namespace rappor {
+
+// A RapporMetric is an object that collects string samples into a Bloom filter,
+// and generates randomized reports about the collected data.
+//
+// For a full description of the rappor metrics, see
+// http://www.chromium.org/developers/design-documents/rappor
+class RapporMetric {
+ public:
+ // Takes the |metric_name| that this will be reported to the server with,
+ // a |parameters| describing size and probability weights to be used in
+ // recording this metric, and cohort value, which modifies the hash
+ // functions and used in the bloom filter.
+ explicit RapporMetric(const std::string& metric_name,
+ const RapporParameters& parameters,
+ int32_t cohort);
+ ~RapporMetric();
+
+ // Records an additional sample in the Bloom filter.
+ void AddSample(const std::string& str);
+
+ // Retrieves the current Bloom filter bits.
+ const ByteVector& bytes() const { return bloom_filter_.bytes(); }
+
+ // Gets the parameter values this metric was constructed with.
+ const RapporParameters& parameters() const { return parameters_; }
+
+ // Generates the bits to report for this metric. Using the secret as a seed,
+ // randomly selects bits for redaction. Then flips coins to generate the
+ // final report bits.
+ ByteVector GetReport(const std::string& secret) const;
+
+ private:
+ const std::string metric_name_;
+ const RapporParameters parameters_;
+ BloomFilter bloom_filter_;
+
+ DISALLOW_COPY_AND_ASSIGN(RapporMetric);
+};
+
+} // namespace rappor
+
+#endif // COMPONENTS_RAPPOR_RAPPOR_H_
« no previous file with comments | « components/rappor/proto/rappor_metric.proto ('k') | components/rappor/rappor_metric.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698