Reland: Change the video color space default.
[chromium-blink-merge.git] / components / rappor / sampler.h
blobdac87416be5e4570cd100f96a61e43dfc43e5082
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.
5 #ifndef COMPONENTS_RAPPOR_SAMPLER_H_
6 #define COMPONENTS_RAPPOR_SAMPLER_H_
8 #include <map>
9 #include <string>
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"
17 namespace rappor {
19 class RapporReports;
21 namespace internal {
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();
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);
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);
39 private:
40 // The number of samples recorded for each metric since the last export.
41 std::map<std::string, int> sample_counts_;
43 // Stores a Sample for each metric, by metric name.
44 base::ScopedPtrHashMap<std::string, scoped_ptr<Sample>> samples_;
46 DISALLOW_COPY_AND_ASSIGN(Sampler);
49 } // namespace internal
51 } // namespace rappor
53 #endif // COMPONENTS_RAPPOR_SAMPLER_H_