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

Side by Side Diff: components/rappor/rappor_metric.cc

Issue 49753002: RAPPOR implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: RapporMetrics StatsTest 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/rappor/rappor_metric.h"
6
7 namespace rappor {
8
9 RapporMetric::RapporMetric(const RapporParameters& parameters)
10 : parameters_(parameters),
11 bloom_(parameters.bloom_filter_size_bytes,
12 parameters.bloom_filter_hash_function_count) {}
13
14 void RapporMetric::AddSamples(const std::vector<std::string>& strings) {
15 bloom_.AddStrings(strings);
16 }
17
18 void RapporMetric::AddSample(const std::string& str) { bloom_.AddString(str); }
19
20 ByteVector RapporMetric::GetReport(const std::string& secret) const {
21 // Start with the real bloom filter data.
22 const ByteVector real_bits(bytes());
23
24 // Generate a deterministically random mask of fake data based on the
25 // client's secret key.
26 HmacByteVectorGenerator hmac_generator(real_bits.size(),
27 secret + parameters()->rappor_name);
28 const ByteVector fake_mask =
29 hmac_generator.GetWeightedRandomByteVector(parameters()->fake_prob);
30 ByteVector fake_ones =
31 hmac_generator.GetWeightedRandomByteVector(parameters()->fake_one_prob);
32
33 // Redact most of the real data by replacing it with the fake data, hiding
34 // and limiting the amount of information an individual client reports on.
35 const ByteVector* redacted_bits =
36 ByteVectorMerge(fake_mask, real_bits, &fake_ones);
37
38 // Generate biased coin flips for each bit.
39 ByteVectorGenerator coin_generator(real_bits.size());
40 const ByteVector zero_coins =
41 coin_generator.GetWeightedRandomByteVector(parameters()->zero_coin_prob);
42 ByteVector one_coins =
43 coin_generator.GetWeightedRandomByteVector(parameters()->one_coin_prob);
44
45 // Use the redacted data to select which coin type is used for each bit in
46 // the final report.
47 const ByteVector* output =
48 ByteVectorMerge(*redacted_bits, zero_coins, &one_coins);
49
50 return *output;
51 }
52
53 } // namespace rappor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698