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