Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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. | |
| 4 | |
| 5 // RapporRecorder holds all Rappors collected in the system, and methods for | |
| 6 // retrieving the recorded data. | |
| 7 | |
| 8 #ifndef COMPONENTS_RAPPOR_RAPPOR_RECORDER_H_ | |
| 9 #define COMPONENTS_RAPPOR_RAPPOR_RECORDER_H_ | |
| 10 | |
| 11 #include <map> | |
| 12 #include <string> | |
| 13 #include <vector> | |
| 14 | |
| 15 #include "base/basictypes.h" | |
| 16 #include "base/gtest_prod_util.h" | |
| 17 #include "base/lazy_instance.h" | |
| 18 #include "base/synchronization/lock.h" | |
| 19 #include "components/rappor/rappor.h" | |
| 20 | |
| 21 #define RAPPOR_SAMPLES(parameters, samples) \ | |
| 22 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
| |
| 23 | |
| 24 namespace rappor { | |
| 25 | |
| 26 class RapporRecorder { | |
| 27 public: | |
| 28 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
| |
| 29 | |
| 30 // Removes all of the collected rappor metrics from the RapporRecorder, and | |
| 31 // stores them in the output list. The caller is responsible for deleting | |
| 32 // Rappor objects. | |
| 33 void CollectRappors(Rappors* output); | |
| 34 | |
| 35 // Deletes all of the rappors in a list. | |
| 36 static void DeleteRappors(Rappors* rappors); | |
| 37 | |
| 38 // Find a rappor by name, and create it if it doesn't already exist, and adds | |
| 39 // samples to it. This method is thread safe. | |
| 40 void RecordSamples(const RapporParameters* parameters, | |
| 41 const std::vector<std::string>& samples); | |
| 42 | |
| 43 // The constructor just initializes static members. Usually client code should | |
| 44 // use Initialize to do this. But in test code, you can friend this class and | |
| 45 // call destructor/constructor to get a clean RapporRecorder. | |
| 46 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
| |
| 47 ~RapporRecorder(); | |
| 48 | |
| 49 private: | |
| 50 // Find a rappor by name, and create it if it doesn't already exist. | |
| 51 Rappor* GetRappor(const RapporParameters* parameters); | |
| 52 | |
| 53 // We keep all registered histograms in a map, from name to histogram. | |
| 54 typedef std::map<std::string, Rappor*> RapporMap; | |
| 55 | |
| 56 RapporMap rappors_; | |
| 57 | |
| 58 // Lock protects access to above map. | |
| 59 base::Lock lock_; | |
| 60 }; | |
| 61 | |
| 62 extern base::LazyInstance<RapporRecorder>::Leaky g_rappor_recorder; | |
| 63 | |
| 64 } // namespace rappor | |
| 65 | |
| 66 #endif // COMPONENTS_RAPPOR_RAPPOR_RECORDER_H_ | |
| OLD | NEW |