1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_METRICS_SINGLE_SAMPLE_METRICS_H_
6 #define COMPONENTS_METRICS_SINGLE_SAMPLE_METRICS_H_
8 #include "base/functional/callback.h"
9 #include "components/metrics/public/mojom/single_sample_metrics.mojom.h"
10 #include "mojo/public/cpp/bindings/pending_receiver.h"
14 using CreateProviderCB = base::RepeatingCallback<void(
15 mojo::PendingReceiver<mojom::SingleSampleMetricsProvider>)>;
17 // Initializes and sets the base::SingleSampleMetricsFactory for the current
18 // process. |create_provider_cb| is used to create provider instances per each
19 // thread that the factory is used on; this is necessary since the underlying
20 // providers must only be used on the same thread as construction.
22 // We use a callback here to avoid taking additional DEPS on content and a
23 // service_manager::Connector() for simplicity and to avoid the need for
24 // using the service test harness in metrics unittests.
26 // Typically this is called in the process where termination may occur without
27 // warning; e.g. perhaps a renderer process.
28 extern void InitializeSingleSampleMetricsFactory(
29 CreateProviderCB create_provider_cb);
31 // Creates a mojom::SingleSampleMetricsProvider capable of vending single sample
32 // metrics attached to a mojo pipe.
34 // Typically this is given to a service_manager::BinderRegistry in the process
35 // that has a deterministic shutdown path and which serves as a stable endpoint
36 // for the factory created by the above initialize method in another process.
37 extern void CreateSingleSampleMetricsProvider(
38 mojo::PendingReceiver<mojom::SingleSampleMetricsProvider> receiver);
40 } // namespace metrics
42 #endif // COMPONENTS_METRICS_SINGLE_SAMPLE_METRICS_H_