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_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_ |
OLD | NEW |