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

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

Issue 2510803003: Pass RapporService to content/browser/ (Closed)
Patch Set: Fix more compile errors in JNI files Created 4 years 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 #ifndef COMPONENTS_RAPPOR_SAMPLE_H_
6 #define COMPONENTS_RAPPOR_SAMPLE_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include <map>
12 #include <string>
13
14 #include "base/macros.h"
15 #include "components/rappor/rappor_parameters.h"
16
17 namespace rappor {
18
19 class RapporReports;
20 class RapporService;
21 class TestSamplerFactory;
22
23 // Sample is a container for information about a single instance of some event
24 // we are sending Rappor data about. It may contain multiple different fields,
25 // which describe different details of the event, and they will be sent in the
26 // same Rappor report, enabling analysis of correlations between those fields.
27 class Sample {
28 public:
29 virtual ~Sample();
30
31 // Sets a string value field in this sample.
32 virtual void SetStringField(const std::string& field_name,
33 const std::string& value);
34
35 // TODO(holte): Move all callers to the version with NoiseLevel.
36 virtual void SetFlagsField(const std::string& field_name,
37 uint64_t flags,
38 size_t num_flags);
39
40 // Sets a group of boolean flags as a field in this sample, with the
41 // specified noise level.
42 // |flags| should be a set of boolean flags stored in the lowest |num_flags|
43 // bits of |flags|.
44 virtual void SetFlagsField(const std::string& field_name,
45 uint64_t flags,
46 size_t num_flags,
47 NoiseLevel noise_level);
48
49 // Sets an integer value field in this sample, at the given noise level.
50 virtual void SetUInt64Field(const std::string& field_name,
51 uint64_t value,
52 NoiseLevel noise_level);
53
54 // Generate randomized reports and store them in |reports|.
55 virtual void ExportMetrics(const std::string& secret,
56 const std::string& metric_name,
57 RapporReports* reports) const;
58
59 const RapporParameters& parameters() { return parameters_; }
60
61 private:
62 friend class TestSamplerFactory;
63 friend class RapporService;
64 friend class TestSample;
65
66 // Constructs a sample. Instead of calling this directly, call
67 // RapporService::MakeSampleObj to create a sample.
68 Sample(int32_t cohort_seed, const RapporParameters& parameters);
69
70 const RapporParameters parameters_;
71
72 // Offset used for bloom filter hash functions.
73 uint32_t bloom_offset_;
74
75 struct FieldInfo {
76 // Size of the field, in bytes.
77 size_t size;
78 // The non-randomized report value for the field.
79 uint64_t value;
80 // The noise level to use when creating a report for the field.
81 NoiseLevel noise_level;
82 };
83
84 // Information about all recorded fields.
85 std::map<std::string, FieldInfo> field_info_;
86
87 DISALLOW_COPY_AND_ASSIGN(Sample);
88 };
89
90 } // namespace rappor
91
92 #endif // COMPONENTS_RAPPOR_SAMPLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698