Bug 1755316 - Add audio tests with simultaneous processes r=alwu
[gecko.git] / widget / android / GeckoTelemetryDelegate.h
blob43b20d4ad67e52a77f95aab2446548fd172b9ac1
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef GeckoTelemetryDelegate_h__
8 #define GeckoTelemetryDelegate_h__
10 #include "geckoview/streaming/GeckoViewStreamingTelemetry.h"
12 #include <jni.h>
14 #include "mozilla/java/RuntimeTelemetryNatives.h"
15 #include "mozilla/jni/Natives.h"
17 namespace mozilla {
18 namespace widget {
20 class GeckoTelemetryDelegate final
21 : public GeckoViewStreamingTelemetry::StreamingTelemetryDelegate,
22 public mozilla::java::RuntimeTelemetry::Proxy::Natives<
23 GeckoTelemetryDelegate> {
24 public:
25 // Implement Proxy native.
26 static void RegisterDelegateProxy(
27 mozilla::java::RuntimeTelemetry::Proxy::Param aProxy) {
28 MOZ_ASSERT(aProxy);
30 GeckoViewStreamingTelemetry::RegisterDelegate(
31 new GeckoTelemetryDelegate(aProxy));
34 explicit GeckoTelemetryDelegate(
35 mozilla::java::RuntimeTelemetry::Proxy::Param aProxy)
36 : mProxy(aProxy) {}
38 private:
39 void DispatchHistogram(bool aIsCategorical, const nsCString& aName,
40 const nsTArray<uint32_t>& aSamples) {
41 if (!mozilla::jni::IsAvailable() || !mProxy || aSamples.Length() < 1) {
42 return;
45 // Convert aSamples to an array of int64_t. We know |samples| required
46 // capacity needs to match |aSamples.Length()|.
47 nsTArray<int64_t> samples(aSamples.Length());
48 for (size_t i = 0, l = aSamples.Length(); i < l; ++i) {
49 samples.AppendElement(static_cast<int64_t>(aSamples[i]));
52 // LongArray::From *copies* the elements
53 mProxy->DispatchHistogram(aIsCategorical, aName,
54 mozilla::jni::LongArray::From(samples));
57 // Implement StreamingTelemetryDelegate.
58 void ReceiveHistogramSamples(const nsCString& aName,
59 const nsTArray<uint32_t>& aSamples) override {
60 DispatchHistogram(/* isCategorical */ false, aName, aSamples);
63 void ReceiveCategoricalHistogramSamples(
64 const nsCString& aName, const nsTArray<uint32_t>& aSamples) override {
65 DispatchHistogram(/* isCategorical */ true, aName, aSamples);
68 void ReceiveBoolScalarValue(const nsCString& aName, bool aValue) override {
69 if (!mozilla::jni::IsAvailable() || !mProxy) {
70 return;
73 mProxy->DispatchBooleanScalar(aName, aValue);
76 void ReceiveStringScalarValue(const nsCString& aName,
77 const nsCString& aValue) override {
78 if (!mozilla::jni::IsAvailable() || !mProxy) {
79 return;
82 mProxy->DispatchStringScalar(aName, aValue);
85 void ReceiveUintScalarValue(const nsCString& aName,
86 uint32_t aValue) override {
87 if (!mozilla::jni::IsAvailable() || !mProxy) {
88 return;
91 mProxy->DispatchLongScalar(aName, static_cast<int64_t>(aValue));
94 mozilla::java::RuntimeTelemetry::Proxy::GlobalRef mProxy;
97 } // namespace widget
98 } // namespace mozilla
100 #endif // GeckoTelemetryDelegate_h__