Bug 1286798 - Part 47: Add AboutToClearOrigins() method to the quota client interface; r=asuth
authorJan Varga <jan.varga@gmail.com>
Thu, 29 Nov 2018 21:49:46 +0100
changeset 508045 b9badcc1709de40910e1c13b7041d3d4b85d2683
parent 508044 6710732a8d0752472bc82d8fd2faba8f58e7f545
child 508046 f0721a859c7493f831df6e4e25310e9a2021ac5a
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1286798
milestone65.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 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();