Chromium Code Reviews| Index: components/rappor/sampler.h |
| diff --git a/components/rappor/sampler.h b/components/rappor/sampler.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a5b1339cd88820b71fe0510899878d6abb21fc43 |
| --- /dev/null |
| +++ b/components/rappor/sampler.h |
| @@ -0,0 +1,54 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_RAPPOR_SAMPLER_H_ |
| +#define COMPONENTS_RAPPOR_SAMPLER_H_ |
| + |
| +#include <map> |
| +#include <string> |
| + |
| +#include "base/containers/scoped_ptr_hash_map.h" |
| +#include "base/macros.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "components/rappor/rappor_parameters.h" |
| +#include "components/rappor/sample.h" |
| + |
| +namespace rappor { |
| + |
| +class RapporReports; |
| + |
| +namespace internal { |
| + |
| +// Sampler manages the collection and storage of Sample objects. |
| +// For each metric name, it will randomly select one Sample to store and |
| +// use when generating RapporReports. |
| +class Sampler { |
| + public: |
| + Sampler(); |
| + ~Sampler(); |
| + |
| + // Store this sample for metric name, randomly selecting a sample if |
| + // others have already been recorded. |
| + void AddSample(const std::string& metric_name, scoped_ptr<Sample> sample); |
| + |
| + // Generate randomized reports for all stored samples and store them |
| + // in |reports|, then discard the samples. |
| + 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.
|
| + |
| + private: |
| + // The number of samples recorded for each metric since the last export. |
| + std::map<std::string, int> sample_counts_; |
| + |
| + // We keep all registered metrics in a map, from name to metric. |
| + // 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.
|
| + base::ScopedPtrHashMap<std::string, Sample> samples_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Sampler); |
| +}; |
| + |
| +} // namespace internal |
| + |
| +} // namespace rappor |
| + |
| +#endif // COMPONENTS_RAPPOR_SAMPLER_H_ |