Bug 1286798 - Part 49: Add clearStoragesForPattern() method to the quota manager service; r=asuth draft
authorJan Varga <jan.varga@gmail.com>
Wed, 24 Oct 2018 06:59:10 +0200
changeset 481727 e2301860239fb3e343af4f53d73a06b306d3be7e
parent 481726 050bd30da968d942447f19eb1a9879e3ac1d89d7
child 481728 3f2af2a900c14028bdb1b4e81ea081627ee43cf1
push id10
push userbugmail@asutherland.org
push dateSun, 18 Nov 2018 18:57:42 +0000
reviewersasuth
bugs1286798
milestone65.0a1
Bug 1286798 - Part 49: Add clearStoragesForPattern() method to the quota manager service; r=asuth
dom/quota/QuotaManagerService.cpp
dom/quota/nsIQuotaManagerService.idl
--- a/dom/quota/QuotaManagerService.cpp
+++ b/dom/quota/QuotaManagerService.cpp
@@ -650,16 +650,39 @@ QuotaManagerService::Clear(nsIQuotaReque
     return rv;
   }
 
   request.forget(_retval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
+QuotaManagerService::ClearStoragesForPattern(const nsAString& aPattern,
+                                             nsIQuotaRequest** _retval)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  RefPtr<Request> request = new Request();
+
+  ClearDataParams params;
+
+  params.pattern() = aPattern;
+
+  nsAutoPtr<PendingRequestInfo> info(new RequestInfo(request, params));
+
+  nsresult rv = InitiateRequest(info);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  request.forget(_retval);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 QuotaManagerService::ClearStoragesForPrincipal(nsIPrincipal* aPrincipal,
                                                const nsACString& aPersistenceType,
                                                const nsAString& aClientType,
                                                bool aClearAll,
                                                nsIQuotaRequest** _retval)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aPrincipal);
@@ -841,24 +864,19 @@ QuotaManagerService::Observe(nsISupports
   MOZ_ASSERT(NS_IsMainThread());
 
   if (!strcmp(aTopic, PROFILE_BEFORE_CHANGE_QM_OBSERVER_ID)) {
     RemoveIdleObserver();
     return NS_OK;
   }
 
   if (!strcmp(aTopic, "clear-origin-attributes-data")) {
-    RefPtr<Request> request = new Request();
-
-    ClearDataParams params;
-    params.pattern() = nsDependentString(aData);
-
-    nsAutoPtr<PendingRequestInfo> info(new RequestInfo(request, params));
-
-    nsresult rv = InitiateRequest(info);
+    nsCOMPtr<nsIQuotaRequest> request;
+    nsresult rv = ClearStoragesForPattern(nsDependentString(aData),
+                                          getter_AddRefs(request));
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
     return NS_OK;
   }
 
   if (!strcmp(aTopic, OBSERVER_TOPIC_IDLE_DAILY)) {
--- a/dom/quota/nsIQuotaManagerService.idl
+++ b/dom/quota/nsIQuotaManagerService.idl
@@ -92,16 +92,26 @@ interface nsIQuotaManagerService : nsISu
    *
    * If the dom.quotaManager.testing preference is not true the call will be
    * a no-op.
    */
   [must_use] nsIQuotaRequest
   clear();
 
   /**
+   * Removes all storages stored for the given pattern. The files may not be
+   * deleted immediately depending on prohibitive concurrent operations.
+   *
+   * @param aPattern
+   *        A pattern for the origins whose storages are to be cleared.
+   */
+  [must_use] nsIQuotaRequest
+  clearStoragesForPattern(in AString aPattern);
+
+  /**
    * Removes all storages stored for the given principal. The files may not be
    * deleted immediately depending on prohibitive concurrent operations.
    *
    * @param aPrincipal
    *        A principal for the origin whose storages are to be cleared.
    * @param aPersistenceType
    *        An optional string that tells what persistence type of storages
    *        will be cleared.