mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 767320 - Cache results of Addon.hasResource() to try avoid unnecessary IO; r=Unfocused
This commit is contained in:
parent
9b34e299fa
commit
d72258e637
@ -3842,6 +3842,9 @@ var XPIProvider = {
|
||||
if (aAddon._installLocation.locked)
|
||||
throw new Error("Cannot uninstall addons from locked install locations");
|
||||
|
||||
if ("_hasResourceCache" in aAddon)
|
||||
aAddon._hasResourceCache = new Map();
|
||||
|
||||
// Inactive add-ons don't require a restart to uninstall
|
||||
let requiresRestart = this.uninstallRequiresRestart(aAddon);
|
||||
|
||||
@ -5710,8 +5713,10 @@ XPIProvider.DBAddonInternal = DBAddonInternal;
|
||||
function createWrapper(aAddon) {
|
||||
if (!aAddon)
|
||||
return null;
|
||||
if (!aAddon._wrapper)
|
||||
if (!aAddon._wrapper) {
|
||||
aAddon._hasResourceCache = new Map();
|
||||
aAddon._wrapper = new AddonWrapper(aAddon);
|
||||
}
|
||||
return aAddon._wrapper;
|
||||
}
|
||||
|
||||
@ -6106,6 +6111,9 @@ function AddonWrapper(aAddon) {
|
||||
};
|
||||
|
||||
this.hasResource = function(aPath) {
|
||||
if (aAddon._hasResourceCache.has(aPath))
|
||||
return aAddon._hasResourceCache.get(aPath);
|
||||
|
||||
let bundle = aAddon._sourceBundle.clone();
|
||||
|
||||
// Bundle may not exist any more if the addon has just been uninstalled,
|
||||
@ -6113,6 +6121,7 @@ function AddonWrapper(aAddon) {
|
||||
try {
|
||||
var isDir = bundle.isDirectory();
|
||||
} catch (e) {
|
||||
aAddon._hasResourceCache.set(aPath, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -6122,16 +6131,21 @@ function AddonWrapper(aAddon) {
|
||||
bundle.append(aPart);
|
||||
});
|
||||
}
|
||||
return bundle.exists();
|
||||
let result = bundle.exists();
|
||||
aAddon._hasResourceCache.set(aPath, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].
|
||||
createInstance(Ci.nsIZipReader);
|
||||
try {
|
||||
zipReader.open(bundle);
|
||||
return zipReader.hasEntry(aPath);
|
||||
let result = zipReader.hasEntry(aPath);
|
||||
aAddon._hasResourceCache.set(aPath, result);
|
||||
return result;
|
||||
}
|
||||
catch (e) {
|
||||
aAddon._hasResourceCache.set(aPath, false);
|
||||
return false;
|
||||
}
|
||||
finally {
|
||||
|
@ -75,12 +75,17 @@ function run_test() {
|
||||
do_check_true(false);
|
||||
}
|
||||
|
||||
restartManager();
|
||||
AddonManager.getInstallForFile(do_get_addon("test_getresource"), function(aInstall) {
|
||||
do_check_false(a1.hasResource("icon.png"));
|
||||
do_check_true(aInstall.addon.hasResource("icon.png"));
|
||||
|
||||
AddonManager.getAddonByID("addon1@tests.mozilla.org", function(newa1) {
|
||||
do_check_eq(newa1, null);
|
||||
restartManager();
|
||||
|
||||
do_test_finished();
|
||||
AddonManager.getAddonByID("addon1@tests.mozilla.org", function(newa1) {
|
||||
do_check_eq(newa1, null);
|
||||
|
||||
do_test_finished();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user