Bug 1563023 - Part 8: Ignore quota cache if the user loads the same profile in different builds; r=asuth
authorJan Varga <jan.varga@gmail.com>
Sun, 25 Aug 2019 00:45:19 +0000
changeset 489776 d20d9464030e410e8327a86d2f4abecfc22d9471
parent 489775 3d2a85653d22dd6dbac45354da3b83259830d9f8
child 489777 7c0c4b630628342a07e3d5c5cf6b247c835a4718
push id36483
push userbtara@mozilla.com
push dateSun, 25 Aug 2019 09:40:15 +0000
treeherdermozilla-central@5e92e40b13de [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1563023
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1563023 - Part 8: Ignore quota cache if the user loads the same profile in different builds; r=asuth This patch adds support for quota cache invalidation if the profile is loaded in different builds. Differential Revision: https://phabricator.services.mozilla.com/D39673
dom/quota/ActorsParent.cpp
dom/quota/QuotaManager.h
toolkit/xre/nsAppRunner.cpp
--- a/dom/quota/ActorsParent.cpp
+++ b/dom/quota/ActorsParent.cpp
@@ -1835,16 +1835,17 @@ void ReportInternalError(const char* aFi
       NS_ConvertUTF8toUTF16(
           nsPrintfCString("Quota %s: %s:%" PRIu32, aStr, aFile, aLine)),
       "quota", false /* Quota Manager is not active in private browsing mode */,
       true /* Quota Manager runs always in a chrome context */);
 }
 
 namespace {
 
+bool gInvalidateQuotaCache = false;
 StaticAutoPtr<nsString> gBaseDirPath;
 StaticAutoPtr<nsCString> gBuildId;
 
 #ifdef DEBUG
 bool gQuotaManagerInitialized = false;
 #endif
 
 StaticRefPtr<QuotaManager> gInstance;
@@ -6475,16 +6476,25 @@ nsresult QuotaManager::EnsureStorageIsIn
     }
 
     rv = transaction.Commit();
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
+  if (cacheUsable && gInvalidateQuotaCache) {
+    rv = InvalidateCache(connection);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
+
+    gInvalidateQuotaCache = false;
+  }
+
   mStorageConnection = connection;
   mCacheUsable = cacheUsable;
 
   return NS_OK;
 }
 
 already_AddRefed<DirectoryLock> QuotaManager::CreateDirectoryLock(
     PersistenceType aPersistenceType, const nsACString& aGroup,
@@ -7170,16 +7180,21 @@ bool QuotaManager::ParseOrigin(const nsA
       OriginParser::ParseOrigin(sanitizedOrigin, aSpec, aAttrs);
   if (NS_WARN_IF(result != OriginParser::ValidOrigin)) {
     return false;
   }
 
   return true;
 }
 
+// static
+void QuotaManager::InvalidateQuotaCache() {
+  gInvalidateQuotaCache = true;
+}
+
 uint64_t QuotaManager::LockedCollectOriginsForEviction(
     uint64_t aMinSizeToBeFreed, nsTArray<RefPtr<DirectoryLockImpl>>& aLocks) {
   mQuotaMutex.AssertCurrentThreadOwns();
 
   RefPtr<CollectOriginsHelper> helper =
       new CollectOriginsHelper(mQuotaMutex, aMinSizeToBeFreed);
 
   // Unlock while calling out to XPCOM (code behind the dispatch method needs
--- a/dom/quota/QuotaManager.h
+++ b/dom/quota/QuotaManager.h
@@ -425,16 +425,18 @@ class QuotaManager final : public Backgr
 
   static void ChromeOrigin(nsACString& aOrigin);
 
   static bool AreOriginsEqualOnDisk(nsACString& aOrigin1, nsACString& aOrigin2);
 
   static bool ParseOrigin(const nsACString& aOrigin, nsCString& aSpec,
                           OriginAttributes* aAttrs);
 
+  static void InvalidateQuotaCache();
+
  private:
   QuotaManager();
 
   virtual ~QuotaManager();
 
   nsresult Init(const nsAString& aBaseDirPath);
 
   void Shutdown();
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -92,16 +92,17 @@
 #include "nsIWindowWatcher.h"
 #include "nsIXULAppInfo.h"
 #include "nsIXULRuntime.h"
 #include "nsPIDOMWindow.h"
 #include "nsIBaseWindow.h"
 #include "nsIWidget.h"
 #include "nsIDocShell.h"
 #include "nsAppShellCID.h"
+#include "mozilla/dom/quota/QuotaManager.h"
 #include "mozilla/scache/StartupCache.h"
 #include "gfxPlatform.h"
 
 #include "mozilla/Unused.h"
 
 #ifdef XP_WIN
 #  include "nsIWinAppHelper.h"
 #  include <windows.h>
@@ -315,16 +316,17 @@ namespace mozilla {
 int (*RunGTest)(int*, char**) = 0;
 }  // namespace mozilla
 
 using namespace mozilla;
 using namespace mozilla::startup;
 using mozilla::Unused;
 using mozilla::dom::ContentChild;
 using mozilla::dom::ContentParent;
+using mozilla::dom::quota::QuotaManager;
 using mozilla::intl::LocaleService;
 using mozilla::scache::StartupCache;
 
 // Save the given word to the specified environment variable.
 static void MOZ_NEVER_INLINE SaveWordToEnv(const char* name,
                                            const nsACString& word) {
   char* expr =
       Smprintf("%s=%s", name, PromiseFlatCString(word).get()).release();
@@ -4165,16 +4167,18 @@ int XREMain::XRE_mainStartup(bool* aExit
   // the fastload caches.  On subsequent launches if the version matches,
   // there is no need for re-registration.  If the user loads the same
   // profile in different builds the component registry must be
   // re-generated to prevent mysterious component loading failures.
   //
   bool startupCacheValid = true;
 
   if (!cachesOK || !versionOK) {
+    QuotaManager::InvalidateQuotaCache();
+
     startupCacheValid = RemoveComponentRegistries(mProfD, mProfLD, false);
 
     // Rewrite compatibility.ini to match the current build. The next run
     // should attempt to invalidate the caches if either this run is safe mode
     // or the attempt to invalidate the caches this time failed.
     WriteVersion(mProfD, version, osABI, mDirProvider.GetGREDir(),
                  mAppData->directory, gSafeMode || !startupCacheValid);
   }