Chromium Code Reviews| Index: components/metrics/single_sample_metrics_factory_impl.h |
| diff --git a/components/metrics/single_sample_metrics_factory_impl.h b/components/metrics/single_sample_metrics_factory_impl.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ebee040d64df6b9f08ad044ff9ed8ee6fe455e0e |
| --- /dev/null |
| +++ b/components/metrics/single_sample_metrics_factory_impl.h |
| @@ -0,0 +1,61 @@ |
| +// Copyright 2017 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. |
| + |
| +#ifndef COMPONENTS_METRICS_SINGLE_VALUE_HISTOGRAM_FACTORY_IMPL_H_ |
| +#define COMPONENTS_METRICS_SINGLE_VALUE_HISTOGRAM_FACTORY_IMPL_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/metrics/single_sample_metrics.h" |
| +#include "base/threading/thread_local.h" |
| +#include "components/metrics/public/interfaces/single_sample_metrics.mojom.h" |
| + |
| +namespace metrics { |
| + |
| +class SingleSampleMetricsFactoryImpl : public base::SingleSampleMetricsFactory { |
|
Alexei Svitkine (slow)
2017/05/03 19:59:46
Add a comment explaining what this is for.
DaleCurtis
2017/05/03 20:54:48
Done.
|
| + public: |
| + // Constructs a factory capable of vending single sample metrics from any |
| + // thread. |create_provider_cb| will be called from arbitrary threads to |
| + // create providers as necessary; the callback must handle thread safety. |
| + using CreateProviderCB = |
| + base::RepeatingCallback<void(mojom::SingleSampleMetricsProviderRequest)>; |
|
Alexei Svitkine (slow)
2017/05/03 19:59:46
Nit: Add a new line after this.
DaleCurtis
2017/05/03 20:54:48
Rearranged.
|
| + explicit SingleSampleMetricsFactoryImpl(CreateProviderCB create_provider_cb); |
| + ~SingleSampleMetricsFactoryImpl() override; |
| + |
| + // base::SingleSampleMetricsFactory implementation. |
| + std::unique_ptr<base::SingleSampleMetric> CreateCustomCountsMetric( |
| + const std::string& name, |
|
Alexei Svitkine (slow)
2017/05/03 19:59:46
histogram_name
DaleCurtis
2017/05/03 20:54:48
Done.
|
| + base::HistogramBase::Sample min, |
| + base::HistogramBase::Sample max, |
| + uint32_t bucket_count) override; |
| + |
| + // Providers live forever in production, but tests should be kind and clean up |
| + // after themselves to avoid tests trampling on one another. Destroys the |
| + // provider in the TLS slot for the calling thread. |
| + void DestroyProviderForTesting(); |
| + |
| + private: |
| + // Creates a single sample metric. |
| + std::unique_ptr<base::SingleSampleMetric> CreateMetric( |
| + const std::string& name, |
| + base::HistogramBase::Sample min, |
| + base::HistogramBase::Sample max, |
| + uint32_t bucket_count, |
| + int32_t flags); |
| + |
| + // Gets the SingleSampleMetricsProvider for the current thread. If none |
| + // exists, then a new instance is created and set in the TLS slot. |
| + mojom::SingleSampleMetricsProvider* GetProvider(); |
| + |
| + CreateProviderCB create_provider_cb_; |
| + |
| + // Per thread storage slot for the mojo provider. |
| + base::ThreadLocalPointer<mojom::SingleSampleMetricsProviderPtr> provider_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SingleSampleMetricsFactoryImpl); |
| +}; |
| + |
| +} // namespace metrics |
| + |
| +#endif // COMPONENTS_METRICS_SINGLE_VALUE_HISTOGRAM_FACTORY_IMPL_H_ |