| 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..3a7a7d5d579d9efe019ebfb648bb4d787df89eea
|
| --- /dev/null
|
| +++ b/components/rappor/rappor_recorder.h
|
| @@ -0,0 +1,63 @@
|
| +// 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.
|
| +
|
| +// RapporRecorder holds all Histograms and BucketRanges that are used by
|
| +// Histograms in the system. It provides a general place for
|
| +// Histograms/BucketRanges to register, and supports a global API for accessing
|
| +// (i.e., dumping, or graphing) the data.
|
| +
|
| +#ifndef CHROME_BROWSER_RAPPOR_RAPPOR_RECORDER_H_
|
| +#define CHROME_BROWSER_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_SAMPLE(name, sample) \
|
| + rappor::g_rappor_recorder.Get().GetRappor(name)->Add(sample);
|
| +
|
| +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);
|
| +
|
| + // 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 // CHROME_BROWSER_RAPPOR_RAPPOR_RECORDER_H_
|
|
|