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.
5 #ifndef COMPONENTS_RAPPOR_SAMPLE_H_
6 #define COMPONENTS_RAPPOR_SAMPLE_H_
11 #include "base/basictypes.h"
12 #include "base/macros.h"
13 #include "components/rappor/rappor_parameters.h"
19 class TestSamplerFactory
;
21 // Sample is a container for information about a single instance of some event
22 // we are sending Rappor data about. It may contain multiple different fields,
23 // which describe different details of the event, and they will be sent in the
24 // same Rappor report, enabling analysis of correlations between those fields.
29 // Sets a string value field in this sample.
30 void SetStringField(const std::string
& field_name
, const std::string
& value
);
32 // Sets a group of boolean flags as a field in this sample.
33 // |flags| should be a set of boolean flags stored in the lowest |num_flags|
35 void SetFlagsField(const std::string
& field_name
,
39 // Generate randomized reports and store them in |reports|.
40 void ExportMetrics(const std::string
& secret
,
41 const std::string
& metric_name
,
42 RapporReports
* reports
) const;
44 const RapporParameters
& parameters() { return parameters_
; }
47 friend class TestSamplerFactory
;
48 friend class RapporService
;
50 // Constructs a sample. Instead of calling this directly, call
51 // RapporService::MakeSampleObj to create a sample.
52 Sample(int32_t cohort_seed
, const RapporParameters
& parameters
);
54 const RapporParameters parameters_
;
56 // Offset used for bloom filter hash functions.
57 uint32_t bloom_offset_
;
59 // Size of each of the different fields, in bytes.
60 std::map
<std::string
, size_t> sizes_
;
62 // The non-randomized report values for each field.
63 std::map
<std::string
, uint64_t> fields_
;
65 DISALLOW_COPY_AND_ASSIGN(Sample
);
70 #endif // COMPONENTS_RAPPOR_SAMPLE_H_