summaryrefslogtreecommitdiffstats
path: root/widget/android/GeckoTelemetryDelegate.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /widget/android/GeckoTelemetryDelegate.h
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'widget/android/GeckoTelemetryDelegate.h')
-rw-r--r--widget/android/GeckoTelemetryDelegate.h100
1 files changed, 100 insertions, 0 deletions
diff --git a/widget/android/GeckoTelemetryDelegate.h b/widget/android/GeckoTelemetryDelegate.h
new file mode 100644
index 0000000000..43b20d4ad6
--- /dev/null
+++ b/widget/android/GeckoTelemetryDelegate.h
@@ -0,0 +1,100 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef GeckoTelemetryDelegate_h__
+#define GeckoTelemetryDelegate_h__
+
+#include "geckoview/streaming/GeckoViewStreamingTelemetry.h"
+
+#include <jni.h>
+
+#include "mozilla/java/RuntimeTelemetryNatives.h"
+#include "mozilla/jni/Natives.h"
+
+namespace mozilla {
+namespace widget {
+
+class GeckoTelemetryDelegate final
+ : public GeckoViewStreamingTelemetry::StreamingTelemetryDelegate,
+ public mozilla::java::RuntimeTelemetry::Proxy::Natives<
+ GeckoTelemetryDelegate> {
+ public:
+ // Implement Proxy native.
+ static void RegisterDelegateProxy(
+ mozilla::java::RuntimeTelemetry::Proxy::Param aProxy) {
+ MOZ_ASSERT(aProxy);
+
+ GeckoViewStreamingTelemetry::RegisterDelegate(
+ new GeckoTelemetryDelegate(aProxy));
+ }
+
+ explicit GeckoTelemetryDelegate(
+ mozilla::java::RuntimeTelemetry::Proxy::Param aProxy)
+ : mProxy(aProxy) {}
+
+ private:
+ void DispatchHistogram(bool aIsCategorical, const nsCString& aName,
+ const nsTArray<uint32_t>& aSamples) {
+ if (!mozilla::jni::IsAvailable() || !mProxy || aSamples.Length() < 1) {
+ return;
+ }
+
+ // Convert aSamples to an array of int64_t. We know |samples| required
+ // capacity needs to match |aSamples.Length()|.
+ nsTArray<int64_t> samples(aSamples.Length());
+ for (size_t i = 0, l = aSamples.Length(); i < l; ++i) {
+ samples.AppendElement(static_cast<int64_t>(aSamples[i]));
+ }
+
+ // LongArray::From *copies* the elements
+ mProxy->DispatchHistogram(aIsCategorical, aName,
+ mozilla::jni::LongArray::From(samples));
+ }
+
+ // Implement StreamingTelemetryDelegate.
+ void ReceiveHistogramSamples(const nsCString& aName,
+ const nsTArray<uint32_t>& aSamples) override {
+ DispatchHistogram(/* isCategorical */ false, aName, aSamples);
+ }
+
+ void ReceiveCategoricalHistogramSamples(
+ const nsCString& aName, const nsTArray<uint32_t>& aSamples) override {
+ DispatchHistogram(/* isCategorical */ true, aName, aSamples);
+ }
+
+ void ReceiveBoolScalarValue(const nsCString& aName, bool aValue) override {
+ if (!mozilla::jni::IsAvailable() || !mProxy) {
+ return;
+ }
+
+ mProxy->DispatchBooleanScalar(aName, aValue);
+ }
+
+ void ReceiveStringScalarValue(const nsCString& aName,
+ const nsCString& aValue) override {
+ if (!mozilla::jni::IsAvailable() || !mProxy) {
+ return;
+ }
+
+ mProxy->DispatchStringScalar(aName, aValue);
+ }
+
+ void ReceiveUintScalarValue(const nsCString& aName,
+ uint32_t aValue) override {
+ if (!mozilla::jni::IsAvailable() || !mProxy) {
+ return;
+ }
+
+ mProxy->DispatchLongScalar(aName, static_cast<int64_t>(aValue));
+ }
+
+ mozilla::java::RuntimeTelemetry::Proxy::GlobalRef mProxy;
+};
+
+} // namespace widget
+} // namespace mozilla
+
+#endif // GeckoTelemetryDelegate_h__