Chromium Code Reviews| Index: components/rappor/rappor_recorder.h |
| diff --git a/components/rappor/rappor_recorder.h b/components/rappor/rappor_recorder.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e8acd4a30facbe4eaeffd94aebbda207cfb5d53d |
| --- /dev/null |
| +++ b/components/rappor/rappor_recorder.h |
| @@ -0,0 +1,66 @@ |
| +// Copyright (c) 2013 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. |
| + |
| +// RapporRecorder holds all Rappors collected in the system, and methods for |
| +// retrieving the recorded data. |
| + |
| +#ifndef COMPONENTS_RAPPOR_RAPPOR_RECORDER_H_ |
| +#define COMPONENTS_RAPPOR_RAPPOR_RECORDER_H_ |
| + |
| +#include <map> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/gtest_prod_util.h" |
| +#include "base/lazy_instance.h" |
| +#include "base/synchronization/lock.h" |
| +#include "components/rappor/rappor.h" |
| + |
| +#define RAPPOR_SAMPLES(parameters, samples) \ |
| + rappor::g_rappor_recorder.Get().RecordSamples(parameters, samples); |
|
Alexei Svitkine (slow)
2013/12/19 19:47:02
I don't think we should have a global recorder or
Steven Holte
2013/12/20 03:03:55
Collapsed this class into RapporService
|
| + |
| +namespace rappor { |
| + |
| +class RapporRecorder { |
| + public: |
| + typedef std::vector<Rappor*> Rappors; |
|
Alexei Svitkine (slow)
2013/12/19 19:47:02
This should use a ScopedVector<Rappor>.
Steven Holte
2013/12/20 03:03:55
N/A, since RapporService just directly iterates ov
|
| + |
| + // Removes all of the collected rappor metrics from the RapporRecorder, and |
| + // stores them in the output list. The caller is responsible for deleting |
| + // Rappor objects. |
| + void CollectRappors(Rappors* output); |
| + |
| + // Deletes all of the rappors in a list. |
| + static void DeleteRappors(Rappors* rappors); |
| + |
| + // Find a rappor by name, and create it if it doesn't already exist, and adds |
| + // samples to it. This method is thread safe. |
| + void RecordSamples(const RapporParameters* parameters, |
| + const std::vector<std::string>& samples); |
| + |
| + // The constructor just initializes static members. Usually client code should |
| + // use Initialize to do this. But in test code, you can friend this class and |
| + // call destructor/constructor to get a clean RapporRecorder. |
| + RapporRecorder(); |
|
Alexei Svitkine (slow)
2013/12/19 19:47:02
These should be before any other methods.
Steven Holte
2013/12/20 03:03:55
N/A
|
| + ~RapporRecorder(); |
| + |
| + private: |
| + // Find a rappor by name, and create it if it doesn't already exist. |
| + Rappor* GetRappor(const RapporParameters* parameters); |
| + |
| + // We keep all registered histograms in a map, from name to histogram. |
| + typedef std::map<std::string, Rappor*> RapporMap; |
| + |
| + RapporMap rappors_; |
| + |
| + // Lock protects access to above map. |
| + base::Lock lock_; |
| +}; |
| + |
| +extern base::LazyInstance<RapporRecorder>::Leaky g_rappor_recorder; |
| + |
| +} // namespace rappor |
| + |
| +#endif // COMPONENTS_RAPPOR_RAPPOR_RECORDER_H_ |