mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Backed out 7 changesets (bug 1848708) for bustages on TimingDistribution.cpp
Backed out changeset e63a855c0acf (bug 1848708) Backed out changeset 242478709593 (bug 1848708) Backed out changeset f1a77753fa0c (bug 1848708) Backed out changeset d230a932c850 (bug 1848708) Backed out changeset 1261ba650483 (bug 1848708) Backed out changeset 06061d509ab5 (bug 1848708) Backed out changeset 726d5138b1d2 (bug 1848708)
This commit is contained in:
parent
57fb0f7572
commit
5e99494bdd
@ -628,6 +628,6 @@ function _assertGleanPing(ping) {
|
||||
};
|
||||
for (const [key, value] of Object.entries(ping.payload)) {
|
||||
Assert.ok(key in keymap, `A Glean metric exists for field ${key}`);
|
||||
Assert.equal(value ?? null, keymap[key].testGetValue());
|
||||
Assert.equal(value ?? "", keymap[key].testGetValue());
|
||||
}
|
||||
}
|
||||
|
@ -2934,7 +2934,7 @@ bool nsGlobalWindowInner::HasActiveSpeechSynthesis() {
|
||||
|
||||
mozilla::glean::Glean* nsGlobalWindowInner::Glean() {
|
||||
if (!mGlean) {
|
||||
mGlean = new mozilla::glean::Glean(this);
|
||||
mGlean = new mozilla::glean::Glean();
|
||||
}
|
||||
|
||||
return mGlean;
|
||||
|
@ -1568,78 +1568,6 @@ DOMInterfaces = {
|
||||
'nativeType': 'mozilla::glean::GleanLabeled',
|
||||
'headerFile': 'mozilla/glean/bindings/Labeled.h',
|
||||
},
|
||||
'GleanMetric': {
|
||||
'nativeType': 'mozilla::glean::GleanMetric',
|
||||
'headerFile': 'mozilla/glean/bindings/GleanMetric.h',
|
||||
},
|
||||
'GleanBoolean': {
|
||||
'nativeType': 'mozilla::glean::GleanBoolean',
|
||||
'headerFile': 'mozilla/glean/bindings/Boolean.h',
|
||||
},
|
||||
'GleanCounter': {
|
||||
'nativeType': 'mozilla::glean::GleanCounter',
|
||||
'headerFile': 'mozilla/glean/bindings/Counter.h',
|
||||
},
|
||||
'GleanCustomDistribution': {
|
||||
'nativeType': 'mozilla::glean::GleanCustomDistribution',
|
||||
'headerFile': 'mozilla/glean/bindings/CustomDistribution.h',
|
||||
},
|
||||
'GleanDatetime': {
|
||||
'nativeType': 'mozilla::glean::GleanDatetime',
|
||||
'headerFile': 'mozilla/glean/bindings/Datetime.h',
|
||||
},
|
||||
'GleanString': {
|
||||
'nativeType': 'mozilla::glean::GleanString',
|
||||
'headerFile': 'mozilla/glean/bindings/String.h',
|
||||
},
|
||||
'GleanStringList': {
|
||||
'nativeType': 'mozilla::glean::GleanStringList',
|
||||
'headerFile': 'mozilla/glean/bindings/StringList.h',
|
||||
},
|
||||
'GleanTimespan': {
|
||||
'nativeType': 'mozilla::glean::GleanTimespan',
|
||||
'headerFile': 'mozilla/glean/bindings/Timespan.h',
|
||||
},
|
||||
'GleanUuid': {
|
||||
'nativeType': 'mozilla::glean::GleanUuid',
|
||||
'headerFile': 'mozilla/glean/bindings/Uuid.h',
|
||||
},
|
||||
'GleanEvent': {
|
||||
'nativeType': 'mozilla::glean::GleanEvent',
|
||||
'headerFile': 'mozilla/glean/bindings/Event.h',
|
||||
},
|
||||
'GleanQuantity': {
|
||||
'nativeType': 'mozilla::glean::GleanQuantity',
|
||||
'headerFile': 'mozilla/glean/bindings/Quantity.h',
|
||||
},
|
||||
'GleanUrl': {
|
||||
'nativeType': 'mozilla::glean::GleanUrl',
|
||||
'headerFile': 'mozilla/glean/bindings/Url.h',
|
||||
},
|
||||
'GleanTimingDistribution': {
|
||||
'nativeType': 'mozilla::glean::GleanTimingDistribution',
|
||||
'headerFile': 'mozilla/glean/bindings/TimingDistribution.h',
|
||||
},
|
||||
'GleanMemoryDistribution': {
|
||||
'nativeType': 'mozilla::glean::GleanMemoryDistribution',
|
||||
'headerFile': 'mozilla/glean/bindings/MemoryDistribution.h',
|
||||
},
|
||||
'GleanNumerator': {
|
||||
'nativeType': 'mozilla::glean::GleanNumerator',
|
||||
'headerFile': 'mozilla/glean/bindings/Numerator.h',
|
||||
},
|
||||
'GleanDenominator': {
|
||||
'nativeType': 'mozilla::glean::GleanDenominator',
|
||||
'headerFile': 'mozilla/glean/bindings/Denominator.h',
|
||||
},
|
||||
'GleanRate': {
|
||||
'nativeType': 'mozilla::glean::GleanRate',
|
||||
'headerFile': 'mozilla/glean/bindings/Rate.h',
|
||||
},
|
||||
'GleanText': {
|
||||
'nativeType': 'mozilla::glean::GleanText',
|
||||
'headerFile': 'mozilla/glean/bindings/Text.h',
|
||||
},
|
||||
|
||||
# WebRTC
|
||||
|
||||
|
@ -4,7 +4,9 @@
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
interface nsISupports;
|
||||
|
||||
[ChromeOnly, Exposed=Window]
|
||||
interface GleanCategory {
|
||||
/**
|
||||
* Get a metric by name.
|
||||
@ -12,10 +14,10 @@ interface GleanCategory {
|
||||
* Returns an object of the corresponding metric type,
|
||||
* with only the allowed functions available.
|
||||
*/
|
||||
getter GleanMetric (DOMString identifier);
|
||||
getter nsISupports (DOMString identifier);
|
||||
};
|
||||
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
[ChromeOnly, Exposed=Window]
|
||||
interface GleanImpl {
|
||||
/**
|
||||
* Get a metric category by name.
|
||||
@ -25,7 +27,7 @@ interface GleanImpl {
|
||||
getter GleanCategory (DOMString identifier);
|
||||
};
|
||||
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
[ChromeOnly, Exposed=Window]
|
||||
interface GleanLabeled {
|
||||
/**
|
||||
* Get a specific metric for a given label.
|
||||
@ -39,5 +41,5 @@ interface GleanLabeled {
|
||||
* After that, any additional labels will be recorded under the special
|
||||
* `OTHER_LABEL` label.
|
||||
*/
|
||||
getter GleanMetric (DOMString identifier);
|
||||
getter nsISupports (DOMString identifier);
|
||||
};
|
@ -6,7 +6,7 @@
|
||||
|
||||
interface nsIGleanPing;
|
||||
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
[ChromeOnly, Exposed=Window]
|
||||
interface GleanPingsImpl {
|
||||
/**
|
||||
* Get a ping by name.
|
@ -28,6 +28,9 @@ with Files("MatchPattern.webidl"):
|
||||
with Files("WebExtension*.webidl"):
|
||||
BUG_COMPONENT = ("WebExtensions", "General")
|
||||
|
||||
with Files("Glean*.webidl"):
|
||||
BUG_COMPONENT = ("Toolkit", "Telemetry")
|
||||
|
||||
with Files("IOUtils.webidl"):
|
||||
BUG_COMPONENT = ("Toolkit", "IOUtils and PathUtils")
|
||||
|
||||
@ -106,3 +109,8 @@ if CONFIG["MOZ_PLACES"]:
|
||||
"PlacesEvent.webidl",
|
||||
"PlacesObservers.webidl",
|
||||
]
|
||||
|
||||
WEBIDL_FILES += [
|
||||
"Glean.webidl",
|
||||
"GleanPings.webidl",
|
||||
]
|
||||
|
@ -139,9 +139,6 @@ with Files("GeometryUtils.webidl"):
|
||||
with Files("GetUserMediaRequest.webidl"):
|
||||
BUG_COMPONENT = ("Core", "WebRTC")
|
||||
|
||||
with Files("Glean*.webidl"):
|
||||
BUG_COMPONENT = ("Toolkit", "Telemetry")
|
||||
|
||||
with Files("Grid.webidl"):
|
||||
BUG_COMPONENT = ("Core", "CSS Parsing and Computation")
|
||||
|
||||
@ -586,9 +583,6 @@ WEBIDL_FILES = [
|
||||
"GeolocationPositionError.webidl",
|
||||
"GeometryUtils.webidl",
|
||||
"GetUserMediaRequest.webidl",
|
||||
"Glean.webidl",
|
||||
"GleanMetrics.webidl",
|
||||
"GleanPings.webidl",
|
||||
"Grid.webidl",
|
||||
"Headers.webidl",
|
||||
"Highlight.webidl",
|
||||
|
@ -60,7 +60,7 @@ add_task(async function test_no_rules() {
|
||||
});
|
||||
|
||||
// No click telemetry reported.
|
||||
await testClickResultTelemetry({});
|
||||
testClickResultTelemetry({});
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -40,7 +40,6 @@ async function testSetup() {
|
||||
});
|
||||
|
||||
// Reset GLEAN (FOG) telemetry to avoid data bleeding over from other tests.
|
||||
await Services.fog.testFlushAllChildren();
|
||||
Services.fog.testResetFOG();
|
||||
|
||||
registerCleanupFunction(() => {
|
||||
@ -402,15 +401,15 @@ async function testClickResultTelemetry(expected, resetFOG = true) {
|
||||
|
||||
let testMetricState = doAssert => {
|
||||
for (let label of labels) {
|
||||
let expectedValue = expected[label] ?? null;
|
||||
if (doAssert) {
|
||||
is(
|
||||
Glean.cookieBannersClick.result[label].testGetValue(),
|
||||
expectedValue,
|
||||
expected[label],
|
||||
`Counter for label '${label}' has correct state.`
|
||||
);
|
||||
} else if (
|
||||
Glean.cookieBannersClick.result[label].testGetValue() !== expectedValue
|
||||
Glean.cookieBannersClick.result[label].testGetValue() !==
|
||||
expected[label]
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
@ -433,7 +432,6 @@ async function testClickResultTelemetry(expected, resetFOG = true) {
|
||||
// Reset telemetry, even if the test condition above throws. This is to
|
||||
// avoid failing subsequent tests in case of a test failure.
|
||||
if (resetFOG) {
|
||||
await Services.fog.testFlushAllChildren();
|
||||
Services.fog.testResetFOG();
|
||||
}
|
||||
}
|
||||
|
@ -114,9 +114,9 @@ add_task(async function test_startupCache_load_timestamps() {
|
||||
|
||||
let gleanMetric = Glean.extensions.startupCacheLoadTime.testGetValue();
|
||||
equal(
|
||||
gleanMetric,
|
||||
null,
|
||||
"Expect extensions.startup_cache_load_time Glean metric to be initially null"
|
||||
typeof gleanMetric,
|
||||
"undefined",
|
||||
"Expect extensions.startup_cache_load_time Glean metric to be initially undefined"
|
||||
);
|
||||
|
||||
// Make sure the _readData has been called and we can expect
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Category, mParent)
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(Category)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(Category)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(Category)
|
||||
@ -26,7 +26,7 @@ JSObject* Category::WrapObject(JSContext* aCx,
|
||||
return dom::GleanCategory_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
already_AddRefed<GleanMetric> Category::NamedGetter(const nsAString& aName,
|
||||
already_AddRefed<nsISupports> Category::NamedGetter(const nsAString& aName,
|
||||
bool& aFound) {
|
||||
aFound = false;
|
||||
|
||||
@ -45,8 +45,8 @@ already_AddRefed<GleanMetric> Category::NamedGetter(const nsAString& aName,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
aFound = true; // Should always be true (MOZ_ASSERT_UNREACHABLE-guarded).
|
||||
return NewMetricFromId(metricIdx.value(), mParent);
|
||||
aFound = true;
|
||||
return NewMetricFromId(metricIdx.value());
|
||||
}
|
||||
|
||||
bool Category::NameIsEnumerable(const nsAString& aName) { return false; }
|
||||
|
@ -8,7 +8,6 @@
|
||||
#define mozilla_glean_Category_h
|
||||
|
||||
#include "js/TypeDecls.h"
|
||||
#include "mozilla/glean/bindings/GleanMetric.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsTArrayForwardDeclare.h"
|
||||
#include "nsWrapperCache.h"
|
||||
@ -22,19 +21,17 @@ class Category final : public nsISupports, public nsWrapperCache {
|
||||
|
||||
JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
nsISupports* GetParentObject() { return mParent; };
|
||||
nsISupports* GetParentObject() { return nullptr; }
|
||||
|
||||
explicit Category(nsCString&& aName, nsISupports* aParent)
|
||||
: mName(aName), mParent(aParent) {}
|
||||
explicit Category(nsCString&& aName) : mName(aName) {}
|
||||
|
||||
already_AddRefed<GleanMetric> NamedGetter(const nsAString& aName,
|
||||
already_AddRefed<nsISupports> NamedGetter(const nsAString& aName,
|
||||
bool& aFound);
|
||||
bool NameIsEnumerable(const nsAString& aName);
|
||||
void GetSupportedNames(nsTArray<nsString>& aNames);
|
||||
|
||||
private:
|
||||
nsCString mName;
|
||||
nsCOMPtr<nsISupports> mParent;
|
||||
|
||||
protected:
|
||||
virtual ~Category() = default;
|
||||
|
@ -25,7 +25,7 @@ namespace mozilla::glean {
|
||||
// Threading: Must only be read or written to on the main thread.
|
||||
static bool gRuntimeMetricsComprehensive = false;
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Glean, mParent)
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(Glean)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(Glean)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(Glean)
|
||||
@ -52,7 +52,7 @@ bool Glean::DefineGlean(JSContext* aCx, JS::Handle<JSObject*> aGlobal) {
|
||||
JS::Rooted<JS::Value> glean(aCx);
|
||||
js::AssertSameCompartment(aCx, aGlobal);
|
||||
|
||||
auto impl = MakeRefPtr<Glean>(global);
|
||||
auto impl = MakeRefPtr<Glean>();
|
||||
if (!dom::GetOrCreateDOMReflector(aCx, impl.get(), &glean)) {
|
||||
return false;
|
||||
}
|
||||
@ -69,7 +69,7 @@ already_AddRefed<Category> Glean::NamedGetter(const nsAString& aName,
|
||||
NS_ConvertUTF16toUTF8 categoryName(aName);
|
||||
if (JOG::HasCategory(categoryName)) {
|
||||
aFound = true;
|
||||
return MakeAndAddRef<Category>(std::move(categoryName), mParent);
|
||||
return MakeAndAddRef<Category>(std::move(categoryName));
|
||||
}
|
||||
|
||||
if (gRuntimeMetricsComprehensive) {
|
||||
@ -87,7 +87,7 @@ already_AddRefed<Category> Glean::NamedGetter(const nsAString& aName,
|
||||
|
||||
aFound = true;
|
||||
nsDependentCString name(GetCategoryName(categoryIdx.value()));
|
||||
return MakeAndAddRef<Category>(std::move(name), mParent);
|
||||
return MakeAndAddRef<Category>(std::move(name));
|
||||
}
|
||||
|
||||
bool Glean::NameIsEnumerable(const nsAString& aName) { return false; }
|
||||
|
@ -8,7 +8,6 @@
|
||||
#define mozilla_glean_Glean_h
|
||||
|
||||
#include "js/TypeDecls.h"
|
||||
#include "nsGlobalWindowInner.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsTArrayForwardDeclare.h"
|
||||
#include "nsWrapperCache.h"
|
||||
@ -22,11 +21,9 @@ class Glean final : public nsISupports, public nsWrapperCache {
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(Glean)
|
||||
|
||||
explicit Glean(nsIGlobalObject* aGlobal) : mParent(aGlobal) {}
|
||||
|
||||
JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
nsISupports* GetParentObject() { return mParent; }
|
||||
nsISupports* GetParentObject() { return nullptr; }
|
||||
|
||||
static bool DefineGlean(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
|
||||
|
||||
@ -45,9 +42,6 @@ class Glean final : public nsISupports, public nsWrapperCache {
|
||||
*/
|
||||
static void TestSetRuntimeMetricsComprehensive(bool aIsComprehensive);
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsISupports> mParent;
|
||||
|
||||
protected:
|
||||
virtual ~Glean() = default;
|
||||
};
|
||||
|
@ -1,22 +0,0 @@
|
||||
/* -*- 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/. */
|
||||
|
||||
#include "mozilla/glean/bindings/GleanMetric.h"
|
||||
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(GleanMetric, mParent)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(GleanMetric)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(GleanMetric)
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GleanMetric)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
} // namespace mozilla::glean
|
@ -1,31 +0,0 @@
|
||||
/* -*- 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 mozilla_glean_GleanMetric_h
|
||||
#define mozilla_glean_GleanMetric_h
|
||||
|
||||
#include "js/TypeDecls.h"
|
||||
#include "nsIGlobalObject.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
class GleanMetric : public nsISupports, public nsWrapperCache {
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS;
|
||||
NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(GleanMetric);
|
||||
|
||||
nsISupports* GetParentObject() const { return mParent; }
|
||||
|
||||
protected:
|
||||
GleanMetric(nsISupports* aParent) : mParent(aParent) {}
|
||||
virtual ~GleanMetric() = default;
|
||||
nsCOMPtr<nsISupports> mParent;
|
||||
};
|
||||
|
||||
} // namespace mozilla::glean
|
||||
|
||||
#endif /* mozilla_glean_GleanMetric_h */
|
@ -7,10 +7,12 @@
|
||||
#include "mozilla/glean/bindings/Boolean.h"
|
||||
|
||||
#include "nsString.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/dom/GleanMetricsBinding.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
#include "Common.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
@ -46,26 +48,32 @@ Result<Maybe<bool>, nsCString> BooleanMetric::TestGetValue(
|
||||
|
||||
} // namespace impl
|
||||
|
||||
JSObject* GleanBoolean::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
return dom::GleanBoolean_Binding::Wrap(aCx, this, aGivenProto);
|
||||
NS_IMPL_CLASSINFO(GleanBoolean, nullptr, 0, {0})
|
||||
NS_IMPL_ISUPPORTS_CI(GleanBoolean, nsIGleanBoolean)
|
||||
|
||||
NS_IMETHODIMP
|
||||
GleanBoolean::Set(bool aValue) {
|
||||
mBoolean.Set(aValue);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanBoolean::Set(bool aValue) { mBoolean.Set(aValue); }
|
||||
|
||||
dom::Nullable<bool> GleanBoolean::TestGetValue(const nsACString& aPingName,
|
||||
ErrorResult& aRv) {
|
||||
dom::Nullable<bool> ret;
|
||||
auto result = mBoolean.TestGetValue(aPingName);
|
||||
NS_IMETHODIMP
|
||||
GleanBoolean::TestGetValue(const nsACString& aStorageName,
|
||||
JS::MutableHandle<JS::Value> aResult) {
|
||||
auto result = mBoolean.TestGetValue(aStorageName);
|
||||
if (result.isErr()) {
|
||||
aRv.ThrowDataError(result.unwrapErr());
|
||||
return ret;
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (!optresult.isNothing()) {
|
||||
ret.SetValue(optresult.value());
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
aResult.set(JS::BooleanValue(optresult.value()));
|
||||
}
|
||||
return ret;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla::glean
|
||||
|
@ -7,11 +7,9 @@
|
||||
#ifndef mozilla_glean_GleanBoolean_h
|
||||
#define mozilla_glean_GleanBoolean_h
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/glean/bindings/GleanMetric.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsString.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace glean {
|
||||
@ -55,18 +53,12 @@ class BooleanMetric {
|
||||
|
||||
} // namespace impl
|
||||
|
||||
class GleanBoolean final : public GleanMetric {
|
||||
class GleanBoolean final : public nsIGleanBoolean {
|
||||
public:
|
||||
explicit GleanBoolean(uint32_t id, nsISupports* aParent)
|
||||
: GleanMetric(aParent), mBoolean(id) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGLEANBOOLEAN
|
||||
|
||||
virtual JSObject* WrapObject(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final;
|
||||
|
||||
void Set(bool aValue);
|
||||
|
||||
dom::Nullable<bool> TestGetValue(const nsACString& aPingName,
|
||||
ErrorResult& aRv);
|
||||
explicit GleanBoolean(uint32_t id) : mBoolean(id){};
|
||||
|
||||
private:
|
||||
virtual ~GleanBoolean() = default;
|
||||
|
@ -7,10 +7,13 @@
|
||||
#include "mozilla/glean/bindings/Counter.h"
|
||||
|
||||
#include "nsString.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/dom/GleanMetricsBinding.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "Common.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
#include "nsIScriptError.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
@ -48,27 +51,32 @@ Result<Maybe<int32_t>, nsCString> CounterMetric::TestGetValue(
|
||||
|
||||
} // namespace impl
|
||||
|
||||
/* virtual */
|
||||
JSObject* GleanCounter::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
return dom::GleanCounter_Binding::Wrap(aCx, this, aGivenProto);
|
||||
NS_IMPL_CLASSINFO(GleanCounter, nullptr, 0, {0})
|
||||
NS_IMPL_ISUPPORTS_CI(GleanCounter, nsIGleanCounter)
|
||||
|
||||
NS_IMETHODIMP
|
||||
GleanCounter::Add(int32_t aAmount) {
|
||||
mCounter.Add(aAmount);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanCounter::Add(int32_t aAmount) { mCounter.Add(aAmount); }
|
||||
|
||||
dom::Nullable<int32_t> GleanCounter::TestGetValue(const nsACString& aPingName,
|
||||
ErrorResult& aRv) {
|
||||
dom::Nullable<int32_t> ret;
|
||||
auto result = mCounter.TestGetValue(aPingName);
|
||||
NS_IMETHODIMP
|
||||
GleanCounter::TestGetValue(const nsACString& aStorageName,
|
||||
JS::MutableHandle<JS::Value> aResult) {
|
||||
auto result = mCounter.TestGetValue(aStorageName);
|
||||
if (result.isErr()) {
|
||||
aRv.ThrowDataError(result.unwrapErr());
|
||||
return ret;
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (!optresult.isNothing()) {
|
||||
ret.SetValue(optresult.value());
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
aResult.set(JS::Int32Value(optresult.value()));
|
||||
}
|
||||
return ret;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla::glean
|
||||
|
@ -7,10 +7,9 @@
|
||||
#ifndef mozilla_glean_GleanCounter_h
|
||||
#define mozilla_glean_GleanCounter_h
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/glean/bindings/GleanMetric.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsString.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
@ -53,18 +52,12 @@ class CounterMetric {
|
||||
};
|
||||
} // namespace impl
|
||||
|
||||
class GleanCounter final : public GleanMetric {
|
||||
class GleanCounter final : public nsIGleanCounter {
|
||||
public:
|
||||
explicit GleanCounter(uint32_t id, nsISupports* aParent)
|
||||
: GleanMetric(aParent), mCounter(id) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGLEANCOUNTER
|
||||
|
||||
virtual JSObject* WrapObject(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final;
|
||||
|
||||
void Add(int32_t aAmount);
|
||||
|
||||
dom::Nullable<int32_t> TestGetValue(const nsACString& aPingName,
|
||||
ErrorResult& aRv);
|
||||
explicit GleanCounter(uint32_t id) : mCounter(id){};
|
||||
|
||||
private:
|
||||
virtual ~GleanCounter() = default;
|
||||
|
@ -6,10 +6,12 @@
|
||||
|
||||
#include "mozilla/glean/bindings/CustomDistribution.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/dom/GleanMetricsBinding.h"
|
||||
#include "mozilla/glean/bindings/HistogramGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
#include "nsJSUtils.h"
|
||||
#include "nsPrintfCString.h"
|
||||
#include "nsString.h"
|
||||
@ -66,40 +68,58 @@ CustomDistributionMetric::TestGetValue(const nsACString& aPingName) const {
|
||||
|
||||
} // namespace impl
|
||||
|
||||
/* virtual */
|
||||
JSObject* GleanCustomDistribution::WrapObject(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
|
||||
return dom::GleanCustomDistribution_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
NS_IMPL_CLASSINFO(GleanCustomDistribution, nullptr, 0, {0})
|
||||
NS_IMPL_ISUPPORTS_CI(GleanCustomDistribution, nsIGleanCustomDistribution)
|
||||
|
||||
void GleanCustomDistribution::AccumulateSamples(
|
||||
const dom::Sequence<int64_t>& aSamples) {
|
||||
NS_IMETHODIMP
|
||||
GleanCustomDistribution::AccumulateSamples(const nsTArray<int64_t>& aSamples) {
|
||||
mCustomDist.AccumulateSamplesSigned(aSamples);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanCustomDistribution::TestGetValue(
|
||||
const nsACString& aPingName,
|
||||
dom::Nullable<dom::GleanDistributionData>& aRetval, ErrorResult& aRv) {
|
||||
NS_IMETHODIMP
|
||||
GleanCustomDistribution::TestGetValue(const nsACString& aPingName,
|
||||
JSContext* aCx,
|
||||
JS::MutableHandle<JS::Value> aResult) {
|
||||
auto result = mCustomDist.TestGetValue(aPingName);
|
||||
if (result.isErr()) {
|
||||
aRv.ThrowDataError(result.unwrapErr());
|
||||
return;
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (optresult.isNothing()) {
|
||||
return;
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
// Build return value of the form: { sum: #, values: {bucket1: count1, ...}
|
||||
JS::Rooted<JSObject*> root(aCx, JS_NewPlainObject(aCx));
|
||||
if (!root) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
uint64_t sum = optresult.ref().sum;
|
||||
if (!JS_DefineProperty(aCx, root, "sum", static_cast<double>(sum),
|
||||
JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JS::Rooted<JSObject*> valuesObj(aCx, JS_NewPlainObject(aCx));
|
||||
if (!valuesObj ||
|
||||
!JS_DefineProperty(aCx, root, "values", valuesObj, JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
dom::GleanDistributionData ret;
|
||||
ret.mSum = optresult.ref().sum;
|
||||
auto& data = optresult.ref().values;
|
||||
for (const auto& entry : data) {
|
||||
dom::binding_detail::RecordEntry<nsCString, uint64_t> bucket;
|
||||
bucket.mKey = nsPrintfCString("%" PRIu64, entry.GetKey());
|
||||
bucket.mValue = entry.GetData();
|
||||
ret.mValues.Entries().EmplaceBack(std::move(bucket));
|
||||
const uint64_t bucket = entry.GetKey();
|
||||
const uint64_t count = entry.GetData();
|
||||
if (!JS_DefineProperty(aCx, valuesObj,
|
||||
nsPrintfCString("%" PRIu64, bucket).get(),
|
||||
static_cast<double>(count), JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
aRetval.SetValue(std::move(ret));
|
||||
}
|
||||
aResult.setObject(*root);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla::glean
|
||||
|
@ -7,17 +7,12 @@
|
||||
#ifndef mozilla_glean_GleanCustomDistribution_h
|
||||
#define mozilla_glean_GleanCustomDistribution_h
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/glean/bindings/GleanMetric.h"
|
||||
#include "mozilla/glean/bindings/DistributionData.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
namespace mozilla::dom {
|
||||
struct GleanDistributionData;
|
||||
} // namespace mozilla::dom
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
namespace impl {
|
||||
@ -70,19 +65,12 @@ class CustomDistributionMetric {
|
||||
};
|
||||
} // namespace impl
|
||||
|
||||
class GleanCustomDistribution final : public GleanMetric {
|
||||
class GleanCustomDistribution final : public nsIGleanCustomDistribution {
|
||||
public:
|
||||
explicit GleanCustomDistribution(uint64_t aId, nsISupports* aParent)
|
||||
: GleanMetric(aParent), mCustomDist(aId) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGLEANCUSTOMDISTRIBUTION
|
||||
|
||||
virtual JSObject* WrapObject(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final;
|
||||
|
||||
void AccumulateSamples(const dom::Sequence<int64_t>& aSamples);
|
||||
|
||||
void TestGetValue(const nsACString& aPingName,
|
||||
dom::Nullable<dom::GleanDistributionData>& aRetval,
|
||||
ErrorResult& aRv);
|
||||
explicit GleanCustomDistribution(uint64_t aId) : mCustomDist(aId){};
|
||||
|
||||
private:
|
||||
virtual ~GleanCustomDistribution() = default;
|
||||
|
@ -9,10 +9,13 @@
|
||||
#include "jsapi.h"
|
||||
#include "js/Date.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIScriptError.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/dom/GleanMetricsBinding.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
#include "Common.h"
|
||||
#include "prtime.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
@ -81,30 +84,31 @@ Result<Maybe<PRExplodedTime>, nsCString> DatetimeMetric::TestGetValue(
|
||||
|
||||
} // namespace impl
|
||||
|
||||
/* virtual */
|
||||
JSObject* GleanDatetime::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
return dom::GleanDatetime_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
NS_IMPL_CLASSINFO(GleanDatetime, nullptr, 0, {0})
|
||||
NS_IMPL_ISUPPORTS_CI(GleanDatetime, nsIGleanDatetime)
|
||||
|
||||
void GleanDatetime::Set(const dom::Optional<int64_t>& aValue) {
|
||||
if (aValue.WasPassed()) {
|
||||
PRExplodedTime exploded;
|
||||
PR_ExplodeTime(aValue.Value(), PR_LocalTimeParameters, &exploded);
|
||||
mDatetime.Set(&exploded);
|
||||
} else {
|
||||
NS_IMETHODIMP
|
||||
GleanDatetime::Set(PRTime aValue, uint8_t aOptionalArgc) {
|
||||
if (aOptionalArgc == 0) {
|
||||
mDatetime.Set();
|
||||
}
|
||||
} else {
|
||||
PRExplodedTime exploded;
|
||||
PR_ExplodeTime(aValue, PR_LocalTimeParameters, &exploded);
|
||||
mDatetime.Set(&exploded);
|
||||
}
|
||||
|
||||
void GleanDatetime::TestGetValue(JSContext* aCx, const nsACString& aPingName,
|
||||
JS::MutableHandle<JS::Value> aResult,
|
||||
ErrorResult& aRv) {
|
||||
auto result = mDatetime.TestGetValue(aPingName);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GleanDatetime::TestGetValue(const nsACString& aStorageName, JSContext* aCx,
|
||||
JS::MutableHandle<JS::Value> aResult) {
|
||||
auto result = mDatetime.TestGetValue(aStorageName);
|
||||
if (result.isErr()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
aRv.ThrowDataError(result.unwrapErr());
|
||||
return;
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (optresult.isNothing()) {
|
||||
@ -116,6 +120,7 @@ void GleanDatetime::TestGetValue(JSContext* aCx, const nsACString& aPingName,
|
||||
JS::NewDateObject(aCx, JS::TimeClip(millis)));
|
||||
aResult.setObject(*root);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla::glean
|
||||
|
@ -7,12 +7,10 @@
|
||||
#ifndef mozilla_glean_GleanDatetime_h
|
||||
#define mozilla_glean_GleanDatetime_h
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/glean/bindings/GleanMetric.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsString.h"
|
||||
#include "nsWrapperCache.h"
|
||||
#include "prtime.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
@ -55,18 +53,12 @@ class DatetimeMetric {
|
||||
};
|
||||
} // namespace impl
|
||||
|
||||
class GleanDatetime final : public GleanMetric {
|
||||
class GleanDatetime final : public nsIGleanDatetime {
|
||||
public:
|
||||
explicit GleanDatetime(uint32_t aId, nsISupports* aParent)
|
||||
: GleanMetric(aParent), mDatetime(aId) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGLEANDATETIME
|
||||
|
||||
virtual JSObject* WrapObject(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final;
|
||||
|
||||
void Set(const dom::Optional<int64_t>& aValue);
|
||||
|
||||
void TestGetValue(JSContext* aCx, const nsACString& aPingName,
|
||||
JS::MutableHandle<JS::Value> aResult, ErrorResult& aRv);
|
||||
explicit GleanDatetime(uint32_t aId) : mDatetime(aId){};
|
||||
|
||||
private:
|
||||
virtual ~GleanDatetime() = default;
|
||||
|
@ -7,10 +7,13 @@
|
||||
#include "mozilla/glean/bindings/Denominator.h"
|
||||
|
||||
#include "nsString.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/dom/GleanMetricsBinding.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
#include "nsIScriptError.h"
|
||||
#include "Common.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
@ -38,27 +41,32 @@ Result<Maybe<int32_t>, nsCString> DenominatorMetric::TestGetValue(
|
||||
|
||||
} // namespace impl
|
||||
|
||||
/* virtual */
|
||||
JSObject* GleanDenominator::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
return dom::GleanDenominator_Binding::Wrap(aCx, this, aGivenProto);
|
||||
NS_IMPL_CLASSINFO(GleanDenominator, nullptr, 0, {0})
|
||||
NS_IMPL_ISUPPORTS_CI(GleanDenominator, nsIGleanDenominator)
|
||||
|
||||
NS_IMETHODIMP
|
||||
GleanDenominator::Add(int32_t aAmount) {
|
||||
mDenominator.Add(aAmount);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanDenominator::Add(int32_t aAmount) { mDenominator.Add(aAmount); }
|
||||
|
||||
dom::Nullable<int32_t> GleanDenominator::TestGetValue(
|
||||
const nsACString& aPingName, ErrorResult& aRv) {
|
||||
dom::Nullable<int32_t> ret;
|
||||
auto result = mDenominator.TestGetValue(aPingName);
|
||||
NS_IMETHODIMP
|
||||
GleanDenominator::TestGetValue(const nsACString& aStorageName,
|
||||
JS::MutableHandle<JS::Value> aResult) {
|
||||
auto result = mDenominator.TestGetValue(aStorageName);
|
||||
if (result.isErr()) {
|
||||
aRv.ThrowDataError(result.unwrapErr());
|
||||
return ret;
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (!optresult.isNothing()) {
|
||||
ret.SetValue(optresult.value());
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
aResult.set(JS::Int32Value(optresult.value()));
|
||||
}
|
||||
return ret;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla::glean
|
||||
|
@ -7,10 +7,9 @@
|
||||
#ifndef mozilla_glean_GleanDenominator_h
|
||||
#define mozilla_glean_GleanDenominator_h
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/glean/bindings/GleanMetric.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsString.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
@ -53,18 +52,12 @@ class DenominatorMetric {
|
||||
};
|
||||
} // namespace impl
|
||||
|
||||
class GleanDenominator final : public GleanMetric {
|
||||
class GleanDenominator final : public nsIGleanDenominator {
|
||||
public:
|
||||
explicit GleanDenominator(uint32_t id, nsISupports* aParent)
|
||||
: GleanMetric(aParent), mDenominator(id) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGLEANDENOMINATOR
|
||||
|
||||
virtual JSObject* WrapObject(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final;
|
||||
|
||||
void Add(int32_t aAmount);
|
||||
|
||||
dom::Nullable<int32_t> TestGetValue(const nsACString& aPingName,
|
||||
ErrorResult& aRv);
|
||||
explicit GleanDenominator(uint32_t id) : mDenominator(id){};
|
||||
|
||||
private:
|
||||
virtual ~GleanDenominator() = default;
|
||||
|
@ -6,20 +6,19 @@
|
||||
|
||||
#include "mozilla/glean/bindings/Event.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/dom/GleanMetricsBinding.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/dom/ToJSValue.h"
|
||||
#include "mozilla/glean/bindings/Common.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
#include "jsapi.h"
|
||||
#include "js/PropertyAndElement.h" // JS_DefineElement, JS_DefineProperty, JS_Enumerate, JS_GetProperty, JS_GetPropertyById
|
||||
#include "nsIScriptError.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
/* virtual */
|
||||
JSObject* GleanEvent::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
return dom::GleanEvent_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
NS_IMPL_CLASSINFO(GleanEvent, nullptr, 0, {0})
|
||||
NS_IMPL_ISUPPORTS_CI(GleanEvent, nsIGleanEvent)
|
||||
|
||||
// Convert all capital letters to "_x" where "x" is the corresponding lowercase.
|
||||
nsCString camelToSnake(const nsACString& aCamel) {
|
||||
@ -37,28 +36,76 @@ nsCString camelToSnake(const nsACString& aCamel) {
|
||||
return snake;
|
||||
}
|
||||
|
||||
void GleanEvent::Record(
|
||||
const dom::Optional<dom::Record<nsCString, nsCString>>& aExtra) {
|
||||
if (!aExtra.WasPassed()) {
|
||||
NS_IMETHODIMP
|
||||
GleanEvent::Record(JS::Handle<JS::Value> aExtra, JSContext* aCx) {
|
||||
if (aExtra.isNullOrUndefined()) {
|
||||
mEvent.Record();
|
||||
return;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!aExtra.isObject()) {
|
||||
LogToBrowserConsole(
|
||||
nsIScriptError::warningFlag,
|
||||
u"Extras need to be an object. Event will not be recorded."_ns);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsTArray<nsCString> extraKeys;
|
||||
nsTArray<nsCString> extraValues;
|
||||
CopyableTArray<Telemetry::EventExtraEntry> telExtras;
|
||||
for (const auto& entry : aExtra.Value().Entries()) {
|
||||
if (entry.mValue.IsVoid()) {
|
||||
// Someone passed undefined/null for this value.
|
||||
// Pretend it wasn't here.
|
||||
continue;
|
||||
|
||||
JS::Rooted<JSObject*> obj(aCx, &aExtra.toObject());
|
||||
JS::Rooted<JS::IdVector> ids(aCx, JS::IdVector(aCx));
|
||||
if (!JS_Enumerate(aCx, obj, &ids)) {
|
||||
LogToBrowserConsole(
|
||||
nsIScriptError::warningFlag,
|
||||
u"Failed to enumerate object. Event will not be recorded."_ns);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
for (size_t i = 0, n = ids.length(); i < n; i++) {
|
||||
nsAutoJSCString jsKey;
|
||||
if (!jsKey.init(aCx, ids[i])) {
|
||||
LogToBrowserConsole(
|
||||
nsIScriptError::warningFlag,
|
||||
u"Extra dictionary should only contain string keys. Event will not be recorded."_ns);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// We accept camelCase extra keys, but Glean requires snake_case.
|
||||
auto snakeKey = camelToSnake(entry.mKey);
|
||||
auto snakeKey = camelToSnake(jsKey);
|
||||
|
||||
JS::Rooted<JS::Value> value(aCx);
|
||||
if (!JS_GetPropertyById(aCx, obj, ids[i], &value)) {
|
||||
LogToBrowserConsole(
|
||||
nsIScriptError::warningFlag,
|
||||
u"Failed to get extra property. Event will not be recorded."_ns);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsAutoJSCString jsValue;
|
||||
if (value.isString() || (value.isInt32() && value.toInt32() >= 0) ||
|
||||
value.isBoolean()) {
|
||||
if (!jsValue.init(aCx, value)) {
|
||||
LogToBrowserConsole(
|
||||
nsIScriptError::warningFlag,
|
||||
u"Can't extract extra property. Event will not be recorded."_ns);
|
||||
return NS_OK;
|
||||
}
|
||||
} else if (value.isNullOrUndefined()) {
|
||||
// The extra key is present, but has an empty value.
|
||||
// Treat as though it weren't here at all.
|
||||
continue;
|
||||
} else {
|
||||
LogToBrowserConsole(
|
||||
nsIScriptError::warningFlag,
|
||||
u"Extra properties should have string, bool or non-negative integer values. Event will not be recorded."_ns);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
extraKeys.AppendElement(snakeKey);
|
||||
extraValues.AppendElement(entry.mValue);
|
||||
telExtras.EmplaceBack(Telemetry::EventExtraEntry{entry.mKey, entry.mValue});
|
||||
extraValues.AppendElement(jsValue);
|
||||
telExtras.EmplaceBack(Telemetry::EventExtraEntry{jsKey, jsValue});
|
||||
}
|
||||
|
||||
// Since this calls the implementation directly, we need to implement GIFFT
|
||||
@ -72,39 +119,88 @@ void GleanEvent::Record(
|
||||
// Calling the implementation directly, because we have a `string->string`
|
||||
// map, not a `T->string` map the C++ API expects.
|
||||
impl::fog_event_record(mEvent.mId, &extraKeys, &extraValues);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanEvent::TestGetValue(
|
||||
const nsACString& aPingName,
|
||||
dom::Nullable<nsTArray<dom::GleanEventRecord>>& aResult, ErrorResult& aRv) {
|
||||
auto resEvents = mEvent.TestGetValue(aPingName);
|
||||
NS_IMETHODIMP
|
||||
GleanEvent::TestGetValue(const nsACString& aStorageName, JSContext* aCx,
|
||||
JS::MutableHandle<JS::Value> aResult) {
|
||||
auto resEvents = mEvent.TestGetValue(aStorageName);
|
||||
if (resEvents.isErr()) {
|
||||
aRv.ThrowDataError(resEvents.unwrapErr());
|
||||
return;
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(resEvents.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optEvents = resEvents.unwrap();
|
||||
if (optEvents.isNothing()) {
|
||||
return;
|
||||
aResult.set(JS::UndefinedValue());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsTArray<dom::GleanEventRecord> ret;
|
||||
for (auto& event : optEvents.extract()) {
|
||||
dom::GleanEventRecord record;
|
||||
if (!event.mExtra.IsEmpty()) {
|
||||
record.mExtra.Construct();
|
||||
for (auto& extraEntry : event.mExtra) {
|
||||
dom::binding_detail::RecordEntry<nsCString, nsCString> extra;
|
||||
extra.mKey = std::get<0>(extraEntry);
|
||||
extra.mValue = std::get<1>(extraEntry);
|
||||
record.mExtra.Value().Entries().EmplaceBack(std::move(extra));
|
||||
auto events = optEvents.extract();
|
||||
|
||||
auto count = events.Length();
|
||||
JS::Rooted<JSObject*> eventArray(aCx, JS::NewArrayObject(aCx, count));
|
||||
if (NS_WARN_IF(!eventArray)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
auto* value = &events[i];
|
||||
|
||||
JS::Rooted<JSObject*> eventObj(aCx, JS_NewPlainObject(aCx));
|
||||
if (NS_WARN_IF(!eventObj)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (!JS_DefineProperty(aCx, eventObj, "timestamp",
|
||||
(double)value->mTimestamp, JSPROP_ENUMERATE)) {
|
||||
NS_WARNING("Failed to define timestamp for event object.");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JS::Rooted<JS::Value> catStr(aCx);
|
||||
if (!dom::ToJSValue(aCx, value->mCategory, &catStr) ||
|
||||
!JS_DefineProperty(aCx, eventObj, "category", catStr,
|
||||
JSPROP_ENUMERATE)) {
|
||||
NS_WARNING("Failed to define category for event object.");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JS::Rooted<JS::Value> nameStr(aCx);
|
||||
if (!dom::ToJSValue(aCx, value->mName, &nameStr) ||
|
||||
!JS_DefineProperty(aCx, eventObj, "name", nameStr, JSPROP_ENUMERATE)) {
|
||||
NS_WARNING("Failed to define name for event object.");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JS::Rooted<JSObject*> extraObj(aCx, JS_NewPlainObject(aCx));
|
||||
if (!JS_DefineProperty(aCx, eventObj, "extra", extraObj,
|
||||
JSPROP_ENUMERATE)) {
|
||||
NS_WARNING("Failed to define extra for event object.");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
for (auto pair : value->mExtra) {
|
||||
auto key = std::get<0>(pair);
|
||||
auto val = std::get<1>(pair);
|
||||
JS::Rooted<JS::Value> valStr(aCx);
|
||||
if (!dom::ToJSValue(aCx, val, &valStr) ||
|
||||
!JS_DefineProperty(aCx, extraObj, key.Data(), valStr,
|
||||
JSPROP_ENUMERATE)) {
|
||||
NS_WARNING("Failed to define extra property for event object.");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
record.mCategory = event.mCategory;
|
||||
record.mName = event.mName;
|
||||
record.mTimestamp = event.mTimestamp;
|
||||
ret.EmplaceBack(std::move(record));
|
||||
|
||||
if (!JS_DefineElement(aCx, eventArray, i, eventObj, JSPROP_ENUMERATE)) {
|
||||
NS_WARNING("Failed to define item in events array.");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
aResult.SetValue(std::move(ret));
|
||||
}
|
||||
|
||||
aResult.setObject(*eventArray);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla::glean
|
||||
|
@ -7,8 +7,7 @@
|
||||
#ifndef mozilla_glean_GleanEvent_h
|
||||
#define mozilla_glean_GleanEvent_h
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/dom/Record.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "mozilla/glean/bindings/EventGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
@ -16,11 +15,6 @@
|
||||
#include "nsString.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
namespace mozilla::dom {
|
||||
// forward declaration
|
||||
struct GleanEventRecord;
|
||||
} // namespace mozilla::dom
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
// forward declaration
|
||||
@ -151,19 +145,12 @@ struct NoExtraKeys {
|
||||
}
|
||||
};
|
||||
|
||||
class GleanEvent final : public GleanMetric {
|
||||
class GleanEvent final : public nsIGleanEvent {
|
||||
public:
|
||||
explicit GleanEvent(uint32_t id, nsISupports* aParent)
|
||||
: GleanMetric(aParent), mEvent(id) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGLEANEVENT
|
||||
|
||||
virtual JSObject* WrapObject(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final;
|
||||
|
||||
void Record(const dom::Optional<dom::Record<nsCString, nsCString>>& aExtra);
|
||||
|
||||
void TestGetValue(const nsACString& aPingName,
|
||||
dom::Nullable<nsTArray<dom::GleanEventRecord>>& aResult,
|
||||
ErrorResult& aRv);
|
||||
explicit GleanEvent(uint32_t id) : mEvent(id){};
|
||||
|
||||
private:
|
||||
virtual ~GleanEvent() = default;
|
||||
|
@ -10,24 +10,33 @@
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "mozilla/glean/bindings/GleanJSMetricsLookup.h"
|
||||
#include "mozilla/glean/bindings/MetricTypes.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "nsString.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(GleanLabeled)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(GleanLabeled)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(GleanLabeled)
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GleanLabeled)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
JSObject* GleanLabeled::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
return dom::GleanLabeled_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
already_AddRefed<GleanMetric> GleanLabeled::NamedGetter(const nsAString& aName,
|
||||
already_AddRefed<nsISupports> GleanLabeled::NamedGetter(const nsAString& aName,
|
||||
bool& aFound) {
|
||||
auto label = NS_ConvertUTF16toUTF8(aName);
|
||||
// All strings will map to a label. Either a valid one or `__other__`.
|
||||
aFound = true;
|
||||
uint32_t submetricId = 0;
|
||||
already_AddRefed<GleanMetric> submetric =
|
||||
NewSubMetricFromIds(mTypeId, mId, label, &submetricId, mParent);
|
||||
already_AddRefed<nsISupports> submetric =
|
||||
NewSubMetricFromIds(mTypeId, mId, label, &submetricId);
|
||||
|
||||
auto mirrorId = ScalarIdForMetric(mId);
|
||||
if (mirrorId) {
|
||||
|
@ -7,6 +7,7 @@
|
||||
#ifndef mozilla_glean_Labeled_h
|
||||
#define mozilla_glean_Labeled_h
|
||||
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsWrapperCache.h"
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
@ -230,15 +231,19 @@ class Labeled<StringMetric, DynamicLabel> {
|
||||
|
||||
} // namespace impl
|
||||
|
||||
class GleanLabeled final : public GleanMetric {
|
||||
class GleanLabeled final : public nsISupports, public nsWrapperCache {
|
||||
public:
|
||||
explicit GleanLabeled(uint32_t aId, uint32_t aTypeId, nsISupports* aParent)
|
||||
: GleanMetric(aParent), mId(aId), mTypeId(aTypeId) {}
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(GleanLabeled)
|
||||
|
||||
JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override final;
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
nsISupports* GetParentObject() { return nullptr; }
|
||||
|
||||
already_AddRefed<GleanMetric> NamedGetter(const nsAString& aName,
|
||||
explicit GleanLabeled(uint32_t aId, uint32_t aTypeId)
|
||||
: mId(aId), mTypeId(aTypeId){};
|
||||
|
||||
already_AddRefed<nsISupports> NamedGetter(const nsAString& aName,
|
||||
bool& aFound);
|
||||
bool NameIsEnumerable(const nsAString& aName);
|
||||
void GetSupportedNames(nsTArray<nsString>& aNames);
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/dom/GleanMetricsBinding.h"
|
||||
#include "mozilla/glean/bindings/HistogramGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
@ -51,39 +50,57 @@ MemoryDistributionMetric::TestGetValue(const nsACString& aPingName) const {
|
||||
|
||||
} // namespace impl
|
||||
|
||||
/* virtual */
|
||||
JSObject* GleanMemoryDistribution::WrapObject(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
|
||||
return dom::GleanMemoryDistribution_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
NS_IMPL_CLASSINFO(GleanMemoryDistribution, nullptr, 0, {0})
|
||||
NS_IMPL_ISUPPORTS_CI(GleanMemoryDistribution, nsIGleanMemoryDistribution)
|
||||
|
||||
void GleanMemoryDistribution::Accumulate(uint64_t aSample) {
|
||||
NS_IMETHODIMP
|
||||
GleanMemoryDistribution::Accumulate(uint64_t aSample) {
|
||||
mMemoryDist.Accumulate(aSample);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanMemoryDistribution::TestGetValue(
|
||||
const nsACString& aPingName,
|
||||
dom::Nullable<dom::GleanDistributionData>& aRetval, ErrorResult& aRv) {
|
||||
NS_IMETHODIMP
|
||||
GleanMemoryDistribution::TestGetValue(const nsACString& aPingName,
|
||||
JSContext* aCx,
|
||||
JS::MutableHandle<JS::Value> aResult) {
|
||||
auto result = mMemoryDist.TestGetValue(aPingName);
|
||||
if (result.isErr()) {
|
||||
aRv.ThrowDataError(result.unwrapErr());
|
||||
return;
|
||||
aResult.set(JS::UndefinedValue());
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (optresult.isNothing()) {
|
||||
return;
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
// Build return value of the form:
|
||||
// { sum: #, values: {bucket1: count1, ...} }
|
||||
JS::Rooted<JSObject*> root(aCx, JS_NewPlainObject(aCx));
|
||||
if (!root) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
uint64_t sum = optresult.ref().sum;
|
||||
if (!JS_DefineProperty(aCx, root, "sum", static_cast<double>(sum),
|
||||
JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JS::Rooted<JSObject*> valuesObj(aCx, JS_NewPlainObject(aCx));
|
||||
if (!valuesObj ||
|
||||
!JS_DefineProperty(aCx, root, "values", valuesObj, JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
dom::GleanDistributionData ret;
|
||||
ret.mSum = optresult.ref().sum;
|
||||
auto& data = optresult.ref().values;
|
||||
for (const auto& entry : data) {
|
||||
dom::binding_detail::RecordEntry<nsCString, uint64_t> bucket;
|
||||
bucket.mKey = nsPrintfCString("%" PRIu64, entry.GetKey());
|
||||
bucket.mValue = entry.GetData();
|
||||
ret.mValues.Entries().EmplaceBack(std::move(bucket));
|
||||
const uint64_t bucket = entry.GetKey();
|
||||
const uint64_t count = entry.GetData();
|
||||
if (!JS_DefineProperty(aCx, valuesObj,
|
||||
nsPrintfCString("%" PRIu64, bucket).get(),
|
||||
static_cast<double>(count), JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
aRetval.SetValue(std::move(ret));
|
||||
}
|
||||
aResult.setObject(*root);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla::glean
|
||||
|
@ -7,16 +7,11 @@
|
||||
#ifndef mozilla_glean_GleanMemoryDistribution_h
|
||||
#define mozilla_glean_GleanMemoryDistribution_h
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/glean/bindings/DistributionData.h"
|
||||
#include "mozilla/glean/bindings/GleanMetric.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
namespace mozilla::dom {
|
||||
struct GleanDistributionData;
|
||||
} // namespace mozilla::dom
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
namespace impl {
|
||||
@ -61,19 +56,12 @@ class MemoryDistributionMetric {
|
||||
};
|
||||
} // namespace impl
|
||||
|
||||
class GleanMemoryDistribution final : public GleanMetric {
|
||||
class GleanMemoryDistribution final : public nsIGleanMemoryDistribution {
|
||||
public:
|
||||
explicit GleanMemoryDistribution(uint64_t aId, nsISupports* aParent)
|
||||
: GleanMetric(aParent), mMemoryDist(aId) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGLEANMEMORYDISTRIBUTION
|
||||
|
||||
virtual JSObject* WrapObject(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final;
|
||||
|
||||
void Accumulate(uint64_t aSample);
|
||||
|
||||
void TestGetValue(const nsACString& aPingName,
|
||||
dom::Nullable<dom::GleanDistributionData>& aRetval,
|
||||
ErrorResult& aRv);
|
||||
explicit GleanMemoryDistribution(uint64_t aId) : mMemoryDist(aId){};
|
||||
|
||||
private:
|
||||
virtual ~GleanMemoryDistribution() = default;
|
||||
|
@ -7,10 +7,13 @@
|
||||
#include "mozilla/glean/bindings/Numerator.h"
|
||||
|
||||
#include "nsString.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/dom/GleanMetricsBinding.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
#include "nsIScriptError.h"
|
||||
#include "Common.h"
|
||||
#include "jsapi.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
@ -42,32 +45,48 @@ NumeratorMetric::TestGetValue(const nsACString& aPingName) const {
|
||||
|
||||
} // namespace impl
|
||||
|
||||
/* virtual */
|
||||
JSObject* GleanNumerator::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
return dom::GleanNumerator_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
NS_IMPL_CLASSINFO(GleanNumerator, nullptr, 0, {0})
|
||||
NS_IMPL_ISUPPORTS_CI(GleanNumerator, nsIGleanNumerator)
|
||||
|
||||
void GleanNumerator::AddToNumerator(int32_t aAmount) {
|
||||
NS_IMETHODIMP
|
||||
GleanNumerator::AddToNumerator(int32_t aAmount) {
|
||||
mNumerator.AddToNumerator(aAmount);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanNumerator::TestGetValue(const nsACString& aPingName,
|
||||
dom::Nullable<dom::GleanRateData>& aResult,
|
||||
ErrorResult& aRv) {
|
||||
NS_IMETHODIMP
|
||||
GleanNumerator::TestGetValue(const nsACString& aPingName, JSContext* aCx,
|
||||
JS::MutableHandle<JS::Value> aResult) {
|
||||
auto result = mNumerator.TestGetValue(aPingName);
|
||||
if (result.isErr()) {
|
||||
aRv.ThrowDataError(result.unwrapErr());
|
||||
return;
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (!optresult.isNothing()) {
|
||||
dom::GleanRateData ret;
|
||||
auto pair = optresult.extract();
|
||||
ret.mNumerator = pair.first;
|
||||
ret.mDenominator = pair.second;
|
||||
aResult.SetValue(std::move(ret));
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
// Build return value of the form: { numerator: n, denominator: d }
|
||||
JS::Rooted<JSObject*> root(aCx, JS_NewPlainObject(aCx));
|
||||
if (!root) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
auto pair = optresult.extract();
|
||||
int32_t num = pair.first;
|
||||
int32_t den = pair.second;
|
||||
if (!JS_DefineProperty(aCx, root, "numerator", static_cast<double>(num),
|
||||
JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
if (!JS_DefineProperty(aCx, root, "denominator", static_cast<double>(den),
|
||||
JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
aResult.setObject(*root);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla::glean
|
||||
|
@ -7,16 +7,11 @@
|
||||
#ifndef mozilla_glean_GleanNumerator_h
|
||||
#define mozilla_glean_GleanNumerator_h
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/glean/bindings/GleanMetric.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsString.h"
|
||||
|
||||
namespace mozilla::dom {
|
||||
struct GleanRateData;
|
||||
} // namespace mozilla::dom
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
namespace impl {
|
||||
@ -59,19 +54,12 @@ class NumeratorMetric {
|
||||
};
|
||||
} // namespace impl
|
||||
|
||||
class GleanNumerator final : public GleanMetric {
|
||||
class GleanNumerator final : public nsIGleanNumerator {
|
||||
public:
|
||||
explicit GleanNumerator(uint32_t id, nsISupports* aParent)
|
||||
: GleanMetric(aParent), mNumerator(id) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGLEANNUMERATOR
|
||||
|
||||
virtual JSObject* WrapObject(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final;
|
||||
|
||||
void AddToNumerator(int32_t aAmount);
|
||||
|
||||
void TestGetValue(const nsACString& aPingName,
|
||||
dom::Nullable<dom::GleanRateData>& aResult,
|
||||
ErrorResult& aRv);
|
||||
explicit GleanNumerator(uint32_t id) : mNumerator(id){};
|
||||
|
||||
private:
|
||||
virtual ~GleanNumerator() = default;
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "mozilla/DataMutex.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "nsIGleanPing.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsString.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
@ -6,11 +6,13 @@
|
||||
|
||||
#include "mozilla/glean/bindings/Quantity.h"
|
||||
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/dom/GleanMetricsBinding.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
#include "nsString.h"
|
||||
#include "Common.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
@ -42,27 +44,32 @@ Result<Maybe<int64_t>, nsCString> QuantityMetric::TestGetValue(
|
||||
|
||||
} // namespace impl
|
||||
|
||||
/* virtual */
|
||||
JSObject* GleanQuantity::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
return dom::GleanQuantity_Binding::Wrap(aCx, this, aGivenProto);
|
||||
NS_IMPL_CLASSINFO(GleanQuantity, nullptr, 0, {0})
|
||||
NS_IMPL_ISUPPORTS_CI(GleanQuantity, nsIGleanQuantity)
|
||||
|
||||
NS_IMETHODIMP
|
||||
GleanQuantity::Set(int64_t aValue) {
|
||||
mQuantity.Set(aValue);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanQuantity::Set(int64_t aValue) { mQuantity.Set(aValue); }
|
||||
|
||||
dom::Nullable<int64_t> GleanQuantity::TestGetValue(const nsACString& aPingName,
|
||||
ErrorResult& aRv) {
|
||||
dom::Nullable<int64_t> ret;
|
||||
NS_IMETHODIMP
|
||||
GleanQuantity::TestGetValue(const nsACString& aPingName,
|
||||
JS::MutableHandle<JS::Value> aResult) {
|
||||
auto result = mQuantity.TestGetValue(aPingName);
|
||||
if (result.isErr()) {
|
||||
aRv.ThrowDataError(result.unwrapErr());
|
||||
return ret;
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (!optresult.isNothing()) {
|
||||
ret.SetValue(optresult.value());
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
aResult.set(JS::DoubleValue(static_cast<double>(optresult.value())));
|
||||
}
|
||||
return ret;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla::glean
|
||||
|
@ -7,8 +7,7 @@
|
||||
#ifndef mozilla_glean_GleanQuantity_h
|
||||
#define mozilla_glean_GleanQuantity_h
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/glean/bindings/GleanMetric.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsTString.h"
|
||||
#include "nsIScriptError.h"
|
||||
|
||||
@ -53,18 +52,12 @@ class QuantityMetric {
|
||||
|
||||
} // namespace impl
|
||||
|
||||
class GleanQuantity final : public GleanMetric {
|
||||
class GleanQuantity final : public nsIGleanQuantity {
|
||||
public:
|
||||
explicit GleanQuantity(uint32_t id, nsISupports* aParent)
|
||||
: GleanMetric(aParent), mQuantity(id) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGLEANQUANTITY
|
||||
|
||||
virtual JSObject* WrapObject(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final;
|
||||
|
||||
void Set(int64_t aValue);
|
||||
|
||||
dom::Nullable<int64_t> TestGetValue(const nsACString& aPingName,
|
||||
ErrorResult& aRv);
|
||||
explicit GleanQuantity(uint32_t id) : mQuantity(id){};
|
||||
|
||||
private:
|
||||
virtual ~GleanQuantity() = default;
|
||||
|
@ -8,11 +8,12 @@
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/dom/GleanMetricsBinding.h"
|
||||
#include "mozilla/glean/bindings/Common.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
@ -51,36 +52,54 @@ Result<Maybe<std::pair<int32_t, int32_t>>, nsCString> RateMetric::TestGetValue(
|
||||
|
||||
} // namespace impl
|
||||
|
||||
/* virtual */
|
||||
JSObject* GleanRate::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
return dom::GleanRate_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
NS_IMPL_CLASSINFO(GleanRate, nullptr, 0, {0})
|
||||
NS_IMPL_ISUPPORTS_CI(GleanRate, nsIGleanRate)
|
||||
|
||||
void GleanRate::AddToNumerator(int32_t aAmount) {
|
||||
NS_IMETHODIMP
|
||||
GleanRate::AddToNumerator(int32_t aAmount) {
|
||||
mRate.AddToNumerator(aAmount);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanRate::AddToDenominator(int32_t aAmount) {
|
||||
NS_IMETHODIMP
|
||||
GleanRate::AddToDenominator(int32_t aAmount) {
|
||||
mRate.AddToDenominator(aAmount);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanRate::TestGetValue(const nsACString& aPingName,
|
||||
dom::Nullable<dom::GleanRateData>& aResult,
|
||||
ErrorResult& aRv) {
|
||||
NS_IMETHODIMP
|
||||
GleanRate::TestGetValue(const nsACString& aPingName, JSContext* aCx,
|
||||
JS::MutableHandle<JS::Value> aResult) {
|
||||
auto result = mRate.TestGetValue(aPingName);
|
||||
if (result.isErr()) {
|
||||
aRv.ThrowDataError(result.unwrapErr());
|
||||
return;
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (!optresult.isNothing()) {
|
||||
dom::GleanRateData ret;
|
||||
auto pair = optresult.extract();
|
||||
ret.mNumerator = pair.first;
|
||||
ret.mDenominator = pair.second;
|
||||
aResult.SetValue(std::move(ret));
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
// Build return value of the form: { numerator: n, denominator: d }
|
||||
JS::Rooted<JSObject*> root(aCx, JS_NewPlainObject(aCx));
|
||||
if (!root) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
auto pair = optresult.extract();
|
||||
int32_t num = pair.first;
|
||||
int32_t den = pair.second;
|
||||
if (!JS_DefineProperty(aCx, root, "numerator", static_cast<double>(num),
|
||||
JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
if (!JS_DefineProperty(aCx, root, "denominator", static_cast<double>(den),
|
||||
JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
aResult.setObject(*root);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla::glean
|
||||
|
@ -7,16 +7,11 @@
|
||||
#ifndef mozilla_glean_GleanRate_h
|
||||
#define mozilla_glean_GleanRate_h
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/glean/bindings/GleanMetric.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsString.h"
|
||||
|
||||
namespace mozilla::dom {
|
||||
struct GleanRateData;
|
||||
} // namespace mozilla::dom
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
namespace impl {
|
||||
@ -64,20 +59,12 @@ class RateMetric {
|
||||
};
|
||||
} // namespace impl
|
||||
|
||||
class GleanRate final : public GleanMetric {
|
||||
class GleanRate final : public nsIGleanRate {
|
||||
public:
|
||||
explicit GleanRate(uint32_t id, nsISupports* aParent)
|
||||
: GleanMetric(aParent), mRate(id) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGLEANRATE
|
||||
|
||||
virtual JSObject* WrapObject(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final;
|
||||
|
||||
void AddToNumerator(int32_t aAmount);
|
||||
void AddToDenominator(int32_t aAmount);
|
||||
|
||||
void TestGetValue(const nsACString& aPingName,
|
||||
dom::Nullable<dom::GleanRateData>& aResult,
|
||||
ErrorResult& aRv);
|
||||
explicit GleanRate(uint32_t id) : mRate(id){};
|
||||
|
||||
private:
|
||||
virtual ~GleanRate() = default;
|
||||
|
@ -6,14 +6,15 @@
|
||||
|
||||
#include "mozilla/glean/bindings/String.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include "jsapi.h"
|
||||
#include "js/String.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/dom/GleanMetricsBinding.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
@ -43,33 +44,34 @@ Result<Maybe<nsCString>, nsCString> StringMetric::TestGetValue(
|
||||
|
||||
} // namespace impl
|
||||
|
||||
/* virtual */
|
||||
JSObject* GleanString::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
return dom::GleanString_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
NS_IMPL_CLASSINFO(GleanString, nullptr, 0, {0})
|
||||
NS_IMPL_ISUPPORTS_CI(GleanString, nsIGleanString)
|
||||
|
||||
void GleanString::Set(const nsACString& aValue) {
|
||||
if (aValue.IsVoid()) {
|
||||
// TODO: Instrument this error (bug 1691073)
|
||||
return;
|
||||
}
|
||||
NS_IMETHODIMP
|
||||
GleanString::Set(const nsACString& aValue) {
|
||||
mString.Set(aValue);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanString::TestGetValue(const nsACString& aPingName, nsCString& aResult,
|
||||
ErrorResult& aRv) {
|
||||
auto result = mString.TestGetValue(aPingName);
|
||||
NS_IMETHODIMP
|
||||
GleanString::TestGetValue(const nsACString& aStorageName, JSContext* aCx,
|
||||
JS::MutableHandle<JS::Value> aResult) {
|
||||
auto result = mString.TestGetValue(aStorageName);
|
||||
if (result.isErr()) {
|
||||
aRv.ThrowDataError(result.unwrapErr());
|
||||
return;
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (!optresult.isNothing()) {
|
||||
aResult.Assign(optresult.extract());
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
aResult.SetIsVoid(true);
|
||||
const NS_ConvertUTF8toUTF16 str(optresult.ref());
|
||||
aResult.set(
|
||||
JS::StringValue(JS_NewUCStringCopyN(aCx, str.Data(), str.Length())));
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla::glean
|
||||
|
@ -7,10 +7,9 @@
|
||||
#ifndef mozilla_glean_GleanString_h
|
||||
#define mozilla_glean_GleanString_h
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/glean/bindings/GleanMetric.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsString.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
@ -56,22 +55,16 @@ class StringMetric {
|
||||
};
|
||||
} // namespace impl
|
||||
|
||||
class GleanString final : public GleanMetric {
|
||||
class GleanString final : public nsIGleanString {
|
||||
public:
|
||||
explicit GleanString(uint32_t aId, nsISupports* aParent)
|
||||
: GleanMetric(aParent), mString(aId) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGLEANSTRING
|
||||
|
||||
virtual JSObject* WrapObject(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final;
|
||||
|
||||
void Set(const nsACString& aValue);
|
||||
|
||||
void TestGetValue(const nsACString& aPingName, nsCString& aResult,
|
||||
ErrorResult& aRv);
|
||||
|
||||
virtual ~GleanString() = default;
|
||||
explicit GleanString(uint32_t aId) : mString(aId){};
|
||||
|
||||
private:
|
||||
virtual ~GleanString() = default;
|
||||
|
||||
const impl::StringMetric mString;
|
||||
};
|
||||
|
||||
|
@ -6,11 +6,13 @@
|
||||
|
||||
#include "mozilla/glean/bindings/StringList.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/dom/ToJSValue.h"
|
||||
#include "mozilla/dom/GleanMetricsBinding.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
#include "nsString.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
@ -51,30 +53,40 @@ Result<Maybe<nsTArray<nsCString>>, nsCString> StringListMetric::TestGetValue(
|
||||
|
||||
} // namespace impl
|
||||
|
||||
/* virtual */
|
||||
JSObject* GleanStringList::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
return dom::GleanStringList_Binding::Wrap(aCx, this, aGivenProto);
|
||||
NS_IMPL_CLASSINFO(GleanStringList, nullptr, 0, {0})
|
||||
NS_IMPL_ISUPPORTS_CI(GleanStringList, nsIGleanStringList)
|
||||
|
||||
NS_IMETHODIMP
|
||||
GleanStringList::Add(const nsACString& aValue) {
|
||||
mStringList.Add(aValue);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanStringList::Add(const nsACString& aValue) { mStringList.Add(aValue); }
|
||||
|
||||
void GleanStringList::Set(const dom::Sequence<nsCString>& aValue) {
|
||||
NS_IMETHODIMP
|
||||
GleanStringList::Set(const nsTArray<nsCString>& aValue) {
|
||||
mStringList.Set(aValue);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanStringList::TestGetValue(const nsACString& aPingName,
|
||||
dom::Nullable<nsTArray<nsCString>>& aResult,
|
||||
ErrorResult& aRv) {
|
||||
auto result = mStringList.TestGetValue(aPingName);
|
||||
NS_IMETHODIMP
|
||||
GleanStringList::TestGetValue(const nsACString& aStorageName, JSContext* aCx,
|
||||
JS::MutableHandle<JS::Value> aResult) {
|
||||
auto result = mStringList.TestGetValue(aStorageName);
|
||||
if (result.isErr()) {
|
||||
aRv.ThrowDataError(result.unwrapErr());
|
||||
return;
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (!optresult.isNothing()) {
|
||||
aResult.SetValue(optresult.extract());
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
if (!dom::ToJSValue(aCx, optresult.ref(), aResult)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla::glean
|
||||
|
@ -8,8 +8,7 @@
|
||||
#define mozilla_glean_GleanStringList_h
|
||||
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/glean/bindings/GleanMetric.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsString.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
@ -67,20 +66,12 @@ class StringListMetric {
|
||||
};
|
||||
} // namespace impl
|
||||
|
||||
class GleanStringList final : public GleanMetric {
|
||||
class GleanStringList final : public nsIGleanStringList {
|
||||
public:
|
||||
explicit GleanStringList(uint32_t aId, nsISupports* aParent)
|
||||
: GleanMetric(aParent), mStringList(aId) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGLEANSTRINGLIST
|
||||
|
||||
virtual JSObject* WrapObject(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final;
|
||||
|
||||
void Add(const nsACString& aValue);
|
||||
void Set(const dom::Sequence<nsCString>& aValue);
|
||||
|
||||
void TestGetValue(const nsACString& aPingName,
|
||||
dom::Nullable<nsTArray<nsCString>>& aResult,
|
||||
ErrorResult& aRv);
|
||||
explicit GleanStringList(uint32_t aId) : mStringList(aId){};
|
||||
|
||||
private:
|
||||
virtual ~GleanStringList() = default;
|
||||
|
@ -6,13 +6,15 @@
|
||||
|
||||
#include "mozilla/glean/bindings/Text.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include "jsapi.h"
|
||||
#include "js/String.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/dom/GleanMetricsBinding.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
@ -38,27 +40,33 @@ Result<Maybe<nsCString>, nsCString> TextMetric::TestGetValue(
|
||||
|
||||
} // namespace impl
|
||||
|
||||
/* virtual */
|
||||
JSObject* GleanText::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
return dom::GleanText_Binding::Wrap(aCx, this, aGivenProto);
|
||||
NS_IMPL_CLASSINFO(GleanText, nullptr, 0, {0})
|
||||
NS_IMPL_ISUPPORTS_CI(GleanText, nsIGleanText)
|
||||
|
||||
NS_IMETHODIMP
|
||||
GleanText::Set(const nsACString& aValue) {
|
||||
mText.Set(aValue);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanText::Set(const nsACString& aValue) { mText.Set(aValue); }
|
||||
|
||||
void GleanText::TestGetValue(const nsACString& aPingName, nsCString& aResult,
|
||||
ErrorResult& aRv) {
|
||||
auto result = mText.TestGetValue(aPingName);
|
||||
NS_IMETHODIMP
|
||||
GleanText::TestGetValue(const nsACString& aStorageName, JSContext* aCx,
|
||||
JS::MutableHandle<JS::Value> aResult) {
|
||||
auto result = mText.TestGetValue(aStorageName);
|
||||
if (result.isErr()) {
|
||||
aRv.ThrowDataError(result.unwrapErr());
|
||||
return;
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (!optresult.isNothing()) {
|
||||
aResult.Assign(optresult.extract());
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
aResult.SetIsVoid(true);
|
||||
const NS_ConvertUTF8toUTF16 str(optresult.ref());
|
||||
aResult.set(
|
||||
JS::StringValue(JS_NewUCStringCopyN(aCx, str.Data(), str.Length())));
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla::glean
|
||||
|
@ -7,10 +7,9 @@
|
||||
#ifndef mozilla_glean_GleanText_h
|
||||
#define mozilla_glean_GleanText_h
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/glean/bindings/GleanMetric.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsString.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
@ -32,18 +31,12 @@ class TextMetric {
|
||||
|
||||
} // namespace impl
|
||||
|
||||
class GleanText final : public GleanMetric {
|
||||
class GleanText final : public nsIGleanText {
|
||||
public:
|
||||
explicit GleanText(uint32_t aId, nsISupports* aParent)
|
||||
: GleanMetric(aParent), mText(aId) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGLEANTEXT
|
||||
|
||||
virtual JSObject* WrapObject(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final;
|
||||
|
||||
void Set(const nsACString& aValue);
|
||||
|
||||
void TestGetValue(const nsACString& aPingName, nsCString& aResult,
|
||||
ErrorResult& aRv);
|
||||
explicit GleanText(uint32_t aId) : mText(aId){};
|
||||
|
||||
private:
|
||||
virtual ~GleanText() = default;
|
||||
|
@ -6,12 +6,13 @@
|
||||
|
||||
#include "mozilla/glean/bindings/Timespan.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/dom/GleanMetricsBinding.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
@ -83,33 +84,50 @@ Result<Maybe<uint64_t>, nsCString> TimespanMetric::TestGetValue(
|
||||
|
||||
} // namespace impl
|
||||
|
||||
/* virtual */
|
||||
JSObject* GleanTimespan::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
return dom::GleanTimespan_Binding::Wrap(aCx, this, aGivenProto);
|
||||
NS_IMPL_CLASSINFO(GleanTimespan, nullptr, 0, {0})
|
||||
NS_IMPL_ISUPPORTS_CI(GleanTimespan, nsIGleanTimespan)
|
||||
|
||||
NS_IMETHODIMP
|
||||
GleanTimespan::Start() {
|
||||
mTimespan.Start();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanTimespan::Start() { mTimespan.Start(); }
|
||||
NS_IMETHODIMP
|
||||
GleanTimespan::Stop() {
|
||||
mTimespan.Stop();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanTimespan::Stop() { mTimespan.Stop(); }
|
||||
NS_IMETHODIMP
|
||||
GleanTimespan::Cancel() {
|
||||
mTimespan.Cancel();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanTimespan::Cancel() { mTimespan.Cancel(); }
|
||||
NS_IMETHODIMP
|
||||
GleanTimespan::SetRaw(uint32_t aDuration) {
|
||||
mTimespan.SetRaw(aDuration);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanTimespan::SetRaw(uint32_t aDuration) { mTimespan.SetRaw(aDuration); }
|
||||
|
||||
dom::Nullable<uint64_t> GleanTimespan::TestGetValue(const nsACString& aPingName,
|
||||
ErrorResult& aRv) {
|
||||
dom::Nullable<uint64_t> ret;
|
||||
auto result = mTimespan.TestGetValue(aPingName);
|
||||
NS_IMETHODIMP
|
||||
GleanTimespan::TestGetValue(const nsACString& aStorageName,
|
||||
JS::MutableHandle<JS::Value> aResult) {
|
||||
auto result = mTimespan.TestGetValue(aStorageName);
|
||||
if (result.isErr()) {
|
||||
aRv.ThrowDataError(result.unwrapErr());
|
||||
return ret;
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (!optresult.isNothing()) {
|
||||
ret.SetValue(optresult.value());
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
aResult.set(JS::DoubleValue(static_cast<double>(optresult.value())));
|
||||
}
|
||||
return ret;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla::glean
|
||||
|
@ -9,8 +9,7 @@
|
||||
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/glean/bindings/GleanMetric.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsTString.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
@ -83,21 +82,12 @@ class TimespanMetric {
|
||||
};
|
||||
} // namespace impl
|
||||
|
||||
class GleanTimespan final : public GleanMetric {
|
||||
class GleanTimespan final : public nsIGleanTimespan {
|
||||
public:
|
||||
explicit GleanTimespan(uint32_t aId, nsISupports* aParent)
|
||||
: GleanMetric(aParent), mTimespan(aId) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGLEANTIMESPAN
|
||||
|
||||
virtual JSObject* WrapObject(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final;
|
||||
|
||||
void Start();
|
||||
void Stop();
|
||||
void Cancel();
|
||||
void SetRaw(uint32_t aDuration);
|
||||
|
||||
dom::Nullable<uint64_t> TestGetValue(const nsACString& aPingName,
|
||||
ErrorResult& aRv);
|
||||
explicit GleanTimespan(uint32_t aId) : mTimespan(aId){};
|
||||
|
||||
private:
|
||||
virtual ~GleanTimespan() = default;
|
||||
|
@ -6,11 +6,14 @@
|
||||
|
||||
#include "mozilla/glean/bindings/TimingDistribution.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/dom/GleanMetricsBinding.h"
|
||||
|
||||
#include "mozilla/dom/ToJSValue.h"
|
||||
#include "mozilla/glean/bindings/HistogramGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
#include "nsJSUtils.h"
|
||||
#include "nsPrintfCString.h"
|
||||
#include "nsString.h"
|
||||
@ -113,49 +116,80 @@ TimingDistributionMetric::TestGetValue(const nsACString& aPingName) const {
|
||||
|
||||
} // namespace impl
|
||||
|
||||
/* virtual */
|
||||
JSObject* GleanTimingDistribution::WrapObject(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
|
||||
return dom::GleanTimingDistribution_Binding::Wrap(aCx, this, aGivenProto);
|
||||
NS_IMPL_CLASSINFO(GleanTimingDistribution, nullptr, 0, {0})
|
||||
NS_IMPL_ISUPPORTS_CI(GleanTimingDistribution, nsIGleanTimingDistribution)
|
||||
|
||||
NS_IMETHODIMP
|
||||
GleanTimingDistribution::Start(JSContext* aCx,
|
||||
JS::MutableHandle<JS::Value> aResult) {
|
||||
if (!dom::ToJSValue(aCx, mTimingDist.Start(), aResult)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
uint64_t GleanTimingDistribution::Start() { return mTimingDist.Start(); }
|
||||
|
||||
void GleanTimingDistribution::StopAndAccumulate(uint64_t aId) {
|
||||
NS_IMETHODIMP
|
||||
GleanTimingDistribution::StopAndAccumulate(uint64_t aId) {
|
||||
mTimingDist.StopAndAccumulate(std::move(aId));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanTimingDistribution::Cancel(uint64_t aId) {
|
||||
NS_IMETHODIMP
|
||||
GleanTimingDistribution::Cancel(uint64_t aId) {
|
||||
mTimingDist.Cancel(std::move(aId));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanTimingDistribution::TestGetValue(
|
||||
const nsACString& aPingName,
|
||||
dom::Nullable<dom::GleanDistributionData>& aRetval, ErrorResult& aRv) {
|
||||
NS_IMETHODIMP
|
||||
GleanTimingDistribution::TestGetValue(const nsACString& aPingName,
|
||||
JSContext* aCx,
|
||||
JS::MutableHandle<JS::Value> aResult) {
|
||||
auto result = mTimingDist.TestGetValue(aPingName);
|
||||
if (result.isErr()) {
|
||||
aRv.ThrowDataError(result.unwrapErr());
|
||||
return;
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (optresult.isNothing()) {
|
||||
return;
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
// Build return value of the form: { sum: #, values: {bucket1: count1,
|
||||
// ...}
|
||||
JS::Rooted<JSObject*> root(aCx, JS_NewPlainObject(aCx));
|
||||
if (!root) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
uint64_t sum = optresult.ref().sum;
|
||||
if (!JS_DefineProperty(aCx, root, "sum", static_cast<double>(sum),
|
||||
JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JS::Rooted<JSObject*> valuesObj(aCx, JS_NewPlainObject(aCx));
|
||||
if (!valuesObj ||
|
||||
!JS_DefineProperty(aCx, root, "values", valuesObj, JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
dom::GleanDistributionData ret;
|
||||
ret.mSum = optresult.ref().sum;
|
||||
auto& data = optresult.ref().values;
|
||||
for (const auto& entry : data) {
|
||||
dom::binding_detail::RecordEntry<nsCString, uint64_t> bucket;
|
||||
bucket.mKey = nsPrintfCString("%" PRIu64, entry.GetKey());
|
||||
bucket.mValue = entry.GetData();
|
||||
ret.mValues.Entries().EmplaceBack(std::move(bucket));
|
||||
const uint64_t bucket = entry.GetKey();
|
||||
const uint64_t count = entry.GetData();
|
||||
if (!JS_DefineProperty(aCx, valuesObj,
|
||||
nsPrintfCString("%" PRIu64, bucket).get(),
|
||||
static_cast<double>(count), JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
aRetval.SetValue(std::move(ret));
|
||||
}
|
||||
aResult.setObject(*root);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanTimingDistribution::TestAccumulateRawMillis(uint64_t aSample) {
|
||||
NS_IMETHODIMP
|
||||
GleanTimingDistribution::TestAccumulateRawMillis(uint64_t aSample) {
|
||||
mTimingDist.AccumulateRawDuration(TimeDuration::FromMilliseconds(aSample));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla::glean
|
||||
|
@ -7,17 +7,13 @@
|
||||
#ifndef mozilla_glean_GleanTimingDistribution_h
|
||||
#define mozilla_glean_GleanTimingDistribution_h
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/glean/bindings/DistributionData.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
namespace mozilla::dom {
|
||||
struct GleanDistributionData;
|
||||
} // namespace mozilla::dom
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
typedef uint64_t TimerId;
|
||||
@ -95,23 +91,12 @@ class TimingDistributionMetric {
|
||||
};
|
||||
} // namespace impl
|
||||
|
||||
class GleanTimingDistribution final : public GleanMetric {
|
||||
class GleanTimingDistribution final : public nsIGleanTimingDistribution {
|
||||
public:
|
||||
explicit GleanTimingDistribution(uint64_t aId, nsISupports* aParent)
|
||||
: GleanMetric(aParent), mTimingDist(aId) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGLEANTIMINGDISTRIBUTION
|
||||
|
||||
virtual JSObject* WrapObject(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final;
|
||||
|
||||
uint64_t Start();
|
||||
void StopAndAccumulate(uint64_t aId);
|
||||
void Cancel(uint64_t aId);
|
||||
|
||||
void TestGetValue(const nsACString& aPingName,
|
||||
dom::Nullable<dom::GleanDistributionData>& aRetval,
|
||||
ErrorResult& aRv);
|
||||
|
||||
void TestAccumulateRawMillis(uint64_t aSample);
|
||||
explicit GleanTimingDistribution(uint64_t aId) : mTimingDist(aId){};
|
||||
|
||||
private:
|
||||
virtual ~GleanTimingDistribution() = default;
|
||||
|
@ -6,13 +6,15 @@
|
||||
|
||||
#include "mozilla/glean/bindings/Url.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include "jsapi.h"
|
||||
#include "js/String.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/dom/GleanMetricsBinding.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
@ -42,27 +44,34 @@ Result<Maybe<nsCString>, nsCString> UrlMetric::TestGetValue(
|
||||
|
||||
} // namespace impl
|
||||
|
||||
/* virtual */
|
||||
JSObject* GleanUrl::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
return dom::GleanUrl_Binding::Wrap(aCx, this, aGivenProto);
|
||||
NS_IMPL_CLASSINFO(GleanUrl, nullptr, 0, {0})
|
||||
NS_IMPL_ISUPPORTS_CI(GleanUrl, nsIGleanUrl)
|
||||
|
||||
NS_IMETHODIMP
|
||||
GleanUrl::Set(const nsACString& aValue) {
|
||||
mUrl.Set(aValue);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanUrl::Set(const nsACString& aValue) { mUrl.Set(aValue); }
|
||||
|
||||
void GleanUrl::TestGetValue(const nsACString& aPingName, nsCString& aResult,
|
||||
ErrorResult& aRv) {
|
||||
auto result = mUrl.TestGetValue(aPingName);
|
||||
NS_IMETHODIMP
|
||||
GleanUrl::TestGetValue(const nsACString& aStorageName, JSContext* aCx,
|
||||
JS::MutableHandle<JS::Value> aResult) {
|
||||
auto result = mUrl.TestGetValue(aStorageName);
|
||||
if (result.isErr()) {
|
||||
aRv.ThrowDataError(result.unwrapErr());
|
||||
return;
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (!optresult.isNothing()) {
|
||||
aResult.Assign(optresult.extract());
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
aResult.SetIsVoid(true);
|
||||
const NS_ConvertUTF8toUTF16 str(optresult.ref());
|
||||
aResult.set(
|
||||
JS::StringValue(JS_NewUCStringCopyN(aCx, str.Data(), str.Length())));
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla::glean
|
||||
|
@ -7,9 +7,9 @@
|
||||
#ifndef mozilla_glean_GleanUrl_h
|
||||
#define mozilla_glean_GleanUrl_h
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsString.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
@ -52,18 +52,12 @@ class UrlMetric {
|
||||
};
|
||||
} // namespace impl
|
||||
|
||||
class GleanUrl final : public GleanMetric {
|
||||
class GleanUrl final : public nsIGleanUrl {
|
||||
public:
|
||||
explicit GleanUrl(uint32_t aId, nsISupports* aParent)
|
||||
: GleanMetric(aParent), mUrl(aId) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGLEANURL
|
||||
|
||||
virtual JSObject* WrapObject(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final;
|
||||
|
||||
void Set(const nsACString& aValue);
|
||||
|
||||
void TestGetValue(const nsACString& aPingName, nsCString& aResult,
|
||||
ErrorResult& aRv);
|
||||
explicit GleanUrl(uint32_t aId) : mUrl(aId){};
|
||||
|
||||
private:
|
||||
virtual ~GleanUrl() = default;
|
||||
|
@ -6,11 +6,13 @@
|
||||
|
||||
#include "mozilla/glean/bindings/Uuid.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include "jsapi.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/dom/GleanMetricsBinding.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
#include "nsString.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
@ -48,29 +50,40 @@ Result<Maybe<nsCString>, nsCString> UuidMetric::TestGetValue(
|
||||
|
||||
} // namespace impl
|
||||
|
||||
/* virtual */
|
||||
JSObject* GleanUuid::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
return dom::GleanUuid_Binding::Wrap(aCx, this, aGivenProto);
|
||||
NS_IMPL_CLASSINFO(GleanUuid, nullptr, 0, {0})
|
||||
NS_IMPL_ISUPPORTS_CI(GleanUuid, nsIGleanUuid)
|
||||
|
||||
NS_IMETHODIMP
|
||||
GleanUuid::Set(const nsACString& aValue) {
|
||||
mUuid.Set(aValue);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanUuid::Set(const nsACString& aValue) { mUuid.Set(aValue); }
|
||||
NS_IMETHODIMP
|
||||
GleanUuid::GenerateAndSet() {
|
||||
mUuid.GenerateAndSet();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void GleanUuid::GenerateAndSet() { mUuid.GenerateAndSet(); }
|
||||
|
||||
void GleanUuid::TestGetValue(const nsACString& aPingName, nsCString& aResult,
|
||||
ErrorResult& aRv) {
|
||||
auto result = mUuid.TestGetValue(aPingName);
|
||||
NS_IMETHODIMP
|
||||
GleanUuid::TestGetValue(const nsACString& aStorageName, JSContext* aCx,
|
||||
JS::MutableHandle<JS::Value> aResult) {
|
||||
auto result = mUuid.TestGetValue(aStorageName);
|
||||
if (result.isErr()) {
|
||||
aRv.ThrowDataError(result.unwrapErr());
|
||||
return;
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (!optresult.isNothing()) {
|
||||
aResult.Assign(optresult.extract());
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
aResult.SetIsVoid(true);
|
||||
const NS_ConvertUTF8toUTF16 str(optresult.value());
|
||||
aResult.set(
|
||||
JS::StringValue(JS_NewUCStringCopyN(aCx, str.Data(), str.Length())));
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla::glean
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsString.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
@ -57,19 +57,12 @@ class UuidMetric {
|
||||
};
|
||||
} // namespace impl
|
||||
|
||||
class GleanUuid final : public GleanMetric {
|
||||
class GleanUuid final : public nsIGleanUuid {
|
||||
public:
|
||||
explicit GleanUuid(uint32_t aId, nsISupports* aParent)
|
||||
: GleanMetric(aParent), mUuid(aId) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGLEANUUID
|
||||
|
||||
virtual JSObject* WrapObject(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final;
|
||||
|
||||
void Set(const nsACString& aValue);
|
||||
void GenerateAndSet();
|
||||
|
||||
void TestGetValue(const nsACString& aPingName, nsCString& aResult,
|
||||
ErrorResult& aRv);
|
||||
explicit GleanUuid(uint32_t aId) : mUuid(aId){};
|
||||
|
||||
private:
|
||||
virtual ~GleanUuid() = default;
|
||||
|
@ -44,7 +44,7 @@ static_assert({{ categories|length }} < UINT32_MAX, "Too many metric categories
|
||||
static_assert({{ metric_id_mapping|length }} < {{2 ** (id_bits - id_signal_bits)}}, "Too many metrics generated. Need room for {{id_signal_bits}} signal bits.");
|
||||
static_assert({{ metric_type_ids|length }} < {{2 ** type_bits}}, "Too many different metric types.");
|
||||
|
||||
already_AddRefed<GleanMetric> NewMetricFromId(uint32_t id, nsISupports* aParent) {
|
||||
already_AddRefed<nsISupports> NewMetricFromId(uint32_t id) {
|
||||
uint32_t typeId = GLEAN_TYPE_ID(id);
|
||||
uint32_t metricId = GLEAN_METRIC_ID(id);
|
||||
|
||||
@ -52,7 +52,7 @@ already_AddRefed<GleanMetric> NewMetricFromId(uint32_t id, nsISupports* aParent)
|
||||
{% for (type_name, subtype_name), (type_id, original_type) in metric_type_ids.items() %}
|
||||
case {{ type_id }}: /* {{ original_type }} */
|
||||
{
|
||||
return MakeAndAddRef<{{type_name}}>(metricId{% if subtype_name|length > 0 %}, {{ type_id }}{% endif %}, aParent);
|
||||
return MakeAndAddRef<{{type_name}}>(metricId{% if subtype_name|length > 0 %}, {{ type_id }}{% endif %});
|
||||
}
|
||||
{% endfor %}
|
||||
default:
|
||||
@ -72,19 +72,14 @@ already_AddRefed<GleanMetric> NewMetricFromId(uint32_t id, nsISupports* aParent)
|
||||
* @param aSubmetricId - an outparam which is assigned the submetric's SDK-generated submetric id.
|
||||
* Used only by GIFFT.
|
||||
*/
|
||||
already_AddRefed<GleanMetric> NewSubMetricFromIds(uint32_t aParentTypeId,
|
||||
uint32_t aParentMetricId,
|
||||
const nsACString& aLabel,
|
||||
uint32_t* aSubmetricId,
|
||||
nsISupports* aParent) {
|
||||
already_AddRefed<nsISupports> NewSubMetricFromIds(uint32_t aParentTypeId, uint32_t aParentMetricId, const nsACString& aLabel, uint32_t* aSubmetricId) {
|
||||
switch (aParentTypeId) {
|
||||
{% for (type_name, subtype_name), (type_id, original_type) in metric_type_ids.items() %}
|
||||
{# TODO: Remove the subtype inclusion clause when we suport the rest of labeled_* #}
|
||||
{% if subtype_name|length > 0 and original_type in ['labeled_boolean', 'labeled_counter', 'labeled_string'] %}
|
||||
{% if subtype_name|length > 0 %}
|
||||
case {{ type_id }}: { /* {{ original_type }} */
|
||||
auto id = impl::fog_{{original_type}}_get(aParentMetricId, &aLabel);
|
||||
*aSubmetricId = id;
|
||||
return MakeAndAddRef<{{subtype_name}}>(id, aParent);
|
||||
return MakeAndAddRef<{{subtype_name}}>(id);
|
||||
}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
@ -15,7 +15,6 @@ Jinja2 template is not. Please file bugs! #}
|
||||
|
||||
#include "mozilla/AlreadyAddRefed.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/glean/bindings/GleanMetric.h"
|
||||
#include "nsStringFwd.h"
|
||||
|
||||
class nsISupports;
|
||||
@ -35,7 +34,7 @@ using category_entry_t = uint32_t;
|
||||
// characteristics (which hopefully will prove to be enough).
|
||||
using metric_entry_t = uint64_t;
|
||||
|
||||
already_AddRefed<GleanMetric> NewMetricFromId(uint32_t id, nsISupports* aParent);
|
||||
already_AddRefed<nsISupports> NewMetricFromId(uint32_t id);
|
||||
|
||||
/**
|
||||
* Create a submetric instance for a labeled metric of the provided type and id for the given label.
|
||||
@ -48,7 +47,7 @@ already_AddRefed<GleanMetric> NewMetricFromId(uint32_t id, nsISupports* aParent)
|
||||
* @param aSubmetricId - an outparam which is assigned the submetric's SDK-generated submetric id.
|
||||
* Used only by GIFFT.
|
||||
*/
|
||||
already_AddRefed<GleanMetric> NewSubMetricFromIds(uint32_t aParentTypeId, uint32_t aParentMetricId, const nsACString& aLabel, uint32_t* aSubmetricId, nsISupports* aParent);
|
||||
already_AddRefed<nsISupports> NewSubMetricFromIds(uint32_t aParentTypeId, uint32_t aParentMetricId, const nsACString& aLabel, uint32_t* aSubmetricId);
|
||||
|
||||
/**
|
||||
* Get a category's name from the string table.
|
||||
|
@ -29,7 +29,7 @@ Put another way, what shape of storage will this take up in the
|
||||
and send a stream of high-precision samples across IPC.
|
||||
|
||||
To implement IPC support in a metric type,
|
||||
we split FOG's Rust implementation of the metric into three pieces:
|
||||
we split the metric into three pieces:
|
||||
1. An umbrella `enum` with the name `MetricTypeMetric`.
|
||||
* It has a `Child` and a `Parent` variant.
|
||||
* It is IPC-aware and is responsible for
|
||||
@ -160,27 +160,32 @@ Each metric type has six pieces you'll need to cover:
|
||||
### 3. IDL
|
||||
|
||||
- Duplicate the public API (including its docs) to
|
||||
{searchfox}`dom/webidl/GleanMetrics.webidl`
|
||||
with the name `GleanX` (e.g. `GleanCounter`).
|
||||
- Inherit from `GleanMetric`.
|
||||
- The naming style for methods here is `lowerCamelCase`.
|
||||
- If the metric method is a reserved word, prepend it with a `_`.
|
||||
- Web IDL bindings use
|
||||
[their own mapping for types](/dom/webIdlBindings/index.html)
|
||||
If you choose ones that most closely resemble the C++ types,
|
||||
you'll make your life easier.
|
||||
[`xpcom/nsIGleanMetrics.idl`](https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/glean/xpcom/nsIGleanMetrics.idl)
|
||||
with the name `nsIGleanX` (e.g. `nsIGleanCounter`).
|
||||
- Inherit from `nsISupports`.
|
||||
- The naming style for members here is `lowerCamelCase`.
|
||||
You'll need a
|
||||
[GUID](https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Generating_GUIDs)
|
||||
because this is XPCOM, but you'll only need the canonical form since we're only exposing to JS.
|
||||
- The `testGetValue` method will return a
|
||||
`jsval` to permit it to return `undefined` when there is no value.
|
||||
|
||||
### 4. JS Impl
|
||||
|
||||
- Implement the `GleanX` (e.g. `GleanCounter`) type
|
||||
in the same header and `.cpp` as `XMetric` in
|
||||
{searchfox}`toolkit/components/glean/bindings/private/`
|
||||
- It should own an instance of and delegate method implementations to `XMetric`.
|
||||
- Add an `nsIGleanX`-deriving, `XMetric`-owning type called
|
||||
`GleanX` (e.g. `GleanCounter`) in the same header and `.cpp` as `XMetric` in
|
||||
[`bindings/private/`](https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/glean/bindings/private/).
|
||||
- Don't declare any methods beyond a ctor
|
||||
(takes a `uint32_t` metric id, init-constructs a `impl::XMetric` member)
|
||||
and dtor (`default`): the IDL will do the rest so long as you remember to add
|
||||
`NS_DECL_ISUPPORTS` and `NS_DECL_NSIGLEANX`.
|
||||
- In the definition of `GleanX`, member identifiers are back to
|
||||
`CamelCase`.
|
||||
- Test-only methods can throw `DataError` on failure.
|
||||
- Review the [Web IDL Bindings documentation](/dom/webIdlBindings/index.html)
|
||||
for help with optional, nullable, and non-primitive types.
|
||||
`CamelCase` and need macros like `NS_IMETHODIMP`.
|
||||
Delegate operations to the owned `XMetric`, returning
|
||||
`NS_OK` no matter what in non-test methods.
|
||||
- Test-only methods can return `NS_ERROR` codes on failures,
|
||||
but mostly return `NS_OK` and use `undefined` in the
|
||||
`JS::MutableHandleValue` result to signal no value.
|
||||
|
||||
### 6. Tests
|
||||
|
||||
@ -261,7 +266,7 @@ There are four pieces to this:
|
||||
|
||||
#### JS
|
||||
|
||||
- Already handled for you since the JS types all inherit from `GleanMetric`
|
||||
- Already handled for you since the JS types all inherit from `nsISupports`
|
||||
and the JS template knows to add your new type to `NewSubMetricFromIds(...)`
|
||||
(see `GleanLabeled::NamedGetter` if you're curious).
|
||||
|
||||
|
@ -28,7 +28,6 @@ EXPORTS.mozilla.glean.bindings += [
|
||||
"!ScalarGIFFTMap.h",
|
||||
"bindings/Category.h",
|
||||
"bindings/Glean.h",
|
||||
"bindings/GleanMetric.h",
|
||||
"bindings/GleanPings.h",
|
||||
"bindings/MetricTypes.h",
|
||||
"bindings/private/Boolean.h",
|
||||
@ -75,7 +74,6 @@ if CONFIG["COMPILE_ENVIRONMENT"]:
|
||||
UNIFIED_SOURCES += [
|
||||
"bindings/Category.cpp",
|
||||
"bindings/Glean.cpp",
|
||||
"bindings/GleanMetric.cpp",
|
||||
"bindings/GleanPings.cpp",
|
||||
"bindings/jog/JOG.cpp",
|
||||
"bindings/private/Boolean.cpp",
|
||||
|
@ -55,7 +55,7 @@ add_task(async () => {
|
||||
Services.fog.testResetFOG();
|
||||
|
||||
is(
|
||||
null,
|
||||
undefined,
|
||||
Glean.testOnlyIpc.aCounter.testGetValue(),
|
||||
"Ensure we begin without value."
|
||||
);
|
||||
|
@ -18,7 +18,7 @@ add_task(async () => {
|
||||
Services.fog.testResetFOG();
|
||||
|
||||
is(
|
||||
null,
|
||||
undefined,
|
||||
Glean.testOnlyIpc.aCounter.testGetValue(),
|
||||
"Ensure we begin without value."
|
||||
);
|
||||
|
@ -37,7 +37,7 @@ add_task(async () => {
|
||||
Services.fog.testResetFOG();
|
||||
|
||||
is(
|
||||
null,
|
||||
undefined,
|
||||
Glean.testOnlyIpc.aCounter.testGetValue(),
|
||||
"Ensure we begin without value."
|
||||
);
|
||||
|
@ -17,7 +17,7 @@ add_task(async () => {
|
||||
Services.fog.testResetFOG();
|
||||
|
||||
is(
|
||||
null,
|
||||
undefined,
|
||||
Glean.testOnlyIpc.aCounter.testGetValue(),
|
||||
"Ensure we begin without value."
|
||||
);
|
||||
|
@ -13,7 +13,7 @@ add_task(async () => {
|
||||
Services.fog.testResetFOG();
|
||||
|
||||
is(
|
||||
null,
|
||||
undefined,
|
||||
Glean.testOnlyIpc.aCounter.testGetValue(),
|
||||
"Ensure we begin without value."
|
||||
);
|
||||
|
@ -33,7 +33,7 @@ add_task(async () => {
|
||||
Glean.testOnlyIpc.aLabeledCounter["1".repeat(72)].add(3);
|
||||
Assert.throws(
|
||||
() => Glean.testOnlyIpc.aLabeledCounter.__other__.testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Can't get the value when you're error'd"
|
||||
);
|
||||
|
||||
|
@ -42,86 +42,86 @@ static_assert(2 < UINT32_MAX, "Too many metric categories generated.");
|
||||
static_assert(23 < 33554432, "Too many metrics generated. Need room for 2 signal bits.");
|
||||
static_assert(19 < 32, "Too many different metric types.");
|
||||
|
||||
already_AddRefed<GleanMetric> NewMetricFromId(uint32_t id, nsISupports* aParent) {
|
||||
already_AddRefed<nsISupports> NewMetricFromId(uint32_t id) {
|
||||
uint32_t typeId = GLEAN_TYPE_ID(id);
|
||||
uint32_t metricId = GLEAN_METRIC_ID(id);
|
||||
|
||||
switch (typeId) {
|
||||
case 1: /* boolean */
|
||||
{
|
||||
return MakeAndAddRef<GleanBoolean>(metricId, aParent);
|
||||
return MakeAndAddRef<GleanBoolean>(metricId);
|
||||
}
|
||||
case 2: /* counter */
|
||||
{
|
||||
return MakeAndAddRef<GleanCounter>(metricId, aParent);
|
||||
return MakeAndAddRef<GleanCounter>(metricId);
|
||||
}
|
||||
case 3: /* custom_distribution */
|
||||
{
|
||||
return MakeAndAddRef<GleanCustomDistribution>(metricId, aParent);
|
||||
return MakeAndAddRef<GleanCustomDistribution>(metricId);
|
||||
}
|
||||
case 4: /* labeled_boolean */
|
||||
{
|
||||
return MakeAndAddRef<GleanLabeled>(metricId, 4, aParent);
|
||||
return MakeAndAddRef<GleanLabeled>(metricId, 4);
|
||||
}
|
||||
case 5: /* labeled_counter */
|
||||
{
|
||||
return MakeAndAddRef<GleanLabeled>(metricId, 5, aParent);
|
||||
return MakeAndAddRef<GleanLabeled>(metricId, 5);
|
||||
}
|
||||
case 6: /* labeled_string */
|
||||
{
|
||||
return MakeAndAddRef<GleanLabeled>(metricId, 6, aParent);
|
||||
return MakeAndAddRef<GleanLabeled>(metricId, 6);
|
||||
}
|
||||
case 7: /* memory_distribution */
|
||||
{
|
||||
return MakeAndAddRef<GleanMemoryDistribution>(metricId, aParent);
|
||||
return MakeAndAddRef<GleanMemoryDistribution>(metricId);
|
||||
}
|
||||
case 8: /* string_list */
|
||||
{
|
||||
return MakeAndAddRef<GleanStringList>(metricId, aParent);
|
||||
return MakeAndAddRef<GleanStringList>(metricId);
|
||||
}
|
||||
case 9: /* string */
|
||||
{
|
||||
return MakeAndAddRef<GleanString>(metricId, aParent);
|
||||
return MakeAndAddRef<GleanString>(metricId);
|
||||
}
|
||||
case 10: /* text */
|
||||
{
|
||||
return MakeAndAddRef<GleanText>(metricId, aParent);
|
||||
return MakeAndAddRef<GleanText>(metricId);
|
||||
}
|
||||
case 11: /* timespan */
|
||||
{
|
||||
return MakeAndAddRef<GleanTimespan>(metricId, aParent);
|
||||
return MakeAndAddRef<GleanTimespan>(metricId);
|
||||
}
|
||||
case 12: /* timing_distribution */
|
||||
{
|
||||
return MakeAndAddRef<GleanTimingDistribution>(metricId, aParent);
|
||||
return MakeAndAddRef<GleanTimingDistribution>(metricId);
|
||||
}
|
||||
case 13: /* datetime */
|
||||
{
|
||||
return MakeAndAddRef<GleanDatetime>(metricId, aParent);
|
||||
return MakeAndAddRef<GleanDatetime>(metricId);
|
||||
}
|
||||
case 14: /* event */
|
||||
{
|
||||
return MakeAndAddRef<GleanEvent>(metricId, aParent);
|
||||
return MakeAndAddRef<GleanEvent>(metricId);
|
||||
}
|
||||
case 15: /* denominator */
|
||||
{
|
||||
return MakeAndAddRef<GleanDenominator>(metricId, aParent);
|
||||
return MakeAndAddRef<GleanDenominator>(metricId);
|
||||
}
|
||||
case 16: /* quantity */
|
||||
{
|
||||
return MakeAndAddRef<GleanQuantity>(metricId, aParent);
|
||||
return MakeAndAddRef<GleanQuantity>(metricId);
|
||||
}
|
||||
case 17: /* rate */
|
||||
{
|
||||
return MakeAndAddRef<GleanRate>(metricId, aParent);
|
||||
return MakeAndAddRef<GleanRate>(metricId);
|
||||
}
|
||||
case 18: /* numerator */
|
||||
{
|
||||
return MakeAndAddRef<GleanNumerator>(metricId, aParent);
|
||||
return MakeAndAddRef<GleanNumerator>(metricId);
|
||||
}
|
||||
case 19: /* uuid */
|
||||
{
|
||||
return MakeAndAddRef<GleanUuid>(metricId, aParent);
|
||||
return MakeAndAddRef<GleanUuid>(metricId);
|
||||
}
|
||||
default:
|
||||
MOZ_ASSERT_UNREACHABLE("Invalid type ID reached when trying to instantiate a new metric");
|
||||
@ -140,26 +140,22 @@ already_AddRefed<GleanMetric> NewMetricFromId(uint32_t id, nsISupports* aParent)
|
||||
* @param aSubmetricId - an outparam which is assigned the submetric's SDK-generated submetric id.
|
||||
* Used only by GIFFT.
|
||||
*/
|
||||
already_AddRefed<GleanMetric> NewSubMetricFromIds(uint32_t aParentTypeId,
|
||||
uint32_t aParentMetricId,
|
||||
const nsACString& aLabel,
|
||||
uint32_t* aSubmetricId,
|
||||
nsISupports* aParent) {
|
||||
already_AddRefed<nsISupports> NewSubMetricFromIds(uint32_t aParentTypeId, uint32_t aParentMetricId, const nsACString& aLabel, uint32_t* aSubmetricId) {
|
||||
switch (aParentTypeId) {
|
||||
case 4: { /* labeled_boolean */
|
||||
auto id = impl::fog_labeled_boolean_get(aParentMetricId, &aLabel);
|
||||
*aSubmetricId = id;
|
||||
return MakeAndAddRef<GleanBoolean>(id, aParent);
|
||||
return MakeAndAddRef<GleanBoolean>(id);
|
||||
}
|
||||
case 5: { /* labeled_counter */
|
||||
auto id = impl::fog_labeled_counter_get(aParentMetricId, &aLabel);
|
||||
*aSubmetricId = id;
|
||||
return MakeAndAddRef<GleanCounter>(id, aParent);
|
||||
return MakeAndAddRef<GleanCounter>(id);
|
||||
}
|
||||
case 6: { /* labeled_string */
|
||||
auto id = impl::fog_labeled_string_get(aParentMetricId, &aLabel);
|
||||
*aSubmetricId = id;
|
||||
return MakeAndAddRef<GleanString>(id, aParent);
|
||||
return MakeAndAddRef<GleanString>(id);
|
||||
}
|
||||
default: {
|
||||
MOZ_ASSERT_UNREACHABLE("Invalid type ID for submetric.");
|
||||
|
@ -13,7 +13,6 @@
|
||||
|
||||
#include "mozilla/AlreadyAddRefed.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/glean/bindings/GleanMetric.h"
|
||||
#include "nsStringFwd.h"
|
||||
|
||||
class nsISupports;
|
||||
@ -33,7 +32,7 @@ using category_entry_t = uint32_t;
|
||||
// characteristics (which hopefully will prove to be enough).
|
||||
using metric_entry_t = uint64_t;
|
||||
|
||||
already_AddRefed<GleanMetric> NewMetricFromId(uint32_t id, nsISupports* aParent);
|
||||
already_AddRefed<nsISupports> NewMetricFromId(uint32_t id);
|
||||
|
||||
/**
|
||||
* Create a submetric instance for a labeled metric of the provided type and id for the given label.
|
||||
@ -46,7 +45,7 @@ already_AddRefed<GleanMetric> NewMetricFromId(uint32_t id, nsISupports* aParent)
|
||||
* @param aSubmetricId - an outparam which is assigned the submetric's SDK-generated submetric id.
|
||||
* Used only by GIFFT.
|
||||
*/
|
||||
already_AddRefed<GleanMetric> NewSubMetricFromIds(uint32_t aParentTypeId, uint32_t aParentMetricId, const nsACString& aLabel, uint32_t* aSubmetricId, nsISupports* aParent);
|
||||
already_AddRefed<nsISupports> NewSubMetricFromIds(uint32_t aParentTypeId, uint32_t aParentMetricId, const nsACString& aLabel, uint32_t* aSubmetricId);
|
||||
|
||||
/**
|
||||
* Get a category's name from the string table.
|
||||
|
@ -117,7 +117,7 @@ add_task(function test_gifft_memory_dist() {
|
||||
Glean.testOnlyIpc.aMemoryDist.accumulate(Math.pow(2, 31));
|
||||
Assert.throws(
|
||||
() => Glean.testOnlyIpc.aMemoryDist.testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Did not accumulate correctly"
|
||||
);
|
||||
});
|
||||
@ -278,7 +278,7 @@ add_task(function test_gifft_labeled_counter() {
|
||||
Glean.testOnlyIpc.aLabeledCounter["1".repeat(72)].add(3);
|
||||
Assert.throws(
|
||||
() => Glean.testOnlyIpc.aLabeledCounter.__other__.testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Can't get the value when you're error'd"
|
||||
);
|
||||
|
||||
@ -345,7 +345,7 @@ add_task(async function test_gifft_labeled_boolean() {
|
||||
Glean.testOnly.mirrorsForLabeledBools["1".repeat(72)].set(true);
|
||||
Assert.throws(
|
||||
() => Glean.testOnly.mirrorsForLabeledBools.__other__.testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Should throw because of a recording error."
|
||||
);
|
||||
|
||||
@ -397,7 +397,7 @@ add_task(function test_gifft_numeric_limits() {
|
||||
// (chutten blames chutten for his shortsightedness)
|
||||
Assert.throws(
|
||||
() => Glean.testOnlyIpc.aCounter.testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Can't get the value when you're error'd"
|
||||
);
|
||||
Assert.equal(undefined, scalarValue("telemetry.test.mirror_for_counter"));
|
||||
@ -422,7 +422,7 @@ add_task(function test_gifft_numeric_limits() {
|
||||
// Glean will error on this.
|
||||
Assert.throws(
|
||||
() => Glean.testOnly.meaningOfLife.testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Can't get the value when you're error'd"
|
||||
);
|
||||
// GIFFT doesn't tell Telemetry about the weird value at all.
|
||||
@ -445,7 +445,7 @@ add_task(function test_gifft_numeric_limits() {
|
||||
Glean.testOnlyIpc.irate.addToDenominator(7);
|
||||
Assert.throws(
|
||||
() => Glean.testOnlyIpc.irate.testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Can't get the value when you're error'd"
|
||||
);
|
||||
Assert.deepEqual(
|
||||
@ -462,7 +462,7 @@ add_task(function test_gifft_numeric_limits() {
|
||||
Glean.testOnlyIpc.irate.addToDenominator(-7);
|
||||
Assert.throws(
|
||||
() => Glean.testOnlyIpc.irate.testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Can't get the value when you're error'd"
|
||||
);
|
||||
Assert.deepEqual(
|
||||
@ -488,7 +488,7 @@ add_task(function test_gifft_numeric_limits() {
|
||||
Glean.testOnlyIpc.aTimingDist.testAccumulateRawMillis(Math.pow(2, 32) + 1);
|
||||
Assert.throws(
|
||||
() => Glean.testOnlyIpc.aTimingDist.testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Can't get the value when you're error'd"
|
||||
);
|
||||
let snapshot = Telemetry.getHistogramById(
|
||||
|
@ -200,7 +200,7 @@ add_task(
|
||||
|
||||
Assert.throws(
|
||||
() => Glean.testOnlyIpc.anotherLabeledCounter.__other__.testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Invalid labels record errors, which throw"
|
||||
);
|
||||
|
||||
|
@ -33,12 +33,6 @@ add_task(function test_fog_counter_works() {
|
||||
});
|
||||
|
||||
add_task(async function test_fog_string_works() {
|
||||
Assert.equal(null, Glean.testOnly.cheesyString.testGetValue());
|
||||
|
||||
// Setting `undefined` will be ignored.
|
||||
Glean.testOnly.cheesyString.set(undefined);
|
||||
Assert.equal(null, Glean.testOnly.cheesyString.testGetValue());
|
||||
|
||||
const value = "a cheesy string!";
|
||||
Glean.testOnly.cheesyString.set(value);
|
||||
|
||||
@ -80,7 +74,7 @@ add_task(async function test_fog_timespan_throws_on_stop_wout_start() {
|
||||
Glean.testOnly.canWeTimeIt.stop();
|
||||
Assert.throws(
|
||||
() => Glean.testOnly.canWeTimeIt.testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Should throw because stop was called without start."
|
||||
);
|
||||
});
|
||||
@ -127,14 +121,6 @@ add_task(async function test_fog_event_works() {
|
||||
Assert.equal("an_event", events[0].name);
|
||||
Assert.deepEqual(extra, events[0].extra);
|
||||
|
||||
// Corner case: Event with extra with `undefined` value.
|
||||
// Should pretend that extra key isn't there.
|
||||
extra = { extra1: undefined, extra2: "defined" };
|
||||
Glean.testOnlyIpc.anEvent.record(extra);
|
||||
events = Glean.testOnlyIpc.anEvent.testGetValue();
|
||||
Assert.equal(2, events.length);
|
||||
Assert.deepEqual({ extra2: "defined" }, events[1].extra);
|
||||
|
||||
let extra2 = {
|
||||
extra1: "can set extras",
|
||||
extra2: 37,
|
||||
@ -152,6 +138,16 @@ add_task(async function test_fog_event_works() {
|
||||
};
|
||||
Assert.deepEqual(expectedExtra, events[0].extra);
|
||||
|
||||
// Quantities need to be non-negative.
|
||||
// This does not record a Glean error.
|
||||
let extra4 = {
|
||||
extra2: -1,
|
||||
};
|
||||
Glean.testOnlyIpc.eventWithExtra.record(extra4);
|
||||
events = Glean.testOnlyIpc.eventWithExtra.testGetValue();
|
||||
// Unchanged number of events
|
||||
Assert.equal(1, events.length, "Recorded one event too many.");
|
||||
|
||||
// camelCase extras work.
|
||||
let extra5 = {
|
||||
extra3LongerName: false,
|
||||
@ -172,7 +168,7 @@ add_task(async function test_fog_event_works() {
|
||||
Glean.testOnlyIpc.eventWithExtra.record(extra3);
|
||||
Assert.throws(
|
||||
() => Glean.testOnlyIpc.eventWithExtra.testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Should throw because of a recording error."
|
||||
);
|
||||
});
|
||||
@ -208,7 +204,7 @@ add_task(async function test_fog_custom_distribution_works() {
|
||||
Glean.testOnlyIpc.aCustomDist.accumulateSamples([-7]);
|
||||
Assert.throws(
|
||||
() => Glean.testOnlyIpc.aCustomDist.testGetValue(),
|
||||
/DataError/
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/
|
||||
);
|
||||
});
|
||||
|
||||
@ -304,14 +300,14 @@ add_task(async function test_fog_labels_conform() {
|
||||
Glean.testOnly.mabelsLabelMaker[veryLong].set("seventy-two");
|
||||
Assert.throws(
|
||||
() => Glean.testOnly.mabelsLabelMaker[veryLong].testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Should throw because of an invalid label."
|
||||
);
|
||||
// This test should _now_ throw because we are calling data after an invalid
|
||||
// label has been set.
|
||||
Assert.throws(
|
||||
() => Glean.testOnly.mabelsLabelMaker["dot.separated"].testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Should throw because of an invalid label."
|
||||
);
|
||||
});
|
||||
@ -340,7 +336,7 @@ add_task(async function test_fog_labeled_boolean_works() {
|
||||
Glean.testOnly.mabelsLikeBalloons["1".repeat(72)].set(true);
|
||||
Assert.throws(
|
||||
() => Glean.testOnly.mabelsLikeBalloons.__other__.testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Should throw because of a recording error."
|
||||
);
|
||||
});
|
||||
@ -369,7 +365,7 @@ add_task(async function test_fog_labeled_counter_works() {
|
||||
Glean.testOnly.mabelsKitchenCounters["1".repeat(72)].add(1);
|
||||
Assert.throws(
|
||||
() => Glean.testOnly.mabelsKitchenCounters.__other__.testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Should throw because of a recording error."
|
||||
);
|
||||
});
|
||||
@ -398,7 +394,7 @@ add_task(async function test_fog_labeled_string_works() {
|
||||
Glean.testOnly.mabelsBalloonStrings["1".repeat(72)].set("valid");
|
||||
Assert.throws(
|
||||
() => Glean.testOnly.mabelsBalloonStrings.__other__.testGetValue(),
|
||||
/DataError/
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -145,7 +145,7 @@ add_task(
|
||||
|
||||
Assert.throws(
|
||||
() => Glean.testOnly.mabelsBathroomCounters.__other__.testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Invalid labels record errors, which throw"
|
||||
);
|
||||
|
||||
|
@ -213,6 +213,14 @@ add_task(async function test_jog_event_works() {
|
||||
};
|
||||
Assert.deepEqual(expectedExtra, events[0].extra);
|
||||
|
||||
// Quantities need to be non-negative.
|
||||
let extra4 = {
|
||||
extra2: -1,
|
||||
};
|
||||
Glean.jogCat.jogEventWithExtra.record(extra4);
|
||||
events = Glean.jogCat.jogEventWithExtra.testGetValue();
|
||||
Assert.equal(1, events.length, "Recorded one event too many.");
|
||||
|
||||
// Invalid extra keys don't crash, the event is not recorded.
|
||||
let extra3 = {
|
||||
extra1_nonexistent_extra: "this does not crash",
|
||||
@ -221,7 +229,7 @@ add_task(async function test_jog_event_works() {
|
||||
// And test methods throw appropriately
|
||||
Assert.throws(
|
||||
() => Glean.jogCat.jogEventWithExtra.testGetValue(),
|
||||
/DataError/
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/
|
||||
);
|
||||
});
|
||||
|
||||
@ -277,7 +285,10 @@ add_task(async function test_jog_custom_distribution_works() {
|
||||
|
||||
// Negative values will not be recorded, instead an error is recorded.
|
||||
Glean.jogCat.jogCustomDist.accumulateSamples([-7]);
|
||||
Assert.throws(() => Glean.jogCat.jogCustomDist.testGetValue(), /DataError/);
|
||||
Assert.throws(
|
||||
() => Glean.jogCat.jogCustomDist.testGetValue(),
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function test_jog_custom_pings() {
|
||||
@ -371,7 +382,7 @@ add_task(async function test_jog_labeled_boolean_works() {
|
||||
Glean.jogCat.jogLabeledBool["1".repeat(72)].set(true);
|
||||
Assert.throws(
|
||||
() => Glean.jogCat.jogLabeledBool.__other__.testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Should throw because of a recording error."
|
||||
);
|
||||
});
|
||||
@ -440,7 +451,7 @@ add_task(async function test_jog_labeled_counter_works() {
|
||||
Glean.jogCat.jogLabeledCounter["1".repeat(72)].add(1);
|
||||
Assert.throws(
|
||||
() => Glean.jogCat.jogLabeledCounter.__other__.testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Should throw because of a recording error."
|
||||
);
|
||||
});
|
||||
@ -479,7 +490,7 @@ add_task(async function test_jog_labeled_counter_with_static_labels_works() {
|
||||
// TODO:(bug 1766515) - This should throw.
|
||||
/*Assert.throws(
|
||||
() => Glean.jogCat.jogLabeledCounterWithLabels.__other__.testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Should throw because of a recording error."
|
||||
);*/
|
||||
Assert.equal(
|
||||
@ -514,7 +525,7 @@ add_task(async function test_jog_labeled_string_works() {
|
||||
Glean.jogCat.jogLabeledString["1".repeat(72)].set("valid");
|
||||
Assert.throws(
|
||||
() => Glean.jogCat.jogLabeledString.__other__.testGetValue(),
|
||||
/DataError/
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/
|
||||
);
|
||||
});
|
||||
|
||||
@ -552,7 +563,7 @@ add_task(async function test_jog_labeled_string_with_labels_works() {
|
||||
// TODO:(bug 1766515) - This should throw.
|
||||
/*Assert.throws(
|
||||
() => Glean.jogCat.jogLabeledStringWithLabels.__other__.testGetValue(),
|
||||
/DataError/
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/
|
||||
);*/
|
||||
Assert.equal(
|
||||
"valid",
|
||||
|
@ -238,7 +238,7 @@ add_task(
|
||||
|
||||
Assert.throws(
|
||||
() => Glean.jogIpc.jogLabeledCounterErr.__other__.testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Invalid labels record errors, which throw"
|
||||
);
|
||||
|
||||
@ -250,7 +250,7 @@ add_task(
|
||||
/*Assert.throws(
|
||||
() =>
|
||||
Glean.jogIpc.jogLabeledCounterWithLabelsErr.__other__.testGetValue(),
|
||||
/DataError/,
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Invalid labels record errors, which throw"
|
||||
);*/
|
||||
Assert.equal(
|
||||
|
@ -20,7 +20,7 @@ XPIDL_MODULE = "fog"
|
||||
|
||||
XPIDL_SOURCES += [
|
||||
"nsIFOG.idl",
|
||||
"nsIGleanPing.idl",
|
||||
"nsIGleanMetrics.idl",
|
||||
]
|
||||
|
||||
with Files("**"):
|
||||
|
@ -1,26 +1,19 @@
|
||||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
|
||||
/* 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/.
|
||||
*/
|
||||
* 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/. */
|
||||
|
||||
// The definitions in this file are not sorted.
|
||||
// Please add new ones to the bottom.
|
||||
#include "nsISupports.idl"
|
||||
|
||||
/**
|
||||
* Base interface for all metric types to make typing more expressive.
|
||||
*/
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
interface GleanMetric {};
|
||||
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
interface GleanBoolean : GleanMetric {
|
||||
[scriptable, uuid(d3180fe0-19fa-11eb-8b6f-0800200c9a66)]
|
||||
interface nsIGleanBoolean : nsISupports
|
||||
{
|
||||
/**
|
||||
* Set to the specified boolean value.
|
||||
*
|
||||
* @param value the value to set.
|
||||
*/
|
||||
undefined set(boolean value);
|
||||
void set(in bool value);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
@ -37,14 +30,14 @@ interface GleanBoolean : GleanMetric {
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or null if there is no value.
|
||||
* @return value of the stored metric, or undefined if there is no value.
|
||||
*/
|
||||
[Throws, ChromeOnly]
|
||||
boolean? testGetValue(optional UTF8String aPingName = "");
|
||||
jsval testGetValue([optional] in AUTF8String aPingName);
|
||||
};
|
||||
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
interface GleanDatetime : GleanMetric {
|
||||
[scriptable, uuid(aa15fd20-1e8a-11eb-9bec-0800200c9a66)]
|
||||
interface nsIGleanDatetime : nsISupports
|
||||
{
|
||||
/**
|
||||
* Set the datetime to the provided value, or the local now.
|
||||
* The internal value will store the local timezone.
|
||||
@ -55,12 +48,13 @@ interface GleanDatetime : GleanMetric {
|
||||
* @param aValue The (optional) time value as PRTime (nanoseconds since epoch).
|
||||
* Defaults to local now.
|
||||
*/
|
||||
undefined set(optional long long aValue);
|
||||
[optional_argc]
|
||||
void set([optional] in PRTime aValue);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
*
|
||||
* Gets the currently stored value as a Date.
|
||||
* Gets the currently stored value as an integer.
|
||||
*
|
||||
* This function will attempt to await the last parent-process task (if any)
|
||||
* writing to the the metric's storage engine before returning a value.
|
||||
@ -73,20 +67,21 @@ interface GleanDatetime : GleanMetric {
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric as a JS Date with timezone,
|
||||
* or null if there is no value.
|
||||
* or undefined if there is no value.
|
||||
*/
|
||||
[Throws, ChromeOnly]
|
||||
any testGetValue(optional UTF8String aPingName = "");
|
||||
[implicit_jscontext]
|
||||
jsval testGetValue([optional] in AUTF8String aPingName);
|
||||
};
|
||||
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
interface GleanCounter : GleanMetric {
|
||||
[scriptable, uuid(05b89d2a-d57c-11ea-82da-3f63399a6f5a)]
|
||||
interface nsIGleanCounter : nsISupports
|
||||
{
|
||||
/*
|
||||
* Increases the counter by `amount`.
|
||||
*
|
||||
* @param aAmount The (optional) amount to increase by. Should be positive. Defaults to 1.
|
||||
* @param amount The amount to increase by. Should be positive.
|
||||
*/
|
||||
undefined add(optional long aAmount = 1);
|
||||
void add(in int32_t amount);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
@ -103,25 +98,21 @@ interface GleanCounter : GleanMetric {
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or null if there is no value.
|
||||
* @return value of the stored metric, or undefined if there is no value.
|
||||
*/
|
||||
[Throws, ChromeOnly]
|
||||
long? testGetValue(optional UTF8String aPingName = "");
|
||||
jsval testGetValue([optional] in AUTF8String aPingName);
|
||||
};
|
||||
|
||||
dictionary GleanDistributionData {
|
||||
required unsigned long long sum;
|
||||
required record<UTF8String, unsigned long long> values;
|
||||
};
|
||||
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
interface GleanTimingDistribution : GleanMetric {
|
||||
[scriptable, uuid(92e14730-9b5f-45a1-b018-f588d0b964d8)]
|
||||
interface nsIGleanTimingDistribution : nsISupports
|
||||
{
|
||||
/**
|
||||
* Starts tracking time for the provided metric.
|
||||
*
|
||||
* @returns A unique timer id for the new timer
|
||||
*/
|
||||
unsigned long long start();
|
||||
[implicit_jscontext]
|
||||
jsval start();
|
||||
|
||||
/**
|
||||
* Stops tracking time for the provided metric and timer id.
|
||||
@ -133,7 +124,7 @@ interface GleanTimingDistribution : GleanMetric {
|
||||
* @param aId The TimerId associated with this timing. This allows for
|
||||
* concurrent timing of events associated with different ids.
|
||||
*/
|
||||
undefined stopAndAccumulate(unsigned long long aId);
|
||||
void stopAndAccumulate(in uint64_t aId);
|
||||
|
||||
/**
|
||||
* Aborts a previous `start` call. No error is recorded if no `start` was
|
||||
@ -141,12 +132,12 @@ interface GleanTimingDistribution : GleanMetric {
|
||||
*
|
||||
* @param aId The TimerID whose `start` you wish to abort.
|
||||
*/
|
||||
undefined cancel(unsigned long long aId);
|
||||
void cancel(in uint64_t aId);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
*
|
||||
* Gets the currently stored value.
|
||||
* Gets the currently stored value as a DistributionData.
|
||||
*
|
||||
* This function will attempt to await the last parent-process task (if any)
|
||||
* writing to the the metric's storage engine before returning a value.
|
||||
@ -158,26 +149,28 @@ interface GleanTimingDistribution : GleanMetric {
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or null if there is no value.
|
||||
* @return value of the stored metric, or undefined if there is no value.
|
||||
*/
|
||||
[Throws, ChromeOnly]
|
||||
GleanDistributionData? testGetValue(optional UTF8String aPingName = "");
|
||||
[implicit_jscontext]
|
||||
jsval testGetValue([optional] in ACString aPingName);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
*
|
||||
* Accumulates a raw numeric sample of milliseconds.
|
||||
*
|
||||
* Test-only until we find a use-case and decent JS Time Duration type.
|
||||
*
|
||||
* @param aSample The sample, in milliseconds, to add.
|
||||
*/
|
||||
[ChromeOnly]
|
||||
undefined testAccumulateRawMillis(unsigned long long aSample);
|
||||
void testAccumulateRawMillis(in uint64_t aSample);
|
||||
};
|
||||
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
interface GleanMemoryDistribution : GleanMetric {
|
||||
/**
|
||||
* Accumulates the provided signed sample in the metric.
|
||||
[scriptable, uuid(eea5ed46-16ba-46cd-bb1f-504581987fe1)]
|
||||
interface nsIGleanMemoryDistribution : nsISupports
|
||||
{
|
||||
/*
|
||||
* Accumulates the provided sample in the metric.
|
||||
*
|
||||
* @param aSample The sample to be recorded by the metric. The sample is
|
||||
* assumed to be in the confgured memory unit of the metric.
|
||||
@ -185,7 +178,7 @@ interface GleanMemoryDistribution : GleanMetric {
|
||||
* Notes: Values bigger than 1 Terabyte (2^40 bytes) are truncated and an
|
||||
* InvalidValue error is recorded.
|
||||
*/
|
||||
undefined accumulate(unsigned long long aSample);
|
||||
void accumulate(in uint64_t aSample);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
@ -202,15 +195,16 @@ interface GleanMemoryDistribution : GleanMetric {
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or null if there is no value.
|
||||
* @return value of the stored metric, or undefined if there is no value.
|
||||
*/
|
||||
[Throws, ChromeOnly]
|
||||
GleanDistributionData? testGetValue(optional UTF8String aPingName = "");
|
||||
[implicit_jscontext]
|
||||
jsval testGetValue([optional] in ACString aPingName);
|
||||
};
|
||||
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
interface GleanCustomDistribution : GleanMetric {
|
||||
/**
|
||||
[scriptable, uuid(45cc016f-c1d5-4d54-aaa5-a802cf65f23b)]
|
||||
interface nsIGleanCustomDistribution : nsISupports
|
||||
{
|
||||
/*
|
||||
* Accumulates the provided signed samples in the metric.
|
||||
*
|
||||
* @param aSamples - The vector holding the samples to be recorded by the metric.
|
||||
@ -218,7 +212,7 @@ interface GleanCustomDistribution : GleanMetric {
|
||||
* Notes: Discards any negative value in `samples`
|
||||
* and report an `ErrorType::InvalidValue` for each of them.
|
||||
*/
|
||||
undefined accumulateSamples(sequence<long long> aSamples);
|
||||
void accumulateSamples(in Array<int64_t> aSamples);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
@ -235,20 +229,66 @@ interface GleanCustomDistribution : GleanMetric {
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or null if there is no value.
|
||||
* @return value of the stored metric, or undefined if there is no value.
|
||||
*/
|
||||
[Throws, ChromeOnly]
|
||||
GleanDistributionData? testGetValue(optional UTF8String aPingName = "");
|
||||
[implicit_jscontext]
|
||||
jsval testGetValue([optional] in ACString aPingName);
|
||||
};
|
||||
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
interface GleanString : GleanMetric {
|
||||
[scriptable, function, uuid(e5447f62-4b03-497c-81e9-6ab683d20380)]
|
||||
interface nsIGleanPingTestCallback : nsISupports
|
||||
{
|
||||
void call(in ACString aReason);
|
||||
};
|
||||
|
||||
[scriptable, uuid(5223a48b-687d-47ff-a629-fd4a72d1ecfa)]
|
||||
interface nsIGleanPing : nsISupports
|
||||
{
|
||||
/**
|
||||
* Set the string to the provided value.
|
||||
* Collect and submit the ping for eventual upload.
|
||||
*
|
||||
* @param aValue The string to set the metric to.
|
||||
* This will collect all stored data to be included in the ping.
|
||||
* Data with lifetime `ping` will then be reset.
|
||||
*
|
||||
* If the ping is configured with `send_if_empty = false`
|
||||
* and the ping currently contains no content,
|
||||
* it will not be queued for upload.
|
||||
* If the ping is configured with `send_if_empty = true`
|
||||
* it will be queued for upload even if empty.
|
||||
*
|
||||
* Pings always contain the `ping_info` and `client_info` sections.
|
||||
* See [ping sections](https://mozilla.github.io/glean/book/user/pings/index.html#ping-sections)
|
||||
* for details.
|
||||
*
|
||||
* @param aReason - Optional. The reason the ping is being submitted.
|
||||
* Must match one of the configured `reason_codes`.
|
||||
*/
|
||||
undefined set(UTF8String? aValue);
|
||||
void submit([optional] in ACString aReason);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
*
|
||||
* Register a callback to be called right before this ping is next submitted.
|
||||
* The provided function is called exactly once before submitting.
|
||||
*
|
||||
* Note: The callback will be called on any call to submit.
|
||||
* A ping might not be sent afterwards, e.g. if the ping is empty and
|
||||
* `send_if_empty` is `false`.
|
||||
*
|
||||
* @param aCallback - The callback to call on the next submit.
|
||||
*/
|
||||
void testBeforeNextSubmit(in nsIGleanPingTestCallback aCallback);
|
||||
};
|
||||
|
||||
[scriptable, uuid(d84a3555-46f1-48c1-9122-e8e88b069d2b)]
|
||||
interface nsIGleanString : nsISupports
|
||||
{
|
||||
/*
|
||||
* Set to the specified value.
|
||||
*
|
||||
* @param value The string to set the metric to.
|
||||
*/
|
||||
void set(in AUTF8String value);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
@ -265,32 +305,33 @@ interface GleanString : GleanMetric {
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or null if there is no value.
|
||||
* @return value of the stored metric, or undefined if there is no value.
|
||||
*/
|
||||
[Throws, ChromeOnly]
|
||||
UTF8String? testGetValue(optional UTF8String aPingName = "");
|
||||
[implicit_jscontext]
|
||||
jsval testGetValue([optional] in AUTF8String aPingName);
|
||||
};
|
||||
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
interface GleanStringList : GleanMetric {
|
||||
[scriptable, uuid(46751205-2ac7-47dc-91d2-ef4a95ef2af9)]
|
||||
interface nsIGleanStringList : nsISupports
|
||||
{
|
||||
/**
|
||||
* Adds a new string to the list.
|
||||
*
|
||||
* Truncates the value and logs an error if it is longer than 100 bytes.
|
||||
* Truncates the value and logs an error if it is longer than 50 bytes.
|
||||
*
|
||||
* @param value The string to add.
|
||||
*/
|
||||
undefined add(UTF8String value);
|
||||
void add(in AUTF8String value);
|
||||
|
||||
/**
|
||||
* Sets the string_list to the provided list of strings.
|
||||
* Sets to a specific list of strings.
|
||||
*
|
||||
* Truncates the list and logs an error if longer than 100 items.
|
||||
* Truncates any item longer than 100 bytes and logs an error.
|
||||
* Truncates the list and logs an error if longer than 20 items.
|
||||
* Truncates any item longer than 50 bytes and logs an error.
|
||||
*
|
||||
* @param aValue The list of strings to set the metric to.
|
||||
* @param value The list of strings to set.
|
||||
*/
|
||||
undefined set(sequence<UTF8String> aValue);
|
||||
void set(in Array<AUTF8String> value);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
@ -307,14 +348,15 @@ interface GleanStringList : GleanMetric {
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or null if there is no value.
|
||||
* @return value of the stored metric, or undefined if there is no value.
|
||||
*/
|
||||
[Throws, ChromeOnly]
|
||||
sequence<UTF8String>? testGetValue(optional UTF8String aPingName = "");
|
||||
[implicit_jscontext]
|
||||
jsval testGetValue([optional] in AUTF8String aPingName);
|
||||
};
|
||||
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
interface GleanTimespan : GleanMetric {
|
||||
[scriptable, uuid(2586530c-030f-11eb-93cb-cbf30d25225a)]
|
||||
interface nsIGleanTimespan : nsISupports
|
||||
{
|
||||
/**
|
||||
* Start tracking time for the provided metric.
|
||||
*
|
||||
@ -322,7 +364,7 @@ interface GleanTimespan : GleanMetric {
|
||||
* called with no corresponding [stop]): in that case the original
|
||||
* start time will be preserved.
|
||||
*/
|
||||
undefined start();
|
||||
void start();
|
||||
|
||||
/**
|
||||
* Stop tracking time for the provided metric.
|
||||
@ -332,14 +374,14 @@ interface GleanTimespan : GleanMetric {
|
||||
* This will record an error if no [start] was called or there is an already
|
||||
* existing value.
|
||||
*/
|
||||
undefined stop();
|
||||
void stop();
|
||||
|
||||
/**
|
||||
* Aborts a previous start.
|
||||
*
|
||||
* Does not record an error if there was no previous call to start.
|
||||
*/
|
||||
undefined cancel();
|
||||
void cancel();
|
||||
|
||||
/**
|
||||
* Explicitly sets the timespan value.
|
||||
@ -350,145 +392,7 @@ interface GleanTimespan : GleanMetric {
|
||||
* @param aDuration The duration of this timespan, in units matching the
|
||||
* `time_unit` of this metric's definition.
|
||||
*/
|
||||
undefined setRaw(unsigned long aDuration);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
*
|
||||
* Gets the currently stored value.
|
||||
*
|
||||
* This function will attempt to await the last parent-process task (if any)
|
||||
* writing to the the metric's storage engine before returning a value.
|
||||
* This function will not wait for data from child processes.
|
||||
*
|
||||
* This doesn't clear the stored value.
|
||||
* Parent process only. Panics in child processes.
|
||||
*
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or null if there is no value.
|
||||
*/
|
||||
[Throws, ChromeOnly]
|
||||
unsigned long long? testGetValue(optional UTF8String aPingName = "");
|
||||
};
|
||||
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
interface GleanUuid : GleanMetric {
|
||||
/**
|
||||
* Set to the specified value.
|
||||
*
|
||||
* @param aValue The UUID to set the metric to.
|
||||
*/
|
||||
undefined set(UTF8String aValue);
|
||||
|
||||
/**
|
||||
* Generate a new random UUID and set the metric to it.
|
||||
*/
|
||||
undefined generateAndSet();
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
*
|
||||
* Gets the currently stored value.
|
||||
*
|
||||
* This function will attempt to await the last parent-process task (if any)
|
||||
* writing to the the metric's storage engine before returning a value.
|
||||
* This function will not wait for data from child processes.
|
||||
*
|
||||
* This doesn't clear the stored value.
|
||||
* Parent process only. Panics in child processes.
|
||||
*
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or null if there is no value.
|
||||
*/
|
||||
[Throws, ChromeOnly]
|
||||
UTF8String? testGetValue(optional UTF8String aPingName = "");
|
||||
};
|
||||
|
||||
dictionary GleanEventRecord {
|
||||
required unsigned long long timestamp;
|
||||
required UTF8String category;
|
||||
required UTF8String name;
|
||||
record<UTF8String, UTF8String> extra;
|
||||
};
|
||||
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
interface GleanEvent : GleanMetric {
|
||||
|
||||
/*
|
||||
* Record an event.
|
||||
*
|
||||
* @param aExtra An (optional) map of extra values.
|
||||
*/
|
||||
undefined _record(optional record<UTF8String, UTF8String?> aExtra);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
*
|
||||
* Gets the currently stored value.
|
||||
*
|
||||
* This function will attempt to await the last parent-process task (if any)
|
||||
* writing to the the metric's storage engine before returning a value.
|
||||
* This function will not wait for data from child processes.
|
||||
*
|
||||
* This doesn't clear the stored value.
|
||||
* Parent process only. Panics in child processes.
|
||||
*
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or null if there is no value.
|
||||
*
|
||||
* The difference between event timestamps is in milliseconds
|
||||
* See https://mozilla.github.io/glean/book/user/metrics/event.html for further details.
|
||||
* Due to limitations of numbers in JavaScript, the timestamp will only be accurate up until 2^53.
|
||||
* (This is probably not an issue with the current clock implementation. Probably.)
|
||||
*/
|
||||
[Throws, ChromeOnly]
|
||||
sequence<GleanEventRecord>? testGetValue(optional UTF8String aPingName = "");
|
||||
};
|
||||
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
interface GleanQuantity : GleanMetric {
|
||||
/**
|
||||
* Set to the specified value.
|
||||
*
|
||||
* @param aValue The value to set the metric to.
|
||||
*/
|
||||
undefined set(long long aValue);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
*
|
||||
* Gets the currently stored value.
|
||||
*
|
||||
* This function will attempt to await the last parent-process task (if any)
|
||||
* writing to the the metric's storage engine before returning a value.
|
||||
* This function will not wait for data from child processes.
|
||||
*
|
||||
* This doesn't clear the stored value.
|
||||
* Parent process only. Panics in child processes.
|
||||
*
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or null if there is no value.
|
||||
*/
|
||||
[Throws, ChromeOnly]
|
||||
long long? testGetValue(optional UTF8String aPingName = "");
|
||||
};
|
||||
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
interface GleanDenominator : GleanMetric {
|
||||
/*
|
||||
* Increases the counter by `aAmount`.
|
||||
*
|
||||
* @param aAmount The (optional) amount to increase by. Should be positive. Defaults to 1.
|
||||
*/
|
||||
undefined add(optional long aAmount = 1);
|
||||
void setRaw(in uint32_t aDuration);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
@ -505,92 +409,110 @@ interface GleanDenominator : GleanMetric {
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or null if there is no value.
|
||||
* @return value of the stored metric, or undefined if there is no value.
|
||||
*/
|
||||
[Throws, ChromeOnly]
|
||||
long? testGetValue(optional UTF8String aPingName = "");
|
||||
jsval testGetValue([optional] in AUTF8String aPingName);
|
||||
};
|
||||
|
||||
dictionary GleanRateData {
|
||||
required long numerator;
|
||||
required long denominator;
|
||||
};
|
||||
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
interface GleanNumerator : GleanMetric {
|
||||
/*
|
||||
* Increases the numerator by `aAmount`.
|
||||
*
|
||||
* @param aAmount The (optional) amount to increase by. Should be positive. Defaults to 1.
|
||||
*/
|
||||
undefined addToNumerator(optional long aAmount = 1);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
*
|
||||
* Gets the currently stored value in the form {numerator: n, denominator: d}
|
||||
*
|
||||
* This function will attempt to await the last parent-process task (if any)
|
||||
* writing to the the metric's storage engine before returning a value.
|
||||
* This function will not wait for data from child processes.
|
||||
*
|
||||
* This doesn't clear the stored value.
|
||||
* Parent process only. Panics in child processes.
|
||||
*
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or null if there is no value.
|
||||
*/
|
||||
[Throws, ChromeOnly]
|
||||
GleanRateData? testGetValue(optional UTF8String aPingName = "");
|
||||
};
|
||||
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
interface GleanRate : GleanMetric {
|
||||
/*
|
||||
* Increases the numerator by `amount`.
|
||||
*
|
||||
* @param aAmount The (optional) amount to increase by. Should be positive. Defaults to 1.
|
||||
*/
|
||||
undefined addToNumerator(optional long aAmount = 1);
|
||||
|
||||
/*
|
||||
* Increases the denominator by `amount`.
|
||||
*
|
||||
* @param aAmount The (optional) amount to increase by. Should be positive. Defaults to 1.
|
||||
*/
|
||||
undefined addToDenominator(optional long aAmount = 1);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
*
|
||||
* Gets the currently stored value in the form {numerator: n, denominator: d}
|
||||
*
|
||||
* This function will attempt to await the last parent-process task (if any)
|
||||
* writing to the the metric's storage engine before returning a value.
|
||||
* This function will not wait for data from child processes.
|
||||
*
|
||||
* This doesn't clear the stored value.
|
||||
* Parent process only. Panics in child processes.
|
||||
*
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or null if there is no value.
|
||||
*/
|
||||
[Throws, ChromeOnly]
|
||||
GleanRateData? testGetValue(optional UTF8String aPingName = "");
|
||||
};
|
||||
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
interface GleanUrl : GleanMetric {
|
||||
[scriptable, uuid(395700e7-06f6-46be-adcc-ea58977fda6d)]
|
||||
interface nsIGleanUuid : nsISupports
|
||||
{
|
||||
/**
|
||||
* Set to the specified value.
|
||||
*
|
||||
* @param aValue The stringified URL to set the metric to.
|
||||
* @param aValue The UUID to set the metric to.
|
||||
*/
|
||||
undefined set(UTF8String aValue);
|
||||
void set(in AUTF8String aValue);
|
||||
|
||||
/**
|
||||
* Generate a new random UUID and set the metric to it.
|
||||
*/
|
||||
void generateAndSet();
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
*
|
||||
* Gets the currently stored value as an integer.
|
||||
*
|
||||
* This function will attempt to await the last parent-process task (if any)
|
||||
* writing to the the metric's storage engine before returning a value.
|
||||
* This function will not wait for data from child processes.
|
||||
*
|
||||
* This doesn't clear the stored value.
|
||||
* Parent process only. Panics in child processes.
|
||||
*
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or undefined if there is no value.
|
||||
*/
|
||||
[implicit_jscontext]
|
||||
jsval testGetValue([optional] in AUTF8String aPingName);
|
||||
};
|
||||
|
||||
[scriptable, uuid(1b01424a-1f55-11eb-92a5-0754f6c3f240)]
|
||||
interface nsIGleanEvent : nsISupports
|
||||
{
|
||||
/*
|
||||
* Record an event.
|
||||
*
|
||||
* @param aExtra An (optional) map of extra values.
|
||||
*/
|
||||
[implicit_jscontext]
|
||||
void record([optional] in jsval aExtra);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
*
|
||||
* Get a list of currently stored events for this event metric.
|
||||
*
|
||||
* This function will attempt to await the last parent-process task (if any)
|
||||
* writing to the the metric's storage engine before returning a value.
|
||||
* This function will not wait for data from child processes.
|
||||
*
|
||||
* This doesn't clear the stored value.
|
||||
* Parent process only. Panics in child processes.
|
||||
*
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or undefined if there is no value.
|
||||
*
|
||||
* The data is an array of objects:
|
||||
*
|
||||
* ```
|
||||
* [
|
||||
* {
|
||||
* timestamp: Integer,
|
||||
* category: String,
|
||||
* name: String,
|
||||
* extra: {
|
||||
* String: String
|
||||
* ...
|
||||
* }
|
||||
* },
|
||||
* ...
|
||||
* ]
|
||||
* ```
|
||||
*
|
||||
* The difference between event timestamps is in milliseconds
|
||||
* See https://mozilla.github.io/glean/book/user/metrics/event.html for further details.
|
||||
* Due to limitations of numbers in JavaScript, the timestamp will only be accurate up until 2^53.
|
||||
* (This is probably not an issue with the current clock implementation. Probably.)
|
||||
*/
|
||||
[implicit_jscontext]
|
||||
jsval testGetValue([optional] in AUTF8String aPingName);
|
||||
};
|
||||
|
||||
[scriptable, uuid(0558c1b2-2cb1-4e21-a0a0-6a91a35ef219)]
|
||||
interface nsIGleanQuantity : nsISupports
|
||||
{
|
||||
/**
|
||||
* Set to the specified value.
|
||||
*
|
||||
* @param value the value to set.
|
||||
*/
|
||||
void set(in int64_t value);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
@ -607,20 +529,119 @@ interface GleanUrl : GleanMetric {
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or null if there is no value.
|
||||
* @return value of the stored metric, or undefined if there is no value.
|
||||
*/
|
||||
[Throws, ChromeOnly]
|
||||
UTF8String? testGetValue(optional UTF8String aPingName = "");
|
||||
jsval testGetValue([optional] in AUTF8String aPingName);
|
||||
};
|
||||
|
||||
[Func="nsGlobalWindowInner::IsGleanNeeded", Exposed=Window]
|
||||
interface GleanText : GleanMetric {
|
||||
/**
|
||||
* Set to the provided value.
|
||||
[scriptable, uuid(394d9d3b-9e7e-48cc-b76c-a89a51830da3)]
|
||||
interface nsIGleanDenominator : nsISupports
|
||||
{
|
||||
/*
|
||||
* Increases the counter by `amount`.
|
||||
*
|
||||
* @param aValue The text to set the metric to.
|
||||
* @param amount The amount to increase by. Should be positive.
|
||||
*/
|
||||
undefined set(UTF8String aValue);
|
||||
void add(in int32_t amount);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
*
|
||||
* Gets the currently stored value as an integer.
|
||||
*
|
||||
* This function will attempt to await the last parent-process task (if any)
|
||||
* writing to the the metric's storage engine before returning a value.
|
||||
* This function will not wait for data from child processes.
|
||||
*
|
||||
* This doesn't clear the stored value.
|
||||
* Parent process only. Panics in child processes.
|
||||
*
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or undefined if there is no value.
|
||||
*/
|
||||
jsval testGetValue([optional] in AUTF8String aPingName);
|
||||
};
|
||||
|
||||
[scriptable, uuid(153fff71-7edd-49b4-a166-4697aa89c7a1)]
|
||||
interface nsIGleanNumerator : nsISupports
|
||||
{
|
||||
/*
|
||||
* Increases the numerator by `amount`.
|
||||
*
|
||||
* @param amount The amount to increase by. Should be positive.
|
||||
*/
|
||||
void addToNumerator(in int32_t amount);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
*
|
||||
* Gets the currently stored value in the form {numerator: n, denominator: d}
|
||||
*
|
||||
* This function will attempt to await the last parent-process task (if any)
|
||||
* writing to the the metric's storage engine before returning a value.
|
||||
* This function will not wait for data from child processes.
|
||||
*
|
||||
* This doesn't clear the stored value.
|
||||
* Parent process only. Panics in child processes.
|
||||
*
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or undefined if there is no value.
|
||||
*/
|
||||
[implicit_jscontext]
|
||||
jsval testGetValue([optional] in AUTF8String aPingName);
|
||||
};
|
||||
|
||||
[scriptable, uuid(920cf631-2b1e-4efe-ae2e-f03277c3112a)]
|
||||
interface nsIGleanRate : nsISupports
|
||||
{
|
||||
/*
|
||||
* Increases the numerator by `amount`.
|
||||
*
|
||||
* @param amount The amount to increase by. Should be positive.
|
||||
*/
|
||||
void addToNumerator(in int32_t amount);
|
||||
|
||||
/*
|
||||
* Increases the denominator by `amount`.
|
||||
*
|
||||
* @param amount The amount to increase by. Should be positive.
|
||||
*/
|
||||
void addToDenominator(in int32_t amount);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
*
|
||||
* Gets the currently stored value in the form {numerator: n, denominator: d}
|
||||
*
|
||||
* This function will attempt to await the last parent-process task (if any)
|
||||
* writing to the the metric's storage engine before returning a value.
|
||||
* This function will not wait for data from child processes.
|
||||
*
|
||||
* This doesn't clear the stored value.
|
||||
* Parent process only. Panics in child processes.
|
||||
*
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or undefined if there is no value.
|
||||
*/
|
||||
[implicit_jscontext]
|
||||
jsval testGetValue([optional] in AUTF8String aPingName);
|
||||
};
|
||||
|
||||
[scriptable, uuid(a59672c4-bc48-4bfe-8f9c-6f408a59d819)]
|
||||
interface nsIGleanUrl : nsISupports
|
||||
{
|
||||
/*
|
||||
* Sets to the specified stringified URL.
|
||||
*
|
||||
* @param value The stringified URL to set the metric to.
|
||||
*/
|
||||
void set(in AUTF8String value);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
@ -637,8 +658,39 @@ interface GleanText : GleanMetric {
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or null if there is no value.
|
||||
* @return value of the stored metric, or undefined if there is no value.
|
||||
*/
|
||||
[Throws, ChromeOnly]
|
||||
UTF8String? testGetValue(optional UTF8String aPingName = "");
|
||||
[implicit_jscontext]
|
||||
jsval testGetValue([optional] in AUTF8String aPingName);
|
||||
};
|
||||
|
||||
[scriptable, uuid(fafceafb-c3a0-4424-b3b9-b7bd487f6bb4)]
|
||||
interface nsIGleanText : nsISupports
|
||||
{
|
||||
/*
|
||||
* Set to the specified value.
|
||||
*
|
||||
* @param value The text to set the metric to.
|
||||
*/
|
||||
void set(in AUTF8String value);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
*
|
||||
* Gets the currently stored value as a string.
|
||||
*
|
||||
* This function will attempt to await the last parent-process task (if any)
|
||||
* writing to the the metric's storage engine before returning a value.
|
||||
* This function will not wait for data from child processes.
|
||||
*
|
||||
* This doesn't clear the stored value.
|
||||
* Parent process only. Panics in child processes.
|
||||
*
|
||||
* @param aPingName The (optional) name of the ping to retrieve the metric
|
||||
* for. Defaults to the first value in `send_in_pings`.
|
||||
*
|
||||
* @return value of the stored metric, or undefined if there is no value.
|
||||
*/
|
||||
[implicit_jscontext]
|
||||
jsval testGetValue([optional] in AUTF8String aPingName);
|
||||
};
|
@ -1,51 +0,0 @@
|
||||
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
|
||||
/* 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/. */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, function, uuid(e5447f62-4b03-497c-81e9-6ab683d20380)]
|
||||
interface nsIGleanPingTestCallback : nsISupports
|
||||
{
|
||||
void call(in ACString aReason);
|
||||
};
|
||||
|
||||
[scriptable, uuid(5223a48b-687d-47ff-a629-fd4a72d1ecfa)]
|
||||
interface nsIGleanPing : nsISupports
|
||||
{
|
||||
/**
|
||||
* Collect and submit the ping for eventual upload.
|
||||
*
|
||||
* This will collect all stored data to be included in the ping.
|
||||
* Data with lifetime `ping` will then be reset.
|
||||
*
|
||||
* If the ping is configured with `send_if_empty = false`
|
||||
* and the ping currently contains no content,
|
||||
* it will not be queued for upload.
|
||||
* If the ping is configured with `send_if_empty = true`
|
||||
* it will be queued for upload even if empty.
|
||||
*
|
||||
* Pings always contain the `ping_info` and `client_info` sections.
|
||||
* See [ping sections](https://mozilla.github.io/glean/book/user/pings/index.html#ping-sections)
|
||||
* for details.
|
||||
*
|
||||
* @param aReason - Optional. The reason the ping is being submitted.
|
||||
* Must match one of the configured `reason_codes`.
|
||||
*/
|
||||
void submit([optional] in ACString aReason);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
*
|
||||
* Register a callback to be called right before this ping is next submitted.
|
||||
* The provided function is called exactly once before submitting.
|
||||
*
|
||||
* Note: The callback will be called on any call to submit.
|
||||
* A ping might not be sent afterwards, e.g. if the ping is empty and
|
||||
* `send_if_empty` is `false`.
|
||||
*
|
||||
* @param aCallback - The callback to call on the next submit.
|
||||
*/
|
||||
void testBeforeNextSubmit(in nsIGleanPingTestCallback aCallback);
|
||||
};
|
@ -161,8 +161,8 @@ add_task(async () => {
|
||||
.forEach(label => {
|
||||
Assert.strictEqual(
|
||||
cpuTimeByType[label],
|
||||
null,
|
||||
`no media was played so the CPU time for ${label} should be null`
|
||||
undefined,
|
||||
`no media was played so the CPU time for ${label} should be undefined`
|
||||
);
|
||||
});
|
||||
|
||||
@ -255,21 +255,21 @@ add_task(async () => {
|
||||
// played in a background tab.
|
||||
Assert.strictEqual(
|
||||
cpuTimeByType["web.background-perceivable"],
|
||||
null,
|
||||
undefined,
|
||||
"CPU time should only be recorded in the web.background-perceivable label"
|
||||
);
|
||||
|
||||
// __other__ should be null, if it is not, we have a missing label in the metrics.yaml file.
|
||||
// __other__ should be undefined, if it is not, we have a missing label in the metrics.yaml file.
|
||||
Assert.strictEqual(
|
||||
cpuTimeByType.__other__,
|
||||
null,
|
||||
undefined,
|
||||
"no CPU time should be recorded in the __other__ label"
|
||||
);
|
||||
|
||||
info("GPU time for each label:");
|
||||
let totalGpuTimeByType = undefined;
|
||||
for (let label of kGleanProcessTypeLabels) {
|
||||
if (gpuTimeByType[label] !== null) {
|
||||
if (gpuTimeByType[label] !== undefined) {
|
||||
totalGpuTimeByType = (totalGpuTimeByType || 0) + gpuTimeByType[label];
|
||||
}
|
||||
info(` ${label} = ${gpuTimeByType[label]}`);
|
||||
@ -281,10 +281,10 @@ add_task(async () => {
|
||||
"The sum of GPU time used by all process types should match totalGpuTimeMs"
|
||||
);
|
||||
|
||||
// __other__ should be null, if it is not, we have a missing label in the metrics.yaml file.
|
||||
// __other__ should be undefined, if it is not, we have a missing label in the metrics.yaml file.
|
||||
Assert.strictEqual(
|
||||
gpuTimeByType.__other__,
|
||||
null,
|
||||
undefined,
|
||||
"no GPU time should be recorded in the __other__ label"
|
||||
);
|
||||
|
||||
@ -318,12 +318,12 @@ add_task(async () => {
|
||||
for (let processType of processTypes) {
|
||||
Assert.equal(
|
||||
Glean.powerCpuMsPerThread[processType][kThreadName].testGetValue(),
|
||||
null,
|
||||
undefined,
|
||||
`no CPU time should have been recorded for the ${processType} main thread`
|
||||
);
|
||||
Assert.equal(
|
||||
Glean.powerWakeupsPerThread[processType][kThreadName].testGetValue(),
|
||||
null,
|
||||
undefined,
|
||||
`no thread wake ups should have been recorded for the ${processType} main thread`
|
||||
);
|
||||
}
|
||||
|
@ -902,7 +902,7 @@ export var BackgroundUpdate = {
|
||||
for (const [key, value] of Object.entries(this.REASON)) {
|
||||
if (reasons.includes(value)) {
|
||||
try {
|
||||
// `testGetValue` throws a `DataError` in case
|
||||
// `testGetValue` throws `NS_ERROR_LOSS_OF_SIGNIFICANT_DATA` in case
|
||||
// of `InvalidOverflow` and other outstanding errors.
|
||||
Glean.backgroundUpdate.reasonsToNotUpdate.testGetValue();
|
||||
Glean.backgroundUpdate.reasonsToNotUpdate.add(key);
|
||||
|
Loading…
Reference in New Issue
Block a user