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

Side by Side Diff: components/metrics/single_sample_metrics_factory_impl.h

Issue 2687583002: Add support for single sample metrics. (Closed)
Patch Set: Add tests. Created 3 years, 7 months 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 #ifndef COMPONENTS_METRICS_SINGLE_VALUE_HISTOGRAM_FACTORY_IMPL_H_
6 #define COMPONENTS_METRICS_SINGLE_VALUE_HISTOGRAM_FACTORY_IMPL_H_
7
8 #include <string>
9
10 #include "base/metrics/single_sample_metrics.h"
11 #include "base/threading/thread_local.h"
12 #include "components/metrics/public/interfaces/single_sample_metrics.mojom.h"
13
14 namespace metrics {
15
16 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.
17 public:
18 // Constructs a factory capable of vending single sample metrics from any
19 // thread. |create_provider_cb| will be called from arbitrary threads to
20 // create providers as necessary; the callback must handle thread safety.
21 using CreateProviderCB =
22 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.
23 explicit SingleSampleMetricsFactoryImpl(CreateProviderCB create_provider_cb);
24 ~SingleSampleMetricsFactoryImpl() override;
25
26 // base::SingleSampleMetricsFactory implementation.
27 std::unique_ptr<base::SingleSampleMetric> CreateCustomCountsMetric(
28 const std::string& name,
Alexei Svitkine (slow) 2017/05/03 19:59:46 histogram_name
DaleCurtis 2017/05/03 20:54:48 Done.
29 base::HistogramBase::Sample min,
30 base::HistogramBase::Sample max,
31 uint32_t bucket_count) override;
32
33 // Providers live forever in production, but tests should be kind and clean up
34 // after themselves to avoid tests trampling on one another. Destroys the
35 // provider in the TLS slot for the calling thread.
36 void DestroyProviderForTesting();
37
38 private:
39 // Creates a single sample metric.
40 std::unique_ptr<base::SingleSampleMetric> CreateMetric(
41 const std::string& name,
42 base::HistogramBase::Sample min,
43 base::HistogramBase::Sample max,
44 uint32_t bucket_count,
45 int32_t flags);
46
47 // Gets the SingleSampleMetricsProvider for the current thread. If none
48 // exists, then a new instance is created and set in the TLS slot.
49 mojom::SingleSampleMetricsProvider* GetProvider();
50
51 CreateProviderCB create_provider_cb_;
52
53 // Per thread storage slot for the mojo provider.
54 base::ThreadLocalPointer<mojom::SingleSampleMetricsProviderPtr> provider_;
55
56 DISALLOW_COPY_AND_ASSIGN(SingleSampleMetricsFactoryImpl);
57 };
58
59 } // namespace metrics
60
61 #endif // COMPONENTS_METRICS_SINGLE_VALUE_HISTOGRAM_FACTORY_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698