Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: components/rappor/rappor_recorder.h

Issue 49753002: RAPPOR implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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(name, samples) \
22 rappor::g_rappor_recorder.Get().GetRappor(name)->AddSamples(samples);
23
24 namespace rappor {
25
26 class RapporRecorder {
27 public:
28 typedef std::vector<Rappor*> Rappors;
29
30 // Method for extracting rappors for use by UMA.
31 void GetRappors(Rappors* output);
32
33 // Clears all recorded rappors.
34 void ClearRappors();
35
36 // Find a rappor by name, and create it if it doesn't already exist. It
37 // matches the exact name. This method is thread safe.
38 Rappor* GetRappor(const std::string& name);
jwd 2013/12/17 23:00:25 Can this return a weak_ptr? Similarly, can |Rappor
Steven Holte 2013/12/18 23:38:49 Hid this pointer inside a RecordSamples() method.
39
40 // The constructor just initializes static members. Usually client code should
41 // use Initialize to do this. But in test code, you can friend this class and
42 // call destructor/constructor to get a clean RapporRecorder.
43 RapporRecorder();
44 ~RapporRecorder();
45
46 private:
47 // We keep all registered histograms in a map, from name to histogram.
48 typedef std::map<std::string, Rappor*> RapporMap;
49
50 RapporMap rappors_;
51
52 // Lock protects access to above map.
53 base::Lock lock_;
54 };
55
56 extern base::LazyInstance<RapporRecorder>::Leaky g_rappor_recorder;
57
58 } // namespace rappor
59
60 #endif // COMPONENTS_RAPPOR_RAPPOR_RECORDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698