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

Unified Diff: components/rappor/rappor_metric.cc

Issue 1058333002: Multi-dimension rappor metrics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup and add xml support Created 5 years, 8 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
« no previous file with comments | « components/rappor/rappor_metric.h ('k') | components/rappor/rappor_metric_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/rappor/rappor_metric.cc
diff --git a/components/rappor/rappor_metric.cc b/components/rappor/rappor_metric.cc
index 862ead8933a0612026378722dca0abeab8398242..e56d5a882f9a932d89af87a21c3ebbb3e074a6e2 100644
--- a/components/rappor/rappor_metric.cc
+++ b/components/rappor/rappor_metric.cc
@@ -6,34 +6,51 @@
#include "base/logging.h"
#include "base/rand_util.h"
+#include "components/rappor/bloom_filter.h"
namespace rappor {
-RapporMetric::RapporMetric(const std::string& metric_name,
- const RapporParameters& parameters,
- int32_t cohort_seed)
- : metric_name_(metric_name),
- parameters_(parameters),
- sample_count_(0),
- bloom_filter_(parameters.bloom_filter_size_bytes,
- parameters.bloom_filter_hash_function_count,
- (cohort_seed % parameters.num_cohorts) *
- parameters.bloom_filter_hash_function_count) {
+namespace internal {
+
+void SetSampleBits(const RapporParameters& parameters, int32_t cohort_seed,
+ const std::string& str, uint64_t flags, Sample* output) {
DCHECK_GE(cohort_seed, 0);
DCHECK_LT(cohort_seed, RapporParameters::kMaxCohorts);
// Since cohort_seed is in the range [0, kMaxCohorts), num_cohorts should
// divide kMaxCohorts for each cohort to have equal weight.
DCHECK_EQ(0, RapporParameters::kMaxCohorts % parameters.num_cohorts);
+ output->resize(parameters.bloom_filter_size_bytes + parameters.flag_bytes);
+ internal::SetBloomBits(parameters.bloom_filter_size_bytes,
+ parameters.bloom_filter_hash_function_count,
+ (cohort_seed % parameters.num_cohorts) *
+ parameters.bloom_filter_hash_function_count,
+ str,
+ output);
+ DCHECK_LE(parameters.flag_bytes, 8);
+ if (parameters.flag_bytes != 8)
+ DCHECK_EQ(0ul, flags >> (parameters.flag_bytes * 8));
+ for(int i = 0; i < parameters.flag_bytes; i++) {
+ uint8_t flag_byte = (flags >> (i * 8)) % (1 << 8);
+ (*output)[parameters.bloom_filter_size_bytes + i] = flag_byte;
+ }
+}
+
+RapporMetric::RapporMetric(const std::string& metric_name,
+ const RapporParameters& parameters)
+ : metric_name_(metric_name),
+ parameters_(parameters),
+ sample_count_(0),
+ sample_(parameters.bloom_filter_size_bytes + parameters.flag_bytes) {
}
RapporMetric::~RapporMetric() {}
-void RapporMetric::AddSample(const std::string& str) {
+void RapporMetric::AddSample(const Sample& sample) {
++sample_count_;
// Replace the previous sample with a 1 in sample_count_ chance so that each
// sample has equal probability of being reported.
if (base::RandGenerator(sample_count_) == 0) {
- bloom_filter_.SetString(str);
+ sample_ = sample;
}
}
@@ -69,8 +86,10 @@ ByteVector RapporMetric::GetReport(const std::string& secret) const {
return *ByteVectorMerge(*fake_and_redacted_bits, zero_coins, &one_coins);
}
-void RapporMetric::SetBytesForTesting(const ByteVector& bytes) {
- bloom_filter_.SetBytesForTesting(bytes);
+void RapporMetric::SetSampleForTesting(const Sample& sample) {
+ sample_ = sample;
}
+} // namespace internal
+
} // namespace rappor
« no previous file with comments | « components/rappor/rappor_metric.h ('k') | components/rappor/rappor_metric_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698