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_
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"
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.
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
);
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
53 #endif // COMPONENTS_RAPPOR_SAMPLER_H_