fune/toolkit/components/nimbus
Drew Willcoxon f0b457683b Bug 1730618 - Allow Nimbus to enable Firefox Suggest online and override the offline default. r=mythmon,preferences-reviewers,mstriemer
This reworks the fix to bug 1729776.

Currently Nimbus doesn't have a way to force the two suggestions prefs [1] on or
off. That might seem surprising since we've run experiments already. Initially
we defaulted the two prefs to true but we defaulted the separate feature-gate
pref [2] to false, and it was the feature-gate pref we controlled via Nimbus. At
some point we changed the defaults to false and then in Firefox flipped them to
true after showing the onboarding dialog. As a result we've never needed to
override the two suggestion prefs via Nimbus.

The problem now is that we default-enable offline (for US en users), so we set
all three prefs to true. For the online rollout, we need to keep the
feature-gate pref enabled but disable the suggestion prefs, and there's no way
to do that.

My first idea was to add new Nimbus variables to override the two suggestion
prefs. The prefs would keep their default true values but be overridden by
Nimbus. But that doesn't work because there's no way for Firefox to tell whether
the prefs are true because the user has opted in (overriding Nimbus) or because
they still have their default values. Setting the prefs to true on the user
branch doesn't have any effect because they're also true on the default branch.
Or maybe there's a way I don't know about to force them to true on the user
branch, but even if there were, it seems brittle to rely on a value being set on
the user branch to distinguish between the two cases. (This is a potential
problem for any prefs that are controlled by both Nimbus and the user. So far
the prefs we've been using via Nimbus have all been hidden feature-gate-type
things and implementation details.)

We already have a `quickSuggestScenario` variable. We currently use it only to
tell what we should send in the telemetry ping (bug 1729576) and whether some
parts of the prefs UI should be shown. This revision makes it much more
important by treating it as the source of truth for the user's scenario. It now
determines the default values of related prefs, including the two suggestions
prefs.

The logic is:

```
If quickSuggestScenario is non-null:
  scenario = quickSuggestScenario
Else (e.g., there's no rollout):
  If the user is US en:
    scenario = offline
  Else:
    scenario = history
```

After determining the scenario, it's set it as
`browser.urlbar.quicksuggest.scenario` on the default branch. There's an
existing pref observer in UrlbarPrefs, and I added a case for this pref so that
when it's updated we also update all the other prefs that depend on the
scenario. This way when the pref is set -- either due to Nimbus update or by
changing it on about:config -- all the other prefs stay in sync.

I kept the default value of `browser.urlbar.quicksuggest.scenario` but removed
it as the fallback for `quickSuggestScenario`. If it still both had a default
and remained the fallback, then it would be impossible to tell when Nimbus is
trying to override it, because any fetch of the value from Nimbus would just
return the fallback pref's value if there is no override.

I considered instead removing the default value and keeping it as the fallback.
The drawback of that is that unenrollments would not take effect until restart.
I actually tried this approach first, and in tests, after mock experiments were
unenrolled, the pref values remained what they were when the experiment was
active.

It might also be possible to not have the `browser.urlbar.quicksuggest.scenario`
pref at all. We could call NimbusFeatures directly to get the scenario. However,
currently we cache and access Nimbus variables through UrlbarPrefs, as we do
with prefs, and I don't want to add an inconsistency.

This revision also fixes bug 1730596 since it was easy to do given that I needed
a way to prevent indirect recursive updates to the scenario, and I can use that
for bug 1730596 too (the `_updatingFirefoxSuggestScenario` bool).

[1] `browser.urlbar.suggest.quicksuggest` and `browser.urlbar.suggest.quicksuggest.sponsored`
[2] `browser.urlbar.quicksuggest.enabled`

Differential Revision: https://phabricator.services.mozilla.com/D125511
2021-09-16 18:28:02 +00:00
..
docs
lib Bug 1728843 - Add once option to NimbusFeatures.recordExposureEvent r=andreio 2021-09-13 14:35:15 +00:00
schemas Bug 1730926 - Split up hasExposure and exposureDescription in Nimbus manifest r=andreio 2021-09-16 17:45:35 +00:00
test Bug 1730926 - Split up hasExposure and exposureDescription in Nimbus manifest r=andreio 2021-09-16 17:45:35 +00:00
ExperimentAPI.jsm Bug 1728843 - Add once option to NimbusFeatures.recordExposureEvent r=andreio 2021-09-13 14:35:15 +00:00
FeatureManifest.js Bug 1730618 - Allow Nimbus to enable Firefox Suggest online and override the offline default. r=mythmon,preferences-reviewers,mstriemer 2021-09-16 18:28:02 +00:00
jar.mn Bug 1723106 - Source files accidentally exposed as resource:// urls r=glandium 2021-07-30 13:43:10 +00:00
moz.build Bug 1716736 - Add schema validation for experiment enrollments in tests r=k88hudson 2021-07-26 14:48:22 +00:00