Bug 1286798 - Part 47: Add AboutToClearOrigins() method to the quota client interface; r=asuth draft
authorJan Varga <jan.varga@gmail.com>
Wed, 24 Oct 2018 06:59:10 +0200
changeset 481725 cf3015b13f989acc8dd401d057b2458fe25067f9
parent 481724 93b458d08f0881bf310e7b063e6c8bdc9ccd2e2a
child 481726 050bd30da968d942447f19eb1a9879e3ac1d89d7
push id10
push userbugmail@asutherland.org
push dateSun, 18 Nov 2018 18:57:42 +0000
reviewersasuth
bugs1286798
milestone65.0a1
Bug 1286798 - Part 47: Add AboutToClearOrigins() method to the quota client interface; r=asuth
dom/quota/ActorsParent.cpp
dom/quota/Client.h
dom/quota/QuotaManager.h
--- a/dom/quota/ActorsParent.cpp
+++ b/dom/quota/ActorsParent.cpp
@@ -5795,16 +5795,45 @@ QuotaManager::EnsureOriginDirectory(nsIF
   rv = EnsureDirectory(aDirectory, aCreated);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
+nsresult
+QuotaManager::AboutToClearOrigins(
+                              const Nullable<PersistenceType>& aPersistenceType,
+                              const OriginScope& aOriginScope,
+                              const Nullable<Client::Type>& aClientType)
+{
+  AssertIsOnIOThread();
+
+  nsresult rv;
+
+  if (aClientType.IsNull()) {
+    for (uint32_t index = 0; index < uint32_t(Client::TypeMax()); index++) {
+      rv = mClients[index]->AboutToClearOrigins(aPersistenceType,
+                                                aOriginScope);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+    }
+  } else {
+    rv = mClients[aClientType.Value()]->AboutToClearOrigins(aPersistenceType,
+                                                            aOriginScope);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
+  }
+
+  return NS_OK;
+}
+
 void
 QuotaManager::OriginClearCompleted(PersistenceType aPersistenceType,
                                    const nsACString& aOrigin,
                                    const Nullable<Client::Type>& aClientType)
 {
   AssertIsOnIOThread();
 
   if (aClientType.IsNull()) {
@@ -7871,20 +7900,28 @@ InitOriginOp::GetResponse(RequestRespons
 }
 
 void
 ResetOrClearOp::DeleteFiles(QuotaManager* aQuotaManager)
 {
   AssertIsOnIOThread();
   MOZ_ASSERT(aQuotaManager);
 
+  nsresult rv =
+    aQuotaManager->AboutToClearOrigins(Nullable<PersistenceType>(),
+                                       OriginScope::FromNull(),
+                                       Nullable<Client::Type>());
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return;
+  }
 
   nsCOMPtr<nsIFile> directory;
-  nsresult rv = NS_NewLocalFile(aQuotaManager->GetStoragePath(), false,
-                                getter_AddRefs(directory));
+  rv = NS_NewLocalFile(aQuotaManager->GetStoragePath(),
+                       false,
+                       getter_AddRefs(directory));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return;
   }
 
   rv = directory->Remove(true);
   if (rv != NS_ERROR_FILE_TARGET_DOES_NOT_EXIST &&
       rv != NS_ERROR_FILE_NOT_FOUND && NS_FAILED(rv)) {
     // This should never fail if we've closed all storage connections
@@ -7944,19 +7981,29 @@ ResetOrClearOp::GetResponse(RequestRespo
 
 void
 ClearRequestBase::DeleteFiles(QuotaManager* aQuotaManager,
                               PersistenceType aPersistenceType)
 {
   AssertIsOnIOThread();
   MOZ_ASSERT(aQuotaManager);
 
+  nsresult rv =
+    aQuotaManager->AboutToClearOrigins(
+                                    Nullable<PersistenceType>(aPersistenceType),
+                                    mOriginScope,
+                                    mClientType);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return;
+  }
+
   nsCOMPtr<nsIFile> directory;
-  nsresult rv = NS_NewLocalFile(aQuotaManager->GetStoragePath(aPersistenceType),
-                                false, getter_AddRefs(directory));
+  rv = NS_NewLocalFile(aQuotaManager->GetStoragePath(aPersistenceType),
+                       false,
+                       getter_AddRefs(directory));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return;
   }
 
   nsCOMPtr<nsIDirectoryEnumerator> entries;
   if (NS_WARN_IF(NS_FAILED(
         directory->GetDirectoryEntries(getter_AddRefs(entries)))) || !entries) {
     return;
--- a/dom/quota/Client.h
+++ b/dom/quota/Client.h
@@ -20,16 +20,17 @@ class nsIRunnable;
 #define IDB_DIRECTORY_NAME "idb"
 #define ASMJSCACHE_DIRECTORY_NAME "asmjs"
 #define DOMCACHE_DIRECTORY_NAME "cache"
 #define SDB_DIRECTORY_NAME "sdb"
 #define LS_DIRECTORY_NAME "ls"
 
 BEGIN_QUOTA_NAMESPACE
 
+class OriginScope;
 class QuotaManager;
 class UsageInfo;
 
 // An abstract interface for quota manager clients.
 // Each storage API must provide an implementation of this interface in order
 // to participate in centralized quota and storage handling.
 class Client
 {
@@ -162,16 +163,25 @@ public:
 
   virtual nsresult
   GetUsageForOrigin(PersistenceType aPersistenceType,
                     const nsACString& aGroup,
                     const nsACString& aOrigin,
                     const AtomicBool& aCanceled,
                     UsageInfo* aUsageInfo) = 0;
 
+  // This method is called when origins are about to be cleared
+  // (except the case when clearing is triggered by the origin eviction).
+  virtual nsresult
+  AboutToClearOrigins(const Nullable<PersistenceType>& aPersistenceType,
+                      const OriginScope& aOriginScope)
+  {
+    return NS_OK;
+  }
+
   virtual void
   OnOriginClearCompleted(PersistenceType aPersistenceType,
                          const nsACString& aOrigin) = 0;
 
   virtual void
   ReleaseIOThreadObjects() = 0;
 
   // Methods which are called on the background thread.
--- a/dom/quota/QuotaManager.h
+++ b/dom/quota/QuotaManager.h
@@ -306,16 +306,21 @@ public:
   nsresult
   EnsureTemporaryStorageIsInitialized();
 
   nsresult
   EnsureOriginDirectory(nsIFile* aDirectory,
                         bool aCreateIfNotExists,
                         bool* aCreated);
 
+  nsresult
+  AboutToClearOrigins(const Nullable<PersistenceType>& aPersistenceType,
+                      const OriginScope& aOriginScope,
+                      const Nullable<Client::Type>& aClientType);
+
   void
   OriginClearCompleted(PersistenceType aPersistenceType,
                        const nsACString& aOrigin,
                        const Nullable<Client::Type>& aClientType);
 
   void
   ResetOrClearCompleted();