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 #include "components/metrics/single_value_histograms_factory_impl.h" | |
6 | |
7 namespace metrics { | |
8 | |
9 class SingleValueCountsHistogramImpl : public base::SingleValueCountsHistogram { | |
10 public: | |
11 SingleValueCountsHistogramImpl( | |
12 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
13 mojom::SingleValueCountsHistogramPtr metric) | |
14 : metric_(std::move(metric)) { | |
15 // TODO(dalecurtis): Do we need |task_runner| or can SetSample() be called | |
16 // from any thread? | |
17 } | |
18 | |
19 ~SingleValueCountsHistogramImpl() override { | |
20 // TODO(dalecurtis): Do we need to release |metric_| on |task_runner_| ? | |
21 } | |
22 | |
23 void SetSample(base::HistogramBase::Sample sample) override { | |
24 metric_->SetSample(sample); | |
25 } | |
26 | |
27 private: | |
28 mojom::SingleValueCountsHistogramPtr metric_; | |
29 | |
30 DISALLOW_COPY_AND_ASSIGN(SingleValueCountsHistogramImpl); | |
31 }; | |
32 | |
33 SingleValueHistogramsFactoryImpl::SingleValueHistogramsFactoryImpl( | |
34 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
35 mojom::SingleValueHistogramsProviderPtr metric_provider) | |
36 : provider_(std::move(metric_provider)) { | |
37 // TODO(dalecurtis): Do we actually need |task_runner| here or is the provider | |
38 // 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.
| |
39 // lifetime of the process? | |
40 } | |
41 | |
42 SingleValueHistogramsFactoryImpl::~SingleValueHistogramsFactoryImpl() { | |
43 // This factory persists until process shutdown. | |
44 NOTREACHED(); | |
45 } | |
46 | |
47 std::unique_ptr<base::SingleValueCountsHistogram> | |
48 SingleValueHistogramsFactoryImpl::CreateSingleValueCountsHistogram( | |
49 const std::string& name, | |
50 base::HistogramBase::Sample min, | |
51 base::HistogramBase::Sample max, | |
52 uint32_t bucket_count) { | |
53 mojom::SingleValueCountsHistogramPtr metric; | |
54 provider_->AcquireSingleValueCountsHistogram( | |
55 name, min, max, bucket_count, | |
56 mojo::MakeRequest<mojom::SingleValueCountsHistogram>(&metric)); | |
57 return base::MakeUnique<SingleValueCountsHistogramImpl>(nullptr, | |
58 std::move(metric)); | |
59 } | |
60 | |
61 } // namespace metrics | |
OLD | NEW |