Index: components/metrics/single_value_histograms_factory_impl.cc |
diff --git a/components/metrics/single_value_histograms_factory_impl.cc b/components/metrics/single_value_histograms_factory_impl.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c19b852787bfdeeadb94958c8bd9f4e5a07e7529 |
--- /dev/null |
+++ b/components/metrics/single_value_histograms_factory_impl.cc |
@@ -0,0 +1,61 @@ |
+// 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. |
+ |
+#include "components/metrics/single_value_histograms_factory_impl.h" |
+ |
+namespace metrics { |
+ |
+class SingleValueCountsHistogramImpl : public base::SingleValueCountsHistogram { |
+ public: |
+ SingleValueCountsHistogramImpl( |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
+ mojom::SingleValueCountsHistogramPtr metric) |
+ : metric_(std::move(metric)) { |
+ // TODO(dalecurtis): Do we need |task_runner| or can SetSample() be called |
+ // from any thread? |
+ } |
+ |
+ ~SingleValueCountsHistogramImpl() override { |
+ // TODO(dalecurtis): Do we need to release |metric_| on |task_runner_| ? |
+ } |
+ |
+ void SetSample(base::HistogramBase::Sample sample) override { |
+ metric_->SetSample(sample); |
+ } |
+ |
+ private: |
+ mojom::SingleValueCountsHistogramPtr metric_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SingleValueCountsHistogramImpl); |
+}; |
+ |
+SingleValueHistogramsFactoryImpl::SingleValueHistogramsFactoryImpl( |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
+ mojom::SingleValueHistogramsProviderPtr metric_provider) |
+ : provider_(std::move(metric_provider)) { |
+ // TODO(dalecurtis): Do we actually need |task_runner| here or is the provider |
+ // safe to access from any thread since it is created and persists for the |
Ken Rockot(use gerrit already)
2017/04/21 17:40:56
No, InterfacePtr is not thread-safe.
DaleCurtis
2017/04/21 17:44:33
Thanks, will redo this section to use task_runner,
Ken Rockot(use gerrit already)
2017/04/21 18:03:27
We'd like a proper thread-safe InterfacePtr, but s
DaleCurtis
2017/04/21 18:18:34
Can you elaborate on how a TL IP would work? I.e.
|
+ // lifetime of the process? |
+} |
+ |
+SingleValueHistogramsFactoryImpl::~SingleValueHistogramsFactoryImpl() { |
+ // This factory persists until process shutdown. |
+ NOTREACHED(); |
+} |
+ |
+std::unique_ptr<base::SingleValueCountsHistogram> |
+SingleValueHistogramsFactoryImpl::CreateSingleValueCountsHistogram( |
+ const std::string& name, |
+ base::HistogramBase::Sample min, |
+ base::HistogramBase::Sample max, |
+ uint32_t bucket_count) { |
+ mojom::SingleValueCountsHistogramPtr metric; |
+ provider_->AcquireSingleValueCountsHistogram( |
+ name, min, max, bucket_count, |
+ mojo::MakeRequest<mojom::SingleValueCountsHistogram>(&metric)); |
+ return base::MakeUnique<SingleValueCountsHistogramImpl>(nullptr, |
+ std::move(metric)); |
+} |
+ |
+} // namespace metrics |