зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1735628 - Expose setExperiment(In)Active on the FOG JS global r=TravisLong
Depends on D128926 Differential Revision: https://phabricator.services.mozilla.com/D128927
This commit is contained in:
Родитель
c1db31f7b1
Коммит
c0766b0829
|
@ -31,6 +31,7 @@ EXPORTS.mozilla.glean.bindings += [
|
|||
"bindings/GleanPings.h",
|
||||
"bindings/MetricTypes.h",
|
||||
"bindings/private/Boolean.h",
|
||||
"bindings/private/Common.h",
|
||||
"bindings/private/Counter.h",
|
||||
"bindings/private/CustomDistribution.h",
|
||||
"bindings/private/Datetime.h",
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/FOGIPC.h"
|
||||
#include "mozilla/glean/bindings/Common.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "mozilla/glean/GleanMetrics.h"
|
||||
#include "mozilla/MozPromise.h"
|
||||
|
@ -21,6 +22,8 @@
|
|||
|
||||
namespace mozilla {
|
||||
|
||||
using glean::LogToBrowserConsole;
|
||||
|
||||
#ifdef MOZ_GLEAN_ANDROID
|
||||
// Defined by `glean_ffi`. We reexport it here for later use.
|
||||
extern "C" NS_EXPORT void glean_enable_logging(void);
|
||||
|
@ -120,6 +123,76 @@ FOG::SendPing(const nsACString& aPingName) {
|
|||
#endif
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
FOG::SetExperimentActive(const nsACString& aExperimentId,
|
||||
const nsACString& aBranch, JS::HandleValue aExtra,
|
||||
JSContext* aCx) {
|
||||
#ifdef MOZ_GLEAN_ANDROID
|
||||
NS_WARNING("Don't set experiments from Gecko in Android. Ignoring.");
|
||||
return NS_OK;
|
||||
#else
|
||||
nsTArray<nsCString> extraKeys;
|
||||
nsTArray<nsCString> extraValues;
|
||||
if (!aExtra.isNullOrUndefined()) {
|
||||
JS::RootedObject obj(aCx, &aExtra.toObject());
|
||||
JS::Rooted<JS::IdVector> keys(aCx, JS::IdVector(aCx));
|
||||
if (!JS_Enumerate(aCx, obj, &keys)) {
|
||||
LogToBrowserConsole(nsIScriptError::warningFlag,
|
||||
u"Failed to enumerate experiment extras object."_ns);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
for (size_t i = 0, n = keys.length(); i < n; i++) {
|
||||
nsAutoJSCString jsKey;
|
||||
if (!jsKey.init(aCx, keys[i])) {
|
||||
LogToBrowserConsole(
|
||||
nsIScriptError::warningFlag,
|
||||
u"Extra dictionary should only contain string keys."_ns);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
JS::Rooted<JS::Value> value(aCx);
|
||||
if (!JS_GetPropertyById(aCx, obj, keys[i], &value)) {
|
||||
LogToBrowserConsole(nsIScriptError::warningFlag,
|
||||
u"Failed to get experiment extra property."_ns);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsAutoJSCString jsValue;
|
||||
if (!value.isString()) {
|
||||
LogToBrowserConsole(
|
||||
nsIScriptError::warningFlag,
|
||||
u"Experiment extra properties must have string values."_ns);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!jsValue.init(aCx, value)) {
|
||||
LogToBrowserConsole(nsIScriptError::warningFlag,
|
||||
u"Can't extract experiment extra property"_ns);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
extraKeys.AppendElement(jsKey);
|
||||
extraValues.AppendElement(jsValue);
|
||||
}
|
||||
}
|
||||
glean::impl::fog_set_experiment_active(&aExperimentId, &aBranch, &extraKeys,
|
||||
&extraValues);
|
||||
return NS_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
FOG::SetExperimentInactive(const nsACString& aExperimentId) {
|
||||
#ifdef MOZ_GLEAN_ANDROID
|
||||
NS_WARNING("Don't unset experiments from Gecko in Android. Ignoring.");
|
||||
return NS_OK;
|
||||
#else
|
||||
glean::impl::fog_set_experiment_inactive(&aExperimentId);
|
||||
return NS_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
FOG::TestFlushAllChildren(JSContext* aCx, mozilla::dom::Promise** aOutPromise) {
|
||||
NS_ENSURE_ARG(aOutPromise);
|
||||
|
|
|
@ -53,6 +53,33 @@ interface nsIFOG : nsISupports
|
|||
*/
|
||||
void sendPing(in ACString aPingName);
|
||||
|
||||
/**
|
||||
* Indicate that an experiment is running.
|
||||
* Glean will add an experiment annotation which is sent with pings.
|
||||
* This information is not persisted between runs.
|
||||
*
|
||||
* See `glean_core::Glean::set_experiment_active`.
|
||||
*
|
||||
* Logs on error, but does not throw.
|
||||
*
|
||||
* @param aExperimentId - The id/slug of the experiment.
|
||||
* @param aBranch - The name of the active branch of the experiment.
|
||||
* @param aExtra - Optional string -> string dictionary of extra information.
|
||||
*/
|
||||
[implicit_jscontext]
|
||||
void setExperimentActive(in ACString aExperimentId, in ACString aBranch, [optional] in jsval aExtra);
|
||||
|
||||
/**
|
||||
* Indicate that an experiment is no longer running.
|
||||
*
|
||||
* See `glean_core::Glean::set_experiment_inactive`.
|
||||
*
|
||||
* Logs on error, but does not throw.
|
||||
*
|
||||
* @param aExperimentId - The id/slug of the experiment from setExperimentActive.
|
||||
*/
|
||||
void setExperimentInactive(in ACString aExperimentId);
|
||||
|
||||
/**
|
||||
* ** Test-only Method **
|
||||
*
|
||||
|
|
Загрузка…
Ссылка в новой задаче