OLD | NEW |
(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 <map> |
| 9 #include <string> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/macros.h" |
| 13 #include "components/rappor/rappor_parameters.h" |
| 14 |
| 15 namespace rappor { |
| 16 |
| 17 class RapporReports; |
| 18 class RapporService; |
| 19 class TestSamplerFactory; |
| 20 |
| 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. |
| 25 class Sample { |
| 26 public: |
| 27 ~Sample(); |
| 28 |
| 29 // Sets a string value field in this sample. |
| 30 void SetStringField(const std::string& field_name, const std::string& value); |
| 31 |
| 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| |
| 34 // bits of |flags|. |
| 35 void SetFlagsField(const std::string& field_name, |
| 36 uint64_t flags, |
| 37 size_t num_flags); |
| 38 |
| 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; |
| 43 |
| 44 const RapporParameters& parameters() { return parameters_; } |
| 45 |
| 46 private: |
| 47 friend class TestSamplerFactory; |
| 48 friend class RapporService; |
| 49 |
| 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); |
| 53 |
| 54 const RapporParameters parameters_; |
| 55 |
| 56 // Offset used for bloom filter hash functions. |
| 57 uint32_t bloom_offset_; |
| 58 |
| 59 // Size of each of the different fields, in bytes. |
| 60 std::map<std::string, size_t> sizes_; |
| 61 |
| 62 // The non-randomized report values for each field. |
| 63 std::map<std::string, uint64_t> fields_; |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(Sample); |
| 66 }; |
| 67 |
| 68 } // namespace rappor |
| 69 |
| 70 #endif // COMPONENTS_RAPPOR_SAMPLE_H_ |
OLD | NEW |