single_sample_metrics.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #ifndef COMPONENTS_METRICS_SINGLE_SAMPLE_METRICS_H_
  5. #define COMPONENTS_METRICS_SINGLE_SAMPLE_METRICS_H_
  6. #include "base/callback.h"
  7. #include "components/metrics/public/mojom/single_sample_metrics.mojom.h"
  8. #include "mojo/public/cpp/bindings/pending_receiver.h"
  9. namespace metrics {
  10. using CreateProviderCB = base::RepeatingCallback<void(
  11. mojo::PendingReceiver<mojom::SingleSampleMetricsProvider>)>;
  12. // Initializes and sets the base::SingleSampleMetricsFactory for the current
  13. // process. |create_provider_cb| is used to create provider instances per each
  14. // thread that the factory is used on; this is necessary since the underlying
  15. // providers must only be used on the same thread as construction.
  16. //
  17. // We use a callback here to avoid taking additional DEPS on content and a
  18. // service_manager::Connector() for simplicity and to avoid the need for
  19. // using the service test harness in metrics unittests.
  20. //
  21. // Typically this is called in the process where termination may occur without
  22. // warning; e.g. perhaps a renderer process.
  23. extern void InitializeSingleSampleMetricsFactory(
  24. CreateProviderCB create_provider_cb);
  25. // Creates a mojom::SingleSampleMetricsProvider capable of vending single sample
  26. // metrics attached to a mojo pipe.
  27. //
  28. // Typically this is given to a service_manager::BinderRegistry in the process
  29. // that has a deterministic shutdown path and which serves as a stable endpoint
  30. // for the factory created by the above initialize method in another process.
  31. extern void CreateSingleSampleMetricsProvider(
  32. mojo::PendingReceiver<mojom::SingleSampleMetricsProvider> receiver);
  33. } // namespace metrics
  34. #endif // COMPONENTS_METRICS_SINGLE_SAMPLE_METRICS_H_