OLD | NEW |
(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 #include "components/rappor/rappor_recorder.h" |
| 6 |
| 7 #include "base/at_exit.h" |
| 8 #include "base/debug/leak_annotations.h" |
| 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/synchronization/lock.h" |
| 12 #include "components/rappor/rappor.h" |
| 13 |
| 14 namespace rappor { |
| 15 |
| 16 // Initialize rappor gathering system. |
| 17 base::LazyInstance<RapporRecorder>::Leaky g_rappor_recorder = |
| 18 LAZY_INSTANCE_INITIALIZER; |
| 19 |
| 20 void RapporRecorder::ClearRappors() { |
| 21 base::AutoLock auto_lock(lock_); |
| 22 |
| 23 for (RapporMap::iterator it = rappors_.begin(); rappors_.end() != it; ++it) { |
| 24 delete it->second; |
| 25 } |
| 26 rappors_.clear(); |
| 27 } |
| 28 |
| 29 void RapporRecorder::GetRappors(Rappors* output) { |
| 30 base::AutoLock auto_lock(lock_); |
| 31 |
| 32 for (RapporMap::iterator it = rappors_.begin(); rappors_.end() != it; ++it) { |
| 33 DCHECK_EQ(it->first, it->second->rappor_name()); |
| 34 output->push_back(it->second); |
| 35 } |
| 36 } |
| 37 |
| 38 Rappor* RapporRecorder::GetRappor(const std::string& name) { |
| 39 base::AutoLock auto_lock(lock_); |
| 40 |
| 41 RapporMap::iterator it = rappors_.find(name); |
| 42 if (rappors_.end() != it) |
| 43 return it->second; |
| 44 |
| 45 Rappor* new_rappor = new Rappor(name, 16, 4, 4, 2, 4, 2); |
| 46 |
| 47 rappors_[name] = new_rappor; |
| 48 return new_rappor; |
| 49 } |
| 50 |
| 51 RapporRecorder::RapporRecorder() {} |
| 52 |
| 53 RapporRecorder::~RapporRecorder() { ClearRappors(); } |
| 54 |
| 55 } // namespace rappor |
OLD | NEW |