Bug 1514600 - P1 - Notify LS to cleanup the gUsages while storage initialization fails; r=janv
authorTom Tung <shes050117@gmail.com>
Mon, 29 Apr 2019 10:49:58 +0000
changeset 533185 695621ee868dc607e49f848c72be87fe7a14c909
parent 533184 4b540d7c269d8319630eb4e69b0377985e163ae6
child 533186 0013ca341d7c9e7dbb6195967002e7b1963da679
push id11276
push userrgurzau@mozilla.com
push dateMon, 20 May 2019 13:11:24 +0000
treeherdermozilla-beta@847755a7c325 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjanv
bugs1514600
milestone68.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 1514600 - P1 - Notify LS to cleanup the gUsages while storage initialization fails; r=janv Differential Revision: https://phabricator.services.mozilla.com/D27502
dom/localstorage/ActorsParent.cpp
dom/quota/ActorsParent.cpp
dom/quota/Client.h
--- a/dom/localstorage/ActorsParent.cpp
+++ b/dom/localstorage/ActorsParent.cpp
@@ -2814,16 +2814,18 @@ class QuotaClient final : public mozilla
       const Nullable<PersistenceType>& aPersistenceType,
       const OriginScope& aOriginScope) override;
 
   void OnOriginClearCompleted(PersistenceType aPersistenceType,
                               const nsACString& aOrigin) override;
 
   void ReleaseIOThreadObjects() override;
 
+  void OnStorageInitFailed() override;
+
   void AbortOperations(const nsACString& aOrigin) override;
 
   void AbortOperationsForProcess(ContentParentId aContentParentId) override;
 
   void StartIdleMaintenance() override;
 
   void StopIdleMaintenance() override;
 
@@ -8800,16 +8802,24 @@ void QuotaClient::ReleaseIOThreadObjects
   gUsages = nullptr;
 
   // Delete archived origins hashtable since QuotaManager clears the whole
   // storage directory including ls-archive.sqlite.
 
   gArchivedOrigins = nullptr;
 }
 
+void QuotaClient::OnStorageInitFailed() {
+  AssertIsOnIOThread();
+  MOZ_DIAGNOSTIC_ASSERT(QuotaManager::Get());
+  MOZ_DIAGNOSTIC_ASSERT(!QuotaManager::Get()->IsTemporaryStorageInitialized());
+
+  gUsages = nullptr;
+}
+
 void QuotaClient::AbortOperations(const nsACString& aOrigin) {
   AssertIsOnBackgroundThread();
 
   // A PrepareDatastoreOp object could already acquire a directory lock for
   // the given origin. Its last step is creation of a Datastore object (which
   // will take ownership of the directory lock) and a PreparedDatastore object
   // which keeps the Datastore alive until a database actor is created.
   // We need to invalidate the PreparedDatastore object when it's created,
--- a/dom/quota/ActorsParent.cpp
+++ b/dom/quota/ActorsParent.cpp
@@ -5821,16 +5821,23 @@ nsresult QuotaManager::EnsureTemporarySt
   }
 
   TimeStamp startTime = TimeStamp::Now();
 
   // A keeper to defer the return only in Nightly, so that the telemetry data
   // for whole profile can be collected
   nsresult statusKeeper = NS_OK;
 
+  AutoTArray<RefPtr<Client>, Client::TYPE_MAX>& clients = mClients;
+  auto autoNotifier = MakeScopeExit([&clients] {
+    for (RefPtr<Client>& client : clients) {
+      client->OnStorageInitFailed();
+    }
+  });
+
   nsresult rv = InitializeRepository(PERSISTENCE_TYPE_DEFAULT);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     RECORD_IN_NIGHTLY(statusKeeper, rv);
 
 #ifndef NIGHTLY_BUILD
     // We have to cleanup partially initialized quota.
     RemoveQuota();
 
@@ -5873,16 +5880,18 @@ nsresult QuotaManager::EnsureTemporarySt
       return rv;
     }
   }
 
   mTemporaryStorageInitialized = true;
 
   CheckTemporaryStorageLimits();
 
+  autoNotifier.release();
+
   return rv;
 }
 
 nsresult QuotaManager::EnsureOriginDirectory(nsIFile* aDirectory,
                                              bool* aCreated) {
   AssertIsOnIOThread();
   MOZ_ASSERT(aDirectory);
   MOZ_ASSERT(aCreated);
--- a/dom/quota/Client.h
+++ b/dom/quota/Client.h
@@ -159,16 +159,18 @@ class Client {
     return NS_OK;
   }
 
   virtual void OnOriginClearCompleted(PersistenceType aPersistenceType,
                                       const nsACString& aOrigin) = 0;
 
   virtual void ReleaseIOThreadObjects() = 0;
 
+  virtual void OnStorageInitFailed(){};
+
   // Methods which are called on the background thread.
   virtual void AbortOperations(const nsACString& aOrigin) = 0;
 
   virtual void AbortOperationsForProcess(ContentParentId aContentParentId) = 0;
 
   virtual void StartIdleMaintenance() = 0;
 
   virtual void StopIdleMaintenance() = 0;