Chromium Code Reviews| 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); | |
|
Alexei Svitkine (slow)
2015/04/22 21:00:13
Could you add a unit test for this class?
i.e. th
Steven Holte
2015/04/22 21:59:32
Done.
| |
| 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 // We keep all registered metrics in a map, from name to metric. | |
| 44 // The map owns the metrics it contains. | |
|
Alexei Svitkine (slow)
2015/04/22 21:00:13
Nit: Last line is uneccessary since the map type i
Steven Holte
2015/04/22 21:59:32
Done.
| |
| 45 base::ScopedPtrHashMap<std::string, Sample> samples_; | |
| 46 | |
| 47 DISALLOW_COPY_AND_ASSIGN(Sampler); | |
| 48 }; | |
| 49 | |
| 50 } // namespace internal | |
| 51 | |
| 52 } // namespace rappor | |
| 53 | |
| 54 #endif // COMPONENTS_RAPPOR_SAMPLER_H_ | |
| OLD | NEW |