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

Unified 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 side-by-side diff with in-line comments
Download patch
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..430978db2ce779811e181ba7fa5fccf2d80bd9c6
--- /dev/null
+++ b/components/rappor/rappor_recorder.h
@@ -0,0 +1,60 @@
+// 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(name, samples) \
+ rappor::g_rappor_recorder.Get().GetRappor(name)->AddSamples(samples);
+
+namespace rappor {
+
+class RapporRecorder {
+ public:
+ typedef std::vector<Rappor*> Rappors;
+
+ // Method for extracting rappors for use by UMA.
+ void GetRappors(Rappors* output);
+
+ // Clears all recorded rappors.
+ void ClearRappors();
+
+ // Find a rappor by name, and create it if it doesn't already exist. It
+ // matches the exact name. This method is thread safe.
+ 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.
+
+ // 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();
+ ~RapporRecorder();
+
+ private:
+ // 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_

Powered by Google App Engine
This is Rietveld 408576698