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

Unified Diff: components/rappor/rappor_metric.cc

Issue 49753002: RAPPOR implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: RapporMetric Created 7 years 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..459ffca084797603ad2e3cb5c9ce6775cc6af479
--- /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(); }
+
+ByteVector RapporMetric::GetReport(const std::string& secret) 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);
+ const ByteVector fake_ones =
+ hmac_generator.GetWeightedRandomByteVector(parameters()->fake_one_prob);
+
+ const ByteVector* onebits = ByteVectorMerge(&real_bits, fake_ones, fake_mask);
+
+ ByteVectorGenerator coinGenerator(real_bits.size());
+ ByteVector zero_coins =
+ coinGenerator.GetWeightedRandomByteVector(parameters()->zero_coin_prob);
+ const ByteVector one_coins =
+ coinGenerator.GetWeightedRandomByteVector(parameters()->one_coin_prob);
+
+ const ByteVector* output = ByteVectorMerge(&zero_coins, one_coins, *onebits);
+
+ return *output;
+}
+
+} // namespace rappor

Powered by Google App Engine
This is Rietveld 408576698