Bug 1532203 - Implement deleteByHost for NetworkCacheCleaner and ImageCacheCleaner. r=baku a=pascalc
authorJohann Hofmann <jhofmann@mozilla.com>
Fri, 05 Apr 2019 09:57:34 +0000
changeset 526077 ac28441f833283523b427725e0cd8d73efe0fab9
parent 526076 ac8fd50744deeb18bff0acc50937d830683964f1
child 526078 4d6bd72cdc0e4bc282d5fada476ae7b15594e131
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, pascalc
bugs1532203
milestone67.0
Bug 1532203 - Implement deleteByHost for NetworkCacheCleaner and ImageCacheCleaner. r=baku a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D23491
toolkit/components/cleardata/ClearDataService.jsm
toolkit/forgetaboutsite/ForgetAboutSite.jsm
--- a/toolkit/components/cleardata/ClearDataService.jsm
+++ b/toolkit/components/cleardata/ClearDataService.jsm
@@ -80,32 +80,68 @@ const CookieCleaner = {
 
       aResolve();
     });
   },
 
 };
 
 const NetworkCacheCleaner = {
+  deleteByHost(aHost, aOriginAttributes) {
+    return new Promise(aResolve => {
+      // Delete data from both HTTP and HTTPS sites.
+      let httpURI = Services.io.newURI("http://" + aHost);
+      let httpsURI = Services.io.newURI("https://" + aHost);
+      let httpPrincipal = Services.scriptSecurityManager
+                                   .createCodebasePrincipal(httpURI, aOriginAttributes);
+      let httpsPrincipal = Services.scriptSecurityManager
+                                   .createCodebasePrincipal(httpsURI, aOriginAttributes);
+
+      Services.cache2.clearOrigin(httpPrincipal);
+      Services.cache2.clearOrigin(httpsPrincipal);
+      aResolve();
+    });
+  },
+
   deleteByPrincipal(aPrincipal) {
     return new Promise(aResolve => {
-      Services.cache2.asyncClearOrigin(aPrincipal);
+      Services.cache2.clearOrigin(aPrincipal);
       aResolve();
     });
   },
 
   deleteAll() {
     return new Promise(aResolve => {
       Services.cache2.clear();
       aResolve();
     });
   },
 };
 
 const ImageCacheCleaner = {
+  deleteByHost(aHost, aOriginAttributes) {
+    return new Promise(aResolve => {
+      let imageCache = Cc["@mozilla.org/image/tools;1"]
+                         .getService(Ci.imgITools)
+                         .getImgCacheForDocument(null);
+
+      // Delete data from both HTTP and HTTPS sites.
+      let httpURI = Services.io.newURI("http://" + aHost);
+      let httpsURI = Services.io.newURI("https://" + aHost);
+      let httpPrincipal = Services.scriptSecurityManager
+                                   .createCodebasePrincipal(httpURI, aOriginAttributes);
+      let httpsPrincipal = Services.scriptSecurityManager
+                                   .createCodebasePrincipal(httpsURI, aOriginAttributes);
+
+      imageCache.removeEntriesFromPrincipal(httpPrincipal);
+      imageCache.removeEntriesFromPrincipal(httpsPrincipal);
+      aResolve();
+    });
+  },
+
   deleteByPrincipal(aPrincipal) {
     return new Promise(aResolve => {
       let imageCache = Cc["@mozilla.org/image/tools;1"]
                          .getService(Ci.imgITools)
                          .getImgCacheForDocument(null);
       imageCache.removeEntriesFromPrincipal(aPrincipal);
       aResolve();
     });
@@ -895,16 +931,19 @@ ClearDataService.prototype = Object.free
   // This internal method uses aFlags against FLAGS_MAP in order to retrieve a
   // list of 'Cleaners'. For each of them, the aHelper callback retrieves a
   // promise object. All these promise objects are resolved before calling
   // onDataDeleted.
   _deleteInternal(aFlags, aCallback, aHelper) {
     let resultFlags = 0;
     let promises = FLAGS_MAP.filter(c => aFlags & c.flag).map(c => {
       // Let's collect the failure in resultFlags.
-      return aHelper(c.cleaner).catch(() => { resultFlags |= c.flag; });
+      return aHelper(c.cleaner).catch(e => {
+        Cu.reportError(e);
+        resultFlags |= c.flag;
+      });
     });
     Promise.all(promises).then(() => { aCallback.onDataDeleted(resultFlags); });
     return Cr.NS_OK;
   },
 });
 
 var EXPORTED_SYMBOLS = ["ClearDataService"];
--- a/toolkit/forgetaboutsite/ForgetAboutSite.jsm
+++ b/toolkit/forgetaboutsite/ForgetAboutSite.jsm
@@ -5,32 +5,22 @@
 "use strict";
 
 const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 var EXPORTED_SYMBOLS = ["ForgetAboutSite"];
 
 var ForgetAboutSite = {
   async removeDataFromDomain(aDomain) {
-    let promises = [];
-    let errorCount = 0;
-
-    ["http://", "https://"].forEach(scheme => {
-      promises.push(new Promise(resolve => {
-        Services.clearData.deleteDataFromHost(aDomain, true /* user request */,
-                                              Ci.nsIClearDataService.CLEAR_FORGET_ABOUT_SITE,
-                                              value => {
-          errorCount += bitCounting(value);
-          resolve();
-        });
-      }));
+    let errorCount = await new Promise(resolve => {
+      Services.clearData.deleteDataFromHost(aDomain, true /* user request */,
+                                            Ci.nsIClearDataService.CLEAR_FORGET_ABOUT_SITE,
+                                            errorCode => resolve(bitCounting(errorCode)));
     });
 
-    await Promise.all(promises);
-
     if (errorCount !== 0) {
       throw new Error(`There were a total of ${errorCount} errors during removal`);
     }
   },
 };
 
 function bitCounting(value) {
   // To know more about how to count bits set to 1 in a numeric value, see this