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

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

Issue 2687583002: Add support for single sample metrics. (Closed)
Patch Set: Use thread local storage. Created 3 years, 8 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_value_histograms.h"
11 #include "base/threading/thread_local.h"
12 #include "components/metrics/public/interfaces/single_value_histograms.mojom.h"
13
14 namespace base {
15 class SingleThreadTaskRunner;
16 }
17
18 namespace service_manager {
19 class Connector;
20 }
21
22 namespace metrics {
23 class SingleValueHistogramsProviderTrampoline;
24
25 class SingleValueHistogramsFactoryImpl
26 : public base::SingleValueHistogramsFactory {
27 public:
28 // Constructs a factory capable of vending single value histograms from any
29 // thread. Uses |connector| to create SingleValueHistogramsProvider instances
30 // as necessary per thread. |task_runner| is the thread |connector| must be
31 // used from. Provider instances are stored in thread local storage (TLS).
32 SingleValueHistogramsFactoryImpl(
33 service_manager::Connector* connector,
34 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
35 ~SingleValueHistogramsFactoryImpl() override;
36
37 // base::SingleValueHistogramsFactory implementation.
38 std::unique_ptr<base::SingleValueCountsHistogram>
39 CreateSingleValueCountsHistogram(const std::string& name,
40 base::HistogramBase::Sample min,
41 base::HistogramBase::Sample max,
42 uint32_t bucket_count) override;
43
44 private:
45 // Gets the SingleValueHistogramsProvider for the current thread. If none
46 // exists, then a new instance is created and set in the TLS slot.
47 mojom::SingleValueHistogramsProvider* GetProvider();
48
49 // Service manager connector and the task runner it must be used from.
50 service_manager::Connector* const connector_;
51 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
52
53 // Per thread storage slot for internal trampoline. Necessary since we can't
54 // store mojo-style "pointers" using the TLS helper classes.
55 base::ThreadLocalPointer<SingleValueHistogramsProviderTrampoline> provider_;
56
57 DISALLOW_COPY_AND_ASSIGN(SingleValueHistogramsFactoryImpl);
58 };
59
60 } // namespace metrics
61
62 #endif // COMPONENTS_METRICS_SINGLE_VALUE_HISTOGRAM_FACTORY_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698