mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1406097 - Use the cached attribution code in the environment. r=mhowell
This adds a new sync function to AttributionCode.jsm that returns the cached attribution data. The cached data is then used to populate the environment instead of relying on the async function. MozReview-Commit-ID: F0se7kXspo2 --HG-- extra : rebase_source : 0a2631651e3da6edde9592eabd354b070ffa6ae8
This commit is contained in:
parent
0c903578be
commit
fb8a2826f2
@ -90,6 +90,16 @@ var AttributionCode = {
|
||||
})();
|
||||
},
|
||||
|
||||
/**
|
||||
* Return the cached attribution data synchronously without hitting
|
||||
* the disk.
|
||||
* @returns A dictionary with the attribution data if it's available,
|
||||
* null otherwise.
|
||||
*/
|
||||
getCachedAttributionData() {
|
||||
return gCachedAttrData;
|
||||
},
|
||||
|
||||
/**
|
||||
* Deletes the attribution data file.
|
||||
* Returns a promise that resolves when the file is deleted,
|
||||
|
@ -867,7 +867,7 @@ function EnvironmentCache() {
|
||||
this._currentEnvironment.profile = {};
|
||||
p.push(this._updateProfile());
|
||||
if (AppConstants.MOZ_BUILD_APP == "browser") {
|
||||
p.push(this._updateAttribution());
|
||||
p.push(this._loadAttributionAsync());
|
||||
}
|
||||
|
||||
for (const [id, {branch, options}] of gActiveExperimentStartupBuffer.entries()) {
|
||||
@ -1363,13 +1363,7 @@ EnvironmentCache.prototype = {
|
||||
updateChannel = UpdateUtils.getUpdateChannel(false);
|
||||
} catch (e) {}
|
||||
|
||||
// Make sure to retain the attribution code across environment changes.
|
||||
const attributionCode =
|
||||
(this._currentEnvironment.settings &&
|
||||
this._currentEnvironment.settings.attribution) || {};
|
||||
|
||||
this._currentEnvironment.settings = {
|
||||
attribution: attributionCode,
|
||||
blocklistEnabled: Services.prefs.getBoolPref(PREF_BLOCKLIST_ENABLED, true),
|
||||
e10sEnabled: Services.appinfo.browserTabsRemoteAutostart,
|
||||
e10sMultiProcesses: Services.appinfo.maxWebProcessCount,
|
||||
@ -1388,6 +1382,7 @@ EnvironmentCache.prototype = {
|
||||
this._currentEnvironment.settings.addonCompatibilityCheckEnabled =
|
||||
AddonManager.checkCompatibility;
|
||||
|
||||
this._updateAttribution();
|
||||
this._updateDefaultBrowser();
|
||||
this._updateSearchEngine();
|
||||
},
|
||||
@ -1425,18 +1420,42 @@ EnvironmentCache.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Update the cached attribution data object.
|
||||
* Load the attribution data object and updates the environment.
|
||||
* @returns Promise<> resolved when the I/O is complete.
|
||||
*/
|
||||
async _updateAttribution() {
|
||||
let data = await AttributionCode.getAttrDataAsync();
|
||||
if (Object.keys(data).length > 0) {
|
||||
this._currentEnvironment.settings.attribution = {};
|
||||
for (let key in data) {
|
||||
this._currentEnvironment.settings.attribution[key] =
|
||||
limitStringToLength(data[key], MAX_ATTRIBUTION_STRING_LENGTH);
|
||||
}
|
||||
async _loadAttributionAsync() {
|
||||
try {
|
||||
await AttributionCode.getAttrDataAsync();
|
||||
} catch (e) {
|
||||
// The AttributionCode.jsm module might not be always available
|
||||
// (e.g. tests). Gracefully handle this.
|
||||
return;
|
||||
}
|
||||
this._updateAttribution();
|
||||
},
|
||||
|
||||
/**
|
||||
* Update the environment with the cached attribution data.
|
||||
*/
|
||||
_updateAttribution() {
|
||||
let data = null;
|
||||
try {
|
||||
data = AttributionCode.getCachedAttributionData();
|
||||
} catch (e) {
|
||||
// The AttributionCode.jsm module might not be always available
|
||||
// (e.g. tests). Gracefully handle this.
|
||||
}
|
||||
|
||||
if (!data || !Object.keys(data).length) {
|
||||
return;
|
||||
}
|
||||
|
||||
let attributionData = {};
|
||||
for (let key in data) {
|
||||
attributionData[key] =
|
||||
limitStringToLength(data[key], MAX_ATTRIBUTION_STRING_LENGTH);
|
||||
}
|
||||
this._currentEnvironment.settings.attribution = attributionData;
|
||||
},
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user