Bug 1950658 - Rely on a pref to tell us whether we should initialize Glean on shutdown r=TravisLong

Only once the user interacted with the telemetry reporting policy modal
we can be sure that the preference for collection is valid.
If it's not we don't initialize Glean and thus don't collect any data.

Differential Revision: https://phabricator.services.mozilla.com/D239753
This commit is contained in:
Jan-Erik Rediger
2025-02-27 12:25:53 +00:00
parent 268cc393a6
commit 2de922e5a1
4 changed files with 25 additions and 2 deletions

View File

@@ -16956,6 +16956,11 @@
value: false
mirror: always
- name: telemetry.fog.init_on_shutdown
type: RelaxedAtomicBool
value: true
mirror: always
#---------------------------------------------------------------------------
# Prefs starting with "test."
#---------------------------------------------------------------------------

View File

@@ -46,6 +46,14 @@ Defaults to 120 (activity), 1200 (inactivity).
Read-only. This pref is `true` only if `MOZ_ARTIFACT_BUILDS` was set during configure.
If true, [JOG](./jog) is enabled so that artifact builds will exhibit changes to their Glean metrics.
`telemetry.fog.init_on_shutdown`
Defaults to `true`.
Controls whether Glean initializes on shutdown if it hasn't been initialized, in order to capture data from very short sessions.
In case a policy modal needs to be shown to the user, which will delay Glean initialization,
it's set to `false` until the user has dealt with the modal. It's turned back to `true` afterwards.
This ensures we don't capture data until the user had the chance to make an explicit choice.
## Defines
`MOZ_AUTOMATION`

View File

@@ -88,7 +88,9 @@ already_AddRefed<FOG> FOG::GetSingleton() {
MOZ_ASSERT(idleService);
Unused << idleService->RemoveIdleObserver(gFOG, kIdleSecs);
}
if (!gInitializeCalled) {
bool initOnShutdown =
Preferences::GetBool("telemetry.fog.init_on_shutdown", true);
if (initOnShutdown && !gInitializeCalled) {
gInitializeCalled = true;
// Assuming default data path and application id.
// Consumers using non defaults _must_ initialize FOG explicitly.

View File

@@ -636,6 +636,10 @@ var TelemetryReportingPolicyImpl = {
return;
}
// We're about to show the user the modal dialog.
// Make sure Glean won't initialize on shutdown, in case the user never interacts with the modal
Services.prefs.setBoolPref("telemetry.fog.init_on_shutdown", false);
if (this._nimbusVariables.enabled && this._nimbusVariables.screens) {
if (await this._notifyUserViaMessagingSystem()) {
this._log.trace(
@@ -704,7 +708,11 @@ var TelemetryReportingPolicyImpl = {
this._ensureUserIsNotifiedPromise = this._waitForUserIsNotified();
}
return this._ensureUserIsNotifiedPromise;
return this._ensureUserIsNotifiedPromise.then(() => {
// The user has been notified and interacted with the modal.
// Glean can now init on shutdown if necessary.
Services.prefs.setBoolPref("telemetry.fog.init_on_shutdown", true);
});
},
/**