diff --git a/content/xul/document/src/nsXULPrototypeCache.cpp b/content/xul/document/src/nsXULPrototypeCache.cpp index 9639526ede4a..b71fdd2518e4 100644 --- a/content/xul/document/src/nsXULPrototypeCache.cpp +++ b/content/xul/document/src/nsXULPrototypeCache.cpp @@ -145,6 +145,7 @@ NS_NewXULPrototypeCache(nsISupports* aOuter, REFNSIID aIID, void** aResult) nsXULPrototypeCache *p = result; obsSvc->AddObserver(p, "chrome-flush-skin-caches", PR_FALSE); obsSvc->AddObserver(p, "chrome-flush-caches", PR_FALSE); + obsSvc->AddObserver(p, "startupcache-invalidate", PR_FALSE); } return rv; @@ -410,10 +411,6 @@ nsXULPrototypeCache::AbortFastLoads() NS_BREAK(); #endif - // Save a strong ref to the FastLoad file, so we can remove it after we - // close open streams to it. - nsCOMPtr file = gFastLoadFile; - // Flush the XUL cache for good measure, in case we cached a bogus/downrev // script, somehow. Flush(); @@ -421,29 +418,42 @@ nsXULPrototypeCache::AbortFastLoads() // Clear the FastLoad set mFastLoadURITable.Clear(); - if (! gFastLoadService) - return; + nsCOMPtr fastLoadService = gFastLoadService; + nsCOMPtr file = gFastLoadFile; + + nsresult rv; + + if (! fastLoadService) { + fastLoadService = do_GetFastLoadService(); + if (! fastLoadService) + return; + + rv = fastLoadService->NewFastLoadFile(XUL_FASTLOAD_FILE_BASENAME, + getter_AddRefs(file)); + if (NS_FAILED(rv)) + return; + } // Fetch the current input (if FastLoad file existed) or output (if we're // creating the FastLoad file during this app startup) stream. nsCOMPtr objectInput; nsCOMPtr objectOutput; - gFastLoadService->GetInputStream(getter_AddRefs(objectInput)); - gFastLoadService->GetOutputStream(getter_AddRefs(objectOutput)); + fastLoadService->GetInputStream(getter_AddRefs(objectInput)); + fastLoadService->GetOutputStream(getter_AddRefs(objectOutput)); if (objectOutput) { - gFastLoadService->SetOutputStream(nsnull); + fastLoadService->SetOutputStream(nsnull); if (NS_SUCCEEDED(objectOutput->Close()) && gChecksumXULFastLoadFile) - gFastLoadService->CacheChecksum(gFastLoadFile, - objectOutput); + fastLoadService->CacheChecksum(file, + objectOutput); } if (objectInput) { // If this is the last of one or more XUL master documents loaded // together at app startup, close the FastLoad service's singleton // input stream now. - gFastLoadService->SetInputStream(nsnull); + fastLoadService->SetInputStream(nsnull); objectInput->Close(); } @@ -462,13 +472,15 @@ nsXULPrototypeCache::AbortFastLoads() } file->MoveToNative(nsnull, NS_LITERAL_CSTRING("Aborted.mfasl")); #else - file->Remove(PR_FALSE); + rv = file->Remove(PR_FALSE); + if (NS_FAILED(rv)) + NS_WARNING("Failed to remove fastload file, fastload data may be outdated"); #endif } // If the list is empty now, the FastLoad process is done. - NS_RELEASE(gFastLoadService); - NS_RELEASE(gFastLoadFile); + NS_IF_RELEASE(gFastLoadService); + NS_IF_RELEASE(gFastLoadFile); } diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bug594058.js b/toolkit/mozapps/extensions/test/xpcshell/test_bug594058.js index 3f8f48015829..1ed8a3638a88 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bug594058.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug594058.js @@ -12,6 +12,10 @@ const Ci = Components.interfaces; const extDir = gProfD.clone(); extDir.append("extensions"); +var gFastLoadService = AM_Cc["@mozilla.org/fast-load-service;1"]. + getService(AM_Ci.nsIFastLoadService); +var gFastLoadFile = null; + /** * Start the test by installing extensions. */ @@ -27,10 +31,19 @@ function run_test() { } }, "startupcache-invalidate", false); createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); + + gFastLoadFile = gFastLoadService.newFastLoadFile("XUL"); + do_check_false(gFastLoadFile.exists()); + gFastLoadFile.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); + startupManager(); + // nsAppRunner takes care of clearing this when a new app is installed + do_check_true(gFastLoadFile.exists()); installAllFiles([do_get_addon("test_bug594058")], function() { restartManager(); + do_check_false(gFastLoadFile.exists()); + gFastLoadFile.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); do_check_true(cachePurged); cachePurged = false; @@ -47,15 +60,20 @@ function run_test() { otherFile.lastModifiedTime = pastTime; restartManager(); + do_check_false(gFastLoadFile.exists()); + gFastLoadFile.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); cachePurged = false; otherFile.lastModifiedTime = pastTime + 5000; restartManager(); + do_check_false(gFastLoadFile.exists()); + gFastLoadFile.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); do_check_true(cachePurged); cachePurged = false; restartManager(); - do_check_true(!cachePurged); + do_check_true(gFastLoadFile.exists()); + do_check_false(cachePurged); do_test_finished(); }); diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_startup.js b/toolkit/mozapps/extensions/test/xpcshell/test_startup.js index d9d9a0c0d5c5..e3a4d87d2d8c 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_startup.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_startup.js @@ -85,11 +85,19 @@ registerDirectory("XREUSysExt", userDir.parent); const profileDir = gProfD.clone(); profileDir.append("extensions"); +var gFastLoadService = AM_Cc["@mozilla.org/fast-load-service;1"]. + getService(AM_Ci.nsIFastLoadService); +var gFastLoadFile = null; + // Set up the profile function run_test() { do_test_pending(); startupManager(); + gFastLoadFile = gFastLoadService.newFastLoadFile("XUL"); + do_check_false(gFastLoadFile.exists()); + gFastLoadFile.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); + AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", "addon2@tests.mozilla.org", "addon3@tests.mozilla.org", @@ -127,6 +135,9 @@ function run_test_1() { writeInstallRDFForExtension(addon5, profileDir); restartManager(); + do_check_false(gFastLoadFile.exists()); + gFastLoadFile.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); + AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", "addon2@tests.mozilla.org", "addon3@tests.mozilla.org", @@ -203,6 +214,8 @@ function run_test_2() { dest.remove(true); restartManager(); + do_check_false(gFastLoadFile.exists()); + gFastLoadFile.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", "addon2@tests.mozilla.org", @@ -257,6 +270,8 @@ function run_test_3() { writeInstallRDFForExtension(addon3, profileDir, "addon4@tests.mozilla.org"); restartManager(); + do_check_false(gFastLoadFile.exists()); + gFastLoadFile.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", "addon2@tests.mozilla.org", @@ -308,6 +323,8 @@ function run_test_4() { Services.prefs.setIntPref("extensions.enabledScopes", AddonManager.SCOPE_SYSTEM); restartManager(); + do_check_false(gFastLoadFile.exists()); + gFastLoadFile.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", "addon2@tests.mozilla.org", @@ -340,6 +357,8 @@ function run_test_5() { Services.prefs.setIntPref("extensions.enabledScopes", AddonManager.SCOPE_USER); restartManager(); + do_check_false(gFastLoadFile.exists()); + gFastLoadFile.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", "addon2@tests.mozilla.org", @@ -378,6 +397,8 @@ function run_test_6() { Services.prefs.clearUserPref("extensions.enabledScopes"); restartManager(); + do_check_false(gFastLoadFile.exists()); + gFastLoadFile.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", "addon2@tests.mozilla.org", @@ -420,6 +441,8 @@ function run_test_7() { dest.remove(true); restartManager(); + do_check_false(gFastLoadFile.exists()); + gFastLoadFile.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", "addon2@tests.mozilla.org", @@ -467,6 +490,8 @@ function run_test_8() { Services.prefs.setIntPref("extensions.enabledScopes", 0); restartManager(); + do_check_false(gFastLoadFile.exists()); + gFastLoadFile.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", "addon2@tests.mozilla.org", @@ -508,6 +533,8 @@ function run_test_9() { writeInstallRDFForExtension(addon2, profileDir); restartManager(); + do_check_false(gFastLoadFile.exists()); + gFastLoadFile.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", "addon2@tests.mozilla.org", @@ -558,6 +585,8 @@ function run_test_10() { writeInstallRDFForExtension(addon1, userDir); restartManager(); + do_check_false(gFastLoadFile.exists()); + gFastLoadFile.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", "addon2@tests.mozilla.org", @@ -608,6 +637,8 @@ function run_test_11() { dest.remove(true); restartManager(); + do_check_false(gFastLoadFile.exists()); + gFastLoadFile.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", "addon2@tests.mozilla.org",