| 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..120d6f45a75343d391d0f0416579267345f0d838
|
| --- /dev/null
|
| +++ b/components/rappor/rappor_recorder.cc
|
| @@ -0,0 +1,55 @@
|
| +// 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;
|
| +
|
| +void RapporRecorder::ClearRappors() {
|
| + base::AutoLock auto_lock(lock_);
|
| +
|
| + for (RapporMap::iterator it = rappors_.begin(); rappors_.end() != it; ++it) {
|
| + delete it->second;
|
| + }
|
| + rappors_.clear();
|
| +}
|
| +
|
| +void RapporRecorder::GetRappors(Rappors* output) {
|
| + base::AutoLock auto_lock(lock_);
|
| +
|
| + for (RapporMap::iterator it = rappors_.begin(); rappors_.end() != it; ++it) {
|
| + DCHECK_EQ(it->first, it->second->rappor_name());
|
| + output->push_back(it->second);
|
| + }
|
| +}
|
| +
|
| +Rappor* RapporRecorder::GetRappor(const std::string& name) {
|
| + base::AutoLock auto_lock(lock_);
|
| +
|
| + RapporMap::iterator it = rappors_.find(name);
|
| + if (rappors_.end() != it)
|
| + return it->second;
|
| +
|
| + Rappor* new_rappor = new Rappor(name, 16, 4, 4, 2, 4, 2);
|
| +
|
| + rappors_[name] = new_rappor;
|
| + return new_rappor;
|
| +}
|
| +
|
| +RapporRecorder::RapporRecorder() {}
|
| +
|
| +RapporRecorder::~RapporRecorder() { ClearRappors(); }
|
| +
|
| +} // namespace rappor
|
|
|