Skip to content

Commit

Permalink
Bug 760356: #1 Always request all add-ons when loading AddonRepositor…
Browse files Browse the repository at this point in the history
…y; r=unfocused

UltraBlame original commit: 60de42b54f914c88aa60dfdcae116acfe9dda9fe
  • Loading branch information
marco-c committed Sep 29, 2019
1 parent 73614c0 commit 78ac3f0
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 76 deletions.
17 changes: 8 additions & 9 deletions toolkit/mozapps/extensions/AddonManager.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -1160,39 +1160,38 @@ var AddonManagerInternal = {
Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm", scope);
scope.LightweightThemeManager.updateCurrentTheme();

let aAddons = yield new Promise((resolve, reject) => this.getAllAddons(resolve));


var ids = [a.id for each (a in aAddons) if (a.id != hotfixID)];
let allAddons = yield new Promise((resolve, reject) => this.getAllAddons(resolve));



yield new Promise((resolve, reject) => AddonRepository.backgroundUpdateCheck(ids, resolve));
yield AddonRepository.backgroundUpdateCheck();


let updates = [];

for (let aAddon of aAddons) {
if (aAddon.id == hotfixID) {
for (let addon of allAddons) {
if (addon.id == hotfixID) {
continue;
}



updates.push(new Promise((resolve, reject) => {
aAddon.findUpdates({
addon.findUpdates({
onUpdateAvailable: function BUC_onUpdateAvailable(aAddon, aInstall) {


logger.debug("Found update for add-on ${id}", aAddon);
if (aAddon.permissions & AddonManager.PERM_CAN_UPGRADE &&
AddonManager.shouldAutoUpdate(aAddon)) {


logger.debug("Starting install of ${id}", aAddon);
aInstall.install();
}
},

onUpdateFinished: resolve
onUpdateFinished: aAddon => { logger.debug("onUpdateFinished for ${id}", aAddon); resolve(); }
}, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
}));
}
Expand Down
21 changes: 10 additions & 11 deletions toolkit/mozapps/extensions/content/selectAddons.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ var gChecking = {
showButtons(true, false, false, false);
this._progress = document.getElementById("checking-progress");

let self = this;
AddonManager.getAllAddons(function gChecking_getAllAddons(aAddons) {
AddonManager.getAllAddons(aAddons => {
if (aAddons.length == 0) {
window.close();
return;
}

aAddons = aAddons.filter(function gChecking_filterAddons(aAddon) {
if (aAddon.id == AddonManager.hotfixID) {
return false;
}
if (aAddon.type == "plugin" || aAddon.type == "service")
return false;

Expand All @@ -89,15 +91,12 @@ var gChecking = {
return true;
});

self._addonCount = aAddons.length;
self._progress.value = 0;
self._progress.max = aAddons.length;
self._progress.mode = "determined";
this._addonCount = aAddons.length;
this._progress.value = 0;
this._progress.max = aAddons.length;
this._progress.mode = "determined";



let ids = [addon.id for each (addon in aAddons)];
AddonRepository.repopulateCache(ids, function gChecking_repopulateCache() {
AddonRepository.repopulateCache().then(() => {
for (let addonItem of aAddons) {

if (addonItem.type != "theme" || !addonItem.userDisabled) {
Expand All @@ -108,7 +107,7 @@ var gChecking = {
}
}

addonItem.findUpdates(self, AddonManager.UPDATE_WHEN_NEW_APP_INSTALLED);
addonItem.findUpdates(this, AddonManager.UPDATE_WHEN_NEW_APP_INSTALLED);
}
});
});
Expand Down
18 changes: 4 additions & 14 deletions toolkit/mozapps/extensions/content/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

const PREF_UPDATE_EXTENSIONS_ENABLED = "extensions.update.enabled";
const PREF_XPINSTALL_ENABLED = "xpinstall.enabled";
const PREF_EM_HOTFIX_ID = "extensions.hotfix.id";


const METADATA_TIMEOUT = 30000;
Expand Down Expand Up @@ -181,19 +180,14 @@ var gVersionInfoPage = {
"nextButtonText", true,
"cancelButtonText", false);

try {
var hotfixID = Services.prefs.getCharPref(PREF_EM_HOTFIX_ID);
}
catch (e) { }


AddonManager.getAllAddons(function gVersionInfoPage_getAllAddons(aAddons) {
AddonManager.getAllAddons(aAddons => {
if (gUpdateWizard.shuttingDown) {
logger.debug("getAllAddons completed after dialog closed");
}

gUpdateWizard.addons = [a for (a of aAddons)
if (a.type != "plugin" && a.id != hotfixID)];
if (a.type != "plugin" && a.id != AddonManager.hotfixID)];

gVersionInfoPage._totalCount = gUpdateWizard.addons.length;

Expand All @@ -206,12 +200,8 @@ var gVersionInfoPage = {



let ids = [addon.id for (addon of gUpdateWizard.addons)];


AddonManager.addAddonListener(listener);
AddonRepository.repopulateCache(ids, function gVersionInfoPage_repopulateCache() {

AddonRepository.repopulateCache(METADATA_TIMEOUT).then(() => {
if (gUpdateWizard.shuttingDown) {
logger.debug("repopulateCache completed after dialog closed");
}
Expand All @@ -220,7 +210,7 @@ var gVersionInfoPage = {
logger.debug("VersionInfo Finding updates for " + addon.id);
addon.findUpdates(gVersionInfoPage, AddonManager.UPDATE_WHEN_NEW_APP_INSTALLED);
}
}, METADATA_TIMEOUT);
});
});
},

Expand Down
76 changes: 44 additions & 32 deletions toolkit/mozapps/extensions/internal/AddonRepository.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -601,52 +601,66 @@ this.AddonRepository = {



repopulateCache: function(aTimeout) {
return this._repopulateCacheInternal(false, aTimeout);
},





repopulateCache: function(aIds, aCallback, aTimeout) {
this._repopulateCacheInternal(aIds, aCallback, false, aTimeout);
_clearCache: function () {
this._addons = null;
this._pendingCallbacks = null;
return AddonDatabase.delete().then(() =>
new Promise((resolve, reject) =>
AddonManagerPrivate.updateAddonRepositoryData(resolve))
);
},

_repopulateCacheInternal: function (aIds, aCallback, aSendPerformance, aTimeout) {
_repopulateCacheInternal: Task.async(function* (aSendPerformance, aTimeout) {
let allAddons = yield new Promise((resolve, reject) =>
AddonManager.getAllAddons(resolve));


function repopulateAddonManager() {
AddonManagerPrivate.updateAddonRepositoryData(aCallback);
}
let allAddons = [a for (a of allAddons) if (a.id != AddonManager.hotfixID)];

logger.debug("Repopulate add-on cache with " + aIds.toSource());

if (!this.cacheEnabled) {
logger.debug("Clearing cache because it is disabled");
this._addons = null;
this._pendingCallbacks = null;
AddonDatabase.delete(repopulateAddonManager);
return;
return this._clearCache();
}

let ids = [a.id for (a of allAddons)];
logger.debug("Repopulate add-on cache with " + ids.toSource());

let self = this;
getAddonsToCache(aIds, function repopulateCache_getAddonsToCache(aAddons) {

if (aAddons.length == 0) {
logger.debug("Clearing cache because 0 add-ons were requested");
self._addons = null;
self._pendingCallbacks = null;
AddonDatabase.delete(repopulateAddonManager);
return;
}
let addonsToCache = yield new Promise((resolve, reject) =>
getAddonsToCache(ids, resolve));


if (addonsToCache.length == 0) {
logger.debug("Clearing cache because 0 add-ons were requested");
return this._clearCache();
}

self._beginGetAddons(aAddons, {
yield new Promise((resolve, reject) =>
self._beginGetAddons(addonsToCache, {
searchSucceeded: function repopulateCacheInternal_searchSucceeded(aAddons) {
self._addons = {};
aAddons.forEach(function(aAddon) { self._addons[aAddon.id] = aAddon; });
AddonDatabase.repopulate(aAddons, repopulateAddonManager);
AddonDatabase.repopulate(aAddons, resolve);
},
searchFailed: function repopulateCacheInternal_searchFailed() {
logger.warn("Search failed when repopulating cache");
repopulateAddonManager();
resolve();
}
}, aSendPerformance, aTimeout);
});
},
}, aSendPerformance, aTimeout));


yield new Promise((resolve, reject) =>
AddonManagerPrivate.updateAddonRepositoryData(resolve));
}),



Expand Down Expand Up @@ -864,12 +878,8 @@ this.AddonRepository = {







backgroundUpdateCheck: function AddonRepo_backgroundUpdateCheck(aIDs, aCallback) {
this._repopulateCacheInternal(aIDs, aCallback, true);
backgroundUpdateCheck: function () {
return this._repopulateCacheInternal(true);
},


Expand Down Expand Up @@ -1653,6 +1663,7 @@ var AddonDatabase = {




delete: function AD_delete(aCallback) {
this.DB = BLANK_DB();

Expand All @@ -1665,6 +1676,7 @@ var AddonDatabase = {
this.jsonFile, error))
.then(() => this._deleting = null)
.then(aCallback);
return this._deleting;
},

toJSON: function AD_toJSON() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,35 +551,31 @@ add_task(function* run_test_3() {
Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true);
Services.prefs.setCharPref(PREF_GETADDONS_BYIDS, GETADDONS_FAILED);

yield new Promise((resolve, reject) =>
AddonRepository.repopulateCache(ADDON_IDS, resolve));
yield AddonRepository.repopulateCache();
yield check_initialized_cache([false, false, false]);
});


add_task(function* run_test_4() {
Services.prefs.setCharPref(PREF_GETADDONS_BYIDS, GETADDONS_EMPTY);

yield new Promise((resolve, reject) =>
AddonRepository.repopulateCache(ADDON_IDS, resolve));
yield AddonRepository.repopulateCache();
yield check_initialized_cache([false, false, false]);
});


add_task(function* run_test_5() {
Services.prefs.setCharPref(PREF_GETADDONS_BYIDS, GETADDONS_RESULTS);

yield new Promise((resolve, reject) =>
AddonRepository.repopulateCache(ADDON_IDS, resolve));
yield AddonRepository.repopulateCache();
yield check_initialized_cache([true, true, true]);
});


add_task(function* run_test_5_1() {
Services.prefs.setBoolPref(PREF_ADDON0_CACHE_ENABLED, false);

yield new Promise((resolve, reject) =>
AddonRepository.repopulateCache(ADDON_IDS, resolve));
yield AddonRepository.repopulateCache();


Services.prefs.setBoolPref(PREF_ADDON0_CACHE_ENABLED, true);
Expand All @@ -592,8 +588,7 @@ add_task(function* run_test_6() {
do_check_true(gDBFile.exists());
Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, false);

yield new Promise((resolve, reject) =>
AddonRepository.repopulateCache(ADDON_IDS, resolve));
yield AddonRepository.repopulateCache();

do_check_false(gDBFile.exists());

Expand Down

0 comments on commit 78ac3f0

Please sign in to comment.