This source file includes following definitions.
- bloom_filter_
- AddSample
- GetReport
#include "components/rappor/rappor_metric.h"
#include "base/logging.h"
namespace rappor {
RapporMetric::RapporMetric(const std::string& metric_name,
const RapporParameters& parameters,
int32_t cohort)
: metric_name_(metric_name),
parameters_(parameters),
bloom_filter_(parameters.bloom_filter_size_bytes,
parameters.bloom_filter_hash_function_count,
cohort * parameters.bloom_filter_hash_function_count) {
DCHECK_GE(cohort, 0);
}
RapporMetric::~RapporMetric() {}
void RapporMetric::AddSample(const std::string& str) {
bloom_filter_.AddString(str);
}
ByteVector RapporMetric::GetReport(const std::string& secret) const {
const std::string personalization_string = metric_name_ +
std::string(bytes().begin(), bytes().end());
HmacByteVectorGenerator hmac_generator(bytes().size(), secret,
personalization_string);
const ByteVector fake_mask =
hmac_generator.GetWeightedRandomByteVector(parameters().fake_prob);
ByteVector fake_bits =
hmac_generator.GetWeightedRandomByteVector(parameters().fake_one_prob);
const ByteVector* fake_and_redacted_bits =
ByteVectorMerge(fake_mask, bytes(), &fake_bits);
ByteVectorGenerator coin_generator(bytes().size());
const ByteVector zero_coins =
coin_generator.GetWeightedRandomByteVector(parameters().zero_coin_prob);
ByteVector one_coins =
coin_generator.GetWeightedRandomByteVector(parameters().one_coin_prob);
return *ByteVectorMerge(*fake_and_redacted_bits, zero_coins, &one_coins);
}
}