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_SAMPLER_H_ |
| 6 #define COMPONENTS_RAPPOR_SAMPLER_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 |
| 11 #include "base/containers/scoped_ptr_hash_map.h" |
| 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "components/rappor/rappor_parameters.h" |
| 15 #include "components/rappor/sample.h" |
| 16 |
| 17 namespace rappor { |
| 18 |
| 19 class RapporReports; |
| 20 |
| 21 namespace internal { |
| 22 |
| 23 // Sampler manages the collection and storage of Sample objects. |
| 24 // For each metric name, it will randomly select one Sample to store and |
| 25 // use when generating RapporReports. |
| 26 class Sampler { |
| 27 public: |
| 28 Sampler(); |
| 29 ~Sampler(); |
| 30 |
| 31 // Store this sample for metric name, randomly selecting a sample if |
| 32 // others have already been recorded. |
| 33 void AddSample(const std::string& metric_name, scoped_ptr<Sample> sample); |
| 34 |
| 35 // Generate randomized reports for all stored samples and store them |
| 36 // in |reports|, then discard the samples. |
| 37 void ExportMetrics(const std::string& secret, RapporReports* reports); |
| 38 |
| 39 private: |
| 40 // The number of samples recorded for each metric since the last export. |
| 41 std::map<std::string, int> sample_counts_; |
| 42 |
| 43 // Stores a Sample for each metric, by metric name. |
| 44 base::ScopedPtrHashMap<std::string, Sample> samples_; |
| 45 |
| 46 DISALLOW_COPY_AND_ASSIGN(Sampler); |
| 47 }; |
| 48 |
| 49 } // namespace internal |
| 50 |
| 51 } // namespace rappor |
| 52 |
| 53 #endif // COMPONENTS_RAPPOR_SAMPLER_H_ |
OLD | NEW |