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

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: BrowserProcess member 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) 2012 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 Histograms and BucketRanges that are used by
6 // Histograms in the system. It provides a general place for
7 // Histograms/BucketRanges to register, and supports a global API for accessing
8 // (i.e., dumping, or graphing) the data.
9
10 #ifndef CHROME_BROWSER_RAPPOR_RAPPOR_RECORDER_H_
11 #define CHROME_BROWSER_RAPPOR_RAPPOR_RECORDER_H_
12
13 #include <map>
14 #include <string>
15 #include <vector>
16
17 #include "base/basictypes.h"
18 #include "base/gtest_prod_util.h"
19 #include "base/lazy_instance.h"
20 #include "base/synchronization/lock.h"
21 #include "components/rappor/rappor.h"
22
23 #define RAPPOR_SAMPLE(name, sample) \
24 rappor::g_rappor_recorder.Get().GetRappor(name)->Add(sample);
25
26 namespace rappor {
27
28 class RapporRecorder {
29 public:
30 typedef std::vector<Rappor*> Rappors;
31
32 // Method for extracting rappors for use by UMA.
33 void GetRappors(Rappors* output);
34
35 // Clears all recorded rappors.
36 void ClearRappors();
37
38 // Find a rappor by name, and create it if it doesn't already exist. It
39 // matches the exact name. This method is thread safe.
40 Rappor* GetRappor(const std::string& name);
41
42 // The constructor just initializes static members. Usually client code should
43 // use Initialize to do this. But in test code, you can friend this class and
44 // call destructor/constructor to get a clean RapporRecorder.
45 RapporRecorder();
46 ~RapporRecorder();
47
48 private:
49 // We keep all registered histograms in a map, from name to histogram.
50 typedef std::map<std::string, Rappor*> RapporMap;
51
52 RapporMap rappors_;
53
54 // Lock protects access to above map.
55 base::Lock lock_;
56 };
57
58 extern base::LazyInstance<RapporRecorder>::Leaky g_rappor_recorder;
59
60 } // namespace rappor
61
62 #endif // CHROME_BROWSER_RAPPOR_RAPPOR_RECORDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698