Bug 1564898 - Use UpdateManager to get the earliest Firefox version used (#5165)
This commit is contained in:
Родитель
096404379f
Коммит
7c9f560372
|
@ -36,6 +36,7 @@ Please note that some targeting attributes require stricter controls on the tele
|
|||
* [hasPinnedTabs](#haspinnedtabs)
|
||||
* [hasAccessedFxAPanel](#hasaccessedfxapanel)
|
||||
* [isWhatsNewPanelEnabled](#iswhatsnewpanelenabled)
|
||||
* [earliestFirefoxVersion](#earliestfirefoxversion)
|
||||
|
||||
## Detailed usage
|
||||
|
||||
|
@ -496,3 +497,13 @@ Boolean pref that controls if the What's New panel feature is enabled
|
|||
```ts
|
||||
declare const isWhatsNewPanelEnabled: boolean;
|
||||
```
|
||||
|
||||
### `earliestFirefoxVersion`
|
||||
|
||||
Integer value of the first Firefox version the profile ran on
|
||||
|
||||
#### Definition
|
||||
|
||||
```ts
|
||||
declare const earliestFirefoxVersion: boolean;
|
||||
```
|
||||
|
|
|
@ -753,16 +753,12 @@ class _ASRouter {
|
|||
(await this._storage.get("providerImpressions")) || {};
|
||||
const previousSessionEnd =
|
||||
(await this._storage.get("previousSessionEnd")) || 0;
|
||||
// Infinity so that we default to false (firefoxVersion > previousSessionFirefoxVersion)
|
||||
const previousSessionFirefoxVersion =
|
||||
(await this._storage.get("previousSessionFirefoxVersion")) || Infinity;
|
||||
await this.setState({
|
||||
messageBlockList,
|
||||
providerBlockList,
|
||||
messageImpressions,
|
||||
providerImpressions,
|
||||
previousSessionEnd,
|
||||
previousSessionFirefoxVersion,
|
||||
});
|
||||
this._updateMessageProviders();
|
||||
await this.loadMessagesFromAllProviders();
|
||||
|
@ -782,10 +778,6 @@ class _ASRouter {
|
|||
|
||||
uninit() {
|
||||
this._storage.set("previousSessionEnd", Date.now());
|
||||
this._storage.set(
|
||||
"previousSessionFirefoxVersion",
|
||||
ASRouterTargeting.Environment.firefoxVersion
|
||||
);
|
||||
|
||||
this.messageChannel.sendAsyncMessage(OUTGOING_MESSAGE_NAME, {
|
||||
type: "CLEAR_ALL",
|
||||
|
@ -1048,7 +1040,6 @@ class _ASRouter {
|
|||
const {
|
||||
messageImpressions,
|
||||
previousSessionEnd,
|
||||
previousSessionFirefoxVersion,
|
||||
trailheadInterrupt,
|
||||
trailheadTriplet,
|
||||
} = this.state;
|
||||
|
@ -1060,12 +1051,6 @@ class _ASRouter {
|
|||
get previousSessionEnd() {
|
||||
return previousSessionEnd;
|
||||
},
|
||||
get previousSessionFirefoxVersion() {
|
||||
// Any comparison with `undefined` will return false
|
||||
return isNaN(previousSessionFirefoxVersion)
|
||||
? undefined
|
||||
: previousSessionFirefoxVersion;
|
||||
},
|
||||
get trailheadInterrupt() {
|
||||
return trailheadInterrupt;
|
||||
},
|
||||
|
|
|
@ -2,6 +2,9 @@ const { FilterExpressions } = ChromeUtils.import(
|
|||
"resource://gre/modules/components-utils/FilterExpressions.jsm"
|
||||
);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { XPCOMUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
|
@ -43,6 +46,12 @@ ChromeUtils.defineModuleGetter(
|
|||
"AttributionCode",
|
||||
"resource:///modules/AttributionCode.jsm"
|
||||
);
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this,
|
||||
"UpdateManager",
|
||||
"@mozilla.org/updates/update-manager;1",
|
||||
"nsIUpdateManager"
|
||||
);
|
||||
|
||||
const FXA_USERNAME_PREF = "services.sync.username";
|
||||
const FXA_ENABLED_PREF = "identity.fxaccounts.enabled";
|
||||
|
@ -400,6 +409,16 @@ const TargetingGetters = {
|
|||
false
|
||||
);
|
||||
},
|
||||
get earliestFirefoxVersion() {
|
||||
if (UpdateManager.updateCount) {
|
||||
const earliestFirefoxVersion = UpdateManager.getUpdateAt(
|
||||
UpdateManager.updateCount - 1
|
||||
).previousAppVersion;
|
||||
return parseInt(earliestFirefoxVersion.match(/\d+/), 10);
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
};
|
||||
|
||||
this.ASRouterTargeting = {
|
||||
|
|
|
@ -492,8 +492,8 @@ const ONBOARDING_MESSAGES = async () => [
|
|||
},
|
||||
// Never saw this message or saw it in the past 4 days or more recent
|
||||
targeting: `isWhatsNewPanelEnabled &&
|
||||
(firefoxVersion > previousSessionFirefoxVersion &&
|
||||
messageImpressions[.id == 'WHATS_NEW_BADGE_${FIREFOX_VERSION}']|length == 0) ||
|
||||
(earliestFirefoxVersion && firefoxVersion > earliestFirefoxVersion) &&
|
||||
messageImpressions[.id == 'WHATS_NEW_BADGE_${FIREFOX_VERSION}']|length == 0 ||
|
||||
(messageImpressions[.id == 'WHATS_NEW_BADGE_${FIREFOX_VERSION}']|length >= 1 &&
|
||||
currentDate|date - messageImpressions[.id == 'WHATS_NEW_BADGE_${FIREFOX_VERSION}'][0] <= 4 * 24 * 3600 * 1000)`,
|
||||
},
|
||||
|
|
|
@ -60,7 +60,6 @@ describe("ASRouter", () => {
|
|||
let messageImpressions;
|
||||
let providerImpressions;
|
||||
let previousSessionEnd;
|
||||
let previousSessionFirefoxVersion;
|
||||
let fetchStub;
|
||||
let clock;
|
||||
let getStringPrefStub;
|
||||
|
@ -88,9 +87,6 @@ describe("ASRouter", () => {
|
|||
getStub
|
||||
.withArgs("previousSessionEnd")
|
||||
.returns(Promise.resolve(previousSessionEnd));
|
||||
getStub
|
||||
.withArgs("previousSessionFirefoxVersion")
|
||||
.returns(Promise.resolve(previousSessionFirefoxVersion));
|
||||
return {
|
||||
get: getStub,
|
||||
set: sandbox.stub().returns(Promise.resolve()),
|
||||
|
@ -117,7 +113,6 @@ describe("ASRouter", () => {
|
|||
messageImpressions = {};
|
||||
providerImpressions = {};
|
||||
previousSessionEnd = 100;
|
||||
previousSessionFirefoxVersion = 69;
|
||||
sandbox = sinon.createSandbox();
|
||||
|
||||
sandbox.spy(ASRouterPreferences, "init");
|
||||
|
@ -843,13 +838,6 @@ describe("ASRouter", () => {
|
|||
|
||||
assert.deepEqual(result, message1);
|
||||
});
|
||||
it("should have previousSessionFirefoxVersion in the message context", () => {
|
||||
assert.propertyVal(
|
||||
Router._getMessagesContext(),
|
||||
"previousSessionFirefoxVersion",
|
||||
parseInt(AppConstants.MOZ_APP_VERSION, 10)
|
||||
);
|
||||
});
|
||||
it("should have messageImpressions in the message context", () => {
|
||||
assert.propertyVal(
|
||||
Router._getMessagesContext(),
|
||||
|
@ -967,17 +955,12 @@ describe("ASRouter", () => {
|
|||
it("should save previousSessionEnd", () => {
|
||||
Router.uninit();
|
||||
|
||||
assert.calledTwice(Router._storage.set);
|
||||
assert.calledOnce(Router._storage.set);
|
||||
assert.calledWithExactly(
|
||||
Router._storage.set,
|
||||
"previousSessionEnd",
|
||||
sinon.match.number
|
||||
);
|
||||
assert.calledWithExactly(
|
||||
Router._storage.set,
|
||||
"previousSessionFirefoxVersion",
|
||||
sinon.match.number
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче