Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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_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 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.
| |
| 21 | |
| 22 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.
| |
| 23 const ByteVector real_bits(GetBytes()); | |
| 24 | |
| 25 HmacByteVectorGenerator hmac_generator(real_bits.size(), | |
| 26 secret + parameters()->rappor_name); | |
| 27 const ByteVector fake_mask = | |
| 28 hmac_generator.GetWeightedRandomByteVector(parameters()->fake_prob); | |
| 29 ByteVector fake_ones = | |
| 30 hmac_generator.GetWeightedRandomByteVector(parameters()->fake_one_prob); | |
| 31 | |
| 32 const ByteVector* onebits = ByteVectorMerge(fake_mask, real_bits, &fake_ones); | |
| 33 | |
| 34 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.
| |
| 35 const ByteVector zero_coins = | |
| 36 coinGenerator.GetWeightedRandomByteVector(parameters()->zero_coin_prob); | |
| 37 ByteVector one_coins = | |
| 38 coinGenerator.GetWeightedRandomByteVector(parameters()->one_coin_prob); | |
| 39 | |
| 40 const ByteVector* output = ByteVectorMerge(*onebits, zero_coins, &one_coins); | |
| 41 | |
| 42 return *output; | |
| 43 } | |
| 44 | |
| 45 } // namespace rappor | |
| OLD | NEW |