OLD | NEW |
---|---|
(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 // SingleSampleMetricsFactory implementation for creating SingleSampleMetric | |
17 // instances that communicate over mojo to instances in another process. | |
18 // | |
19 // Persistance outside of the current process allows these metrics to record a | |
20 // sample even in the event of sudden process termination. As an example, this | |
21 // is useful for garbage collected objects which may never get a chance to run | |
22 // their destructors in the event of a fast shutdown event (process kill). | |
23 class SingleSampleMetricsFactoryImpl : public base::SingleSampleMetricsFactory { | |
24 public: | |
25 using CreateProviderCB = | |
26 base::RepeatingCallback<void(mojom::SingleSampleMetricsProviderRequest)>; | |
27 | |
28 // Constructs a factory capable of vending single sample metrics from any | |
29 // thread. |create_provider_cb| will be called from arbitrary threads to | |
30 // create providers as necessary; the callback must handle thread safety. | |
31 explicit SingleSampleMetricsFactoryImpl(CreateProviderCB create_provider_cb); | |
Alexei Svitkine (slow)
2017/05/03 21:18:48
Can you mention somewhere in the comments the purp
DaleCurtis
2017/05/03 21:37:52
What's do you think is missing from the current "|
Alexei Svitkine (slow)
2017/05/03 21:45:08
I meant to explain why it's necessary for it be pr
DaleCurtis
2017/05/04 02:28:59
I'm not sure what you mean? Probably clients will
Alexei Svitkine (slow)
2017/05/04 14:15:08
Sorry for the confusion - I meant that your explan
DaleCurtis
2017/05/04 18:55:27
Ah I see, done.
| |
32 ~SingleSampleMetricsFactoryImpl() override; | |
33 | |
34 // base::SingleSampleMetricsFactory: | |
35 std::unique_ptr<base::SingleSampleMetric> CreateCustomCountsMetric( | |
36 const std::string& histogram_name, | |
37 base::HistogramBase::Sample min, | |
38 base::HistogramBase::Sample max, | |
39 uint32_t bucket_count) override; | |
40 | |
41 // Providers live forever in production, but tests should be kind and clean up | |
42 // after themselves to avoid tests trampling on one another. Destroys the | |
43 // provider in the TLS slot for the calling thread. | |
44 void DestroyProviderForTesting(); | |
45 | |
46 private: | |
47 // Creates a single sample metric. | |
48 std::unique_ptr<base::SingleSampleMetric> CreateMetric( | |
49 const std::string& histogram_name, | |
50 base::HistogramBase::Sample min, | |
51 base::HistogramBase::Sample max, | |
52 uint32_t bucket_count, | |
53 int32_t flags); | |
54 | |
55 // Gets the SingleSampleMetricsProvider for the current thread. If none | |
56 // exists, then a new instance is created and set in the TLS slot. | |
57 mojom::SingleSampleMetricsProvider* GetProvider(); | |
58 | |
59 CreateProviderCB create_provider_cb_; | |
60 | |
61 // Per thread storage slot for the mojo provider. | |
62 base::ThreadLocalPointer<mojom::SingleSampleMetricsProviderPtr> provider_; | |
63 | |
64 DISALLOW_COPY_AND_ASSIGN(SingleSampleMetricsFactoryImpl); | |
65 }; | |
66 | |
67 } // namespace metrics | |
68 | |
69 #endif // COMPONENTS_METRICS_SINGLE_VALUE_HISTOGRAM_FACTORY_IMPL_H_ | |
OLD | NEW |