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

Unified Diff: components/rappor/rappor_recorder.cc

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.cc
diff --git a/components/rappor/rappor_recorder.cc b/components/rappor/rappor_recorder.cc
new file mode 100644
index 0000000000000000000000000000000000000000..13a5e68fe26f8e1ce6978109cf8522c43f56e9e4
--- /dev/null
+++ b/components/rappor/rappor_recorder.cc
@@ -0,0 +1,67 @@
+// Copyright (c) 2012 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.
+
+#include "components/rappor/rappor_recorder.h"
+
+#include "base/at_exit.h"
+#include "base/debug/leak_annotations.h"
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/synchronization/lock.h"
+#include "components/rappor/rappor.h"
+
+namespace rappor {
+
+// Initialize rappor gathering system.
+base::LazyInstance<RapporRecorder>::Leaky g_rappor_recorder =
+ LAZY_INSTANCE_INITIALIZER;
+
+// static
+void RapporRecorder::DeleteRappors(Rappors* rappors) {
+ for (Rappors::iterator it = rappors->begin(); rappors->end() != it; ++it) {
+ delete *it;
+ }
+ rappors->clear();
+}
+
+void RapporRecorder::CollectRappors(Rappors* output) {
+ base::AutoLock auto_lock(lock_);
+
+ for (RapporMap::iterator it = rappors_.begin(); rappors_.end() != it; ++it) {
+ DCHECK_EQ(it->first, it->second->parameters()->rappor_name);
+ output->push_back(it->second);
+ }
+ rappors_.clear();
+}
+
+void RapporRecorder::RecordSamples(const RapporParameters* parameters,
+ const std::vector<std::string>& samples) {
+ base::AutoLock auto_lock(lock_);
+
+ Rappor* rappor = GetRappor(parameters);
+ rappor->AddSamples(samples);
+}
+
+Rappor* RapporRecorder::GetRappor(const RapporParameters* parameters) {
+ RapporMap::iterator it = rappors_.find(parameters->rappor_name);
+ if (rappors_.end() != it) {
+ Rappor* rappor = it->second;
+ DCHECK_EQ(parameters, rappor->parameters());
+ return rappor;
+ }
+
+ Rappor* new_rappor = new Rappor(parameters);
+ rappors_[parameters->rappor_name] = new_rappor;
+ return new_rappor;
+}
+
+RapporRecorder::RapporRecorder() {}
+
+RapporRecorder::~RapporRecorder() {
+ Rappors rappors;
+ CollectRappors(&rappors);
+ DeleteRappors(&rappors);
+}
+
+} // namespace rappor

Powered by Google App Engine
This is Rietveld 408576698