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

Unified Diff: components/rappor/rappor_metric.cc

Issue 49753002: RAPPOR implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 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
Index: components/rappor/rappor_metric.cc
diff --git a/components/rappor/rappor_metric.cc b/components/rappor/rappor_metric.cc
new file mode 100644
index 0000000000000000000000000000000000000000..dc560ba07e081d39afc40704b489f67329c9b351
--- /dev/null
+++ b/components/rappor/rappor_metric.cc
@@ -0,0 +1,45 @@
+// Copyright (c) 2012 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/rappor_metric.h"
+
+namespace rappor {
+
+RapporMetric::RapporMetric(const RapporParameters& parameters)
+ : parameters_(parameters),
+ bloom_(parameters.bloom_filter_size_bytes,
+ parameters.bloom_filter_hash_count) {}
+
+void RapporMetric::AddSamples(const std::vector<std::string>& strings) {
+ bloom_.AddStrings(strings);
+}
+
+void RapporMetric::AddSample(const std::string& str) { bloom_.AddString(str); }
+
+const ByteVector& RapporMetric::GetBytes() const { return bloom_.bytes(); }
Ilya Sherman 2014/01/10 11:00:32 nit: It's fine to name this method "bytes()" and i
Steven Holte 2014/01/14 00:47:54 Done.
+
+ByteVector RapporMetric::GetReport(const std::string& secret) const {
Ilya Sherman 2014/01/10 11:00:32 It would be very useful to include comments in thi
Steven Holte 2014/01/14 00:47:54 Done.
+ const ByteVector real_bits(GetBytes());
+
+ HmacByteVectorGenerator hmac_generator(real_bits.size(),
+ secret + parameters()->rappor_name);
+ const ByteVector fake_mask =
+ hmac_generator.GetWeightedRandomByteVector(parameters()->fake_prob);
+ ByteVector fake_ones =
+ hmac_generator.GetWeightedRandomByteVector(parameters()->fake_one_prob);
+
+ const ByteVector* onebits = ByteVectorMerge(fake_mask, real_bits, &fake_ones);
+
+ ByteVectorGenerator coinGenerator(real_bits.size());
Ilya Sherman 2014/01/10 11:00:32 nit: coinGenerator -> coin_generator
Steven Holte 2014/01/14 00:47:54 Done.
+ const ByteVector zero_coins =
+ coinGenerator.GetWeightedRandomByteVector(parameters()->zero_coin_prob);
+ ByteVector one_coins =
+ coinGenerator.GetWeightedRandomByteVector(parameters()->one_coin_prob);
+
+ const ByteVector* output = ByteVectorMerge(*onebits, zero_coins, &one_coins);
+
+ return *output;
+}
+
+} // namespace rappor

Powered by Google App Engine
This is Rietveld 408576698