Index: components/metrics/single_value_histograms_factory_impl.h |
diff --git a/components/metrics/single_value_histograms_factory_impl.h b/components/metrics/single_value_histograms_factory_impl.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b10fe4c66079fb24c65dede33a1071dcd8a5fdb2 |
--- /dev/null |
+++ b/components/metrics/single_value_histograms_factory_impl.h |
@@ -0,0 +1,62 @@ |
+// 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_value_histograms.h" |
+#include "base/threading/thread_local.h" |
+#include "components/metrics/public/interfaces/single_value_histograms.mojom.h" |
+ |
+namespace base { |
+class SingleThreadTaskRunner; |
+} |
+ |
+namespace service_manager { |
+class Connector; |
+} |
+ |
+namespace metrics { |
+class SingleValueHistogramsProviderTrampoline; |
+ |
+class SingleValueHistogramsFactoryImpl |
+ : public base::SingleValueHistogramsFactory { |
+ public: |
+ // Constructs a factory capable of vending single value histograms from any |
+ // thread. Uses |connector| to create SingleValueHistogramsProvider instances |
+ // as necessary per thread. |task_runner| is the thread |connector| must be |
+ // used from. Provider instances are stored in thread local storage (TLS). |
+ SingleValueHistogramsFactoryImpl( |
+ service_manager::Connector* connector, |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
+ ~SingleValueHistogramsFactoryImpl() override; |
+ |
+ // base::SingleValueHistogramsFactory implementation. |
+ std::unique_ptr<base::SingleValueCountsHistogram> |
+ CreateSingleValueCountsHistogram(const std::string& name, |
+ base::HistogramBase::Sample min, |
+ base::HistogramBase::Sample max, |
+ uint32_t bucket_count) override; |
+ |
+ private: |
+ // Gets the SingleValueHistogramsProvider for the current thread. If none |
+ // exists, then a new instance is created and set in the TLS slot. |
+ mojom::SingleValueHistogramsProvider* GetProvider(); |
+ |
+ // Service manager connector and the task runner it must be used from. |
+ service_manager::Connector* const connector_; |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
+ |
+ // Per thread storage slot for internal trampoline. Necessary since we can't |
+ // store mojo-style "pointers" using the TLS helper classes. |
+ base::ThreadLocalPointer<SingleValueHistogramsProviderTrampoline> provider_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SingleValueHistogramsFactoryImpl); |
+}; |
+ |
+} // namespace metrics |
+ |
+#endif // COMPONENTS_METRICS_SINGLE_VALUE_HISTOGRAM_FACTORY_IMPL_H_ |