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"
14 #include "mozilla/java/RuntimeTelemetryNatives.h"
15 #include "mozilla/jni/Natives.h"
20 class GeckoTelemetryDelegate final
21 : public GeckoViewStreamingTelemetry::StreamingTelemetryDelegate
,
22 public mozilla::java::RuntimeTelemetry::Proxy::Natives
<
23 GeckoTelemetryDelegate
> {
25 // Implement Proxy native.
26 static void RegisterDelegateProxy(
27 mozilla::java::RuntimeTelemetry::Proxy::Param aProxy
) {
30 GeckoViewStreamingTelemetry::RegisterDelegate(
31 new GeckoTelemetryDelegate(aProxy
));
34 explicit GeckoTelemetryDelegate(
35 mozilla::java::RuntimeTelemetry::Proxy::Param aProxy
)
39 void DispatchHistogram(bool aIsCategorical
, const nsCString
& aName
,
40 const nsTArray
<uint32_t>& aSamples
) {
41 if (!mozilla::jni::IsAvailable() || !mProxy
|| aSamples
.Length() < 1) {
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
) {
73 mProxy
->DispatchBooleanScalar(aName
, aValue
);
76 void ReceiveStringScalarValue(const nsCString
& aName
,
77 const nsCString
& aValue
) override
{
78 if (!mozilla::jni::IsAvailable() || !mProxy
) {
82 mProxy
->DispatchStringScalar(aName
, aValue
);
85 void ReceiveUintScalarValue(const nsCString
& aName
,
86 uint32_t aValue
) override
{
87 if (!mozilla::jni::IsAvailable() || !mProxy
) {
91 mProxy
->DispatchLongScalar(aName
, static_cast<int64_t>(aValue
));
94 mozilla::java::RuntimeTelemetry::Proxy::GlobalRef mProxy
;
98 } // namespace mozilla
100 #endif // GeckoTelemetryDelegate_h__