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

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

Issue 1090683003: Alternative Multi-dimensional Rappor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Exporting and Test 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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/sample.h"
6
7 #include <map>
8 #include <string>
9
10 #include "base/logging.h"
11 #include "components/metrics/metrics_hashes.h"
12 #include "components/rappor/bloom_filter.h"
13 #include "components/rappor/byte_vector_utils.h"
14 #include "components/rappor/proto/rappor_metric.pb.h"
15 #include "components/rappor/reports.h"
16
17 namespace rappor {
18
19 Sample::Sample(int32_t cohort_seed, const RapporParameters& parameters)
20 : parameters_(parameters),
21 bloom_offset_((cohort_seed % parameters_.num_cohorts) *
22 parameters_.bloom_filter_hash_function_count) {
23 }
24
25 Sample::~Sample() {
26
Alexei Svitkine (slow) 2015/04/22 21:00:13 Nit: Remove empty line
Steven Holte 2015/04/22 21:59:32 Done.
27 }
28
29 void Sample::SetStringField(const std::string& field_name,
30 const std::string& value) {
31 DCHECK_EQ(0u, sizes_[field_name]);
32 fields_[field_name] = internal::GetBloomBits(
33 parameters_.bloom_filter_size_bytes,
34 parameters_.bloom_filter_hash_function_count,
35 bloom_offset_,
36 value);
37 sizes_[field_name] = parameters_.bloom_filter_size_bytes;
38 }
39
40 void Sample::SetFlagsField(const std::string& field_name,
41 uint64_t flags, size_t num_flags) {
Alexei Svitkine (slow) 2015/04/22 21:00:13 1 param per line.
Steven Holte 2015/04/22 21:59:32 Done.
42 DCHECK_EQ(0u, sizes_[field_name]);
43 DCHECK_GT(num_flags, 0u);
44 DCHECK_LE(num_flags, 64u);
45 DCHECK(num_flags == 64u || flags >> num_flags == 0);
46 fields_[field_name] = flags;
47 sizes_[field_name] = (num_flags + 7) / 8;
48 }
49
50 void Sample::ExportMetrics(const std::string& secret,
51 const std::string& metric_name,
52 RapporReports* reports) const {
53 for (const auto& kv : fields_) {
54 uint64_t value = kv.second;
55 size_t size = sizes_.at(kv.first);
56 ByteVector value_bytes(size);
57 for (size_t i = 0; i < size; i++) {
58 value_bytes[i] = (value & (0xff << (i * 8))) >> (i * 8);
59 }
60 ByteVector report_bytes = internal::GenerateReport(
61 secret, parameters_, value_bytes);
62
63 RapporReports::Report* report = reports->add_report();
64 report->set_name_hash(metrics::HashMetricName(
65 metric_name + "." + kv.first));
66 report->set_bits(std::string(report_bytes.begin(), report_bytes.end()));
67 }
68 }
69
70 } // namespace rappor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698