Bug 1404105 - Sanitize.js must check if QuotaManager returns an error before continuing with cleaning data, r=janv
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 16 Oct 2017 11:50:01 +0200
changeset 680880 b767da767ec5030116f1de62fdd84a4e3c59e946
parent 680879 c49fa16162cb7161e942421f0b7d2f428e46e38c
child 680881 a52945a497c89cca6b8edb746837218dbd64e61d
push id84661
push userbmo:ttromey@mozilla.com
push dateMon, 16 Oct 2017 14:19:39 +0000
reviewersjanv
bugs1404105
milestone58.0a1
Bug 1404105 - Sanitize.js must check if QuotaManager returns an error before continuing with cleaning data, r=janv
browser/base/content/sanitize.js
browser/components/extensions/ext-browsingData.js
--- a/browser/base/content/sanitize.js
+++ b/browser/base/content/sanitize.js
@@ -22,17 +22,17 @@ XPCOMUtils.defineLazyModuleGetters(this,
 
 XPCOMUtils.defineLazyServiceGetter(this, "serviceWorkerManager",
                                    "@mozilla.org/serviceworkers/manager;1",
                                    "nsIServiceWorkerManager");
 XPCOMUtils.defineLazyServiceGetter(this, "quotaManagerService",
                                    "@mozilla.org/dom/quota-manager-service;1",
                                    "nsIQuotaManagerService");
 
-var {classes: Cc, interfaces: Ci} = Components;
+var {classes: Cc, interfaces: Ci, results: Cr} = Components;
 
 /**
  * A number of iterations after which to yield time back
  * to the system.
  */
 const YIELD_PERIOD = 10;
 
 function Sanitizer() {
@@ -303,16 +303,23 @@ Sanitizer.prototype = {
           let host = sw.principal.URI.host;
           serviceWorkerManager.removeAndPropagate(host);
         }
 
         // QuotaManager
         let promises = [];
         await new Promise(resolve => {
           quotaManagerService.getUsage(request => {
+            if (request.resultCode != Cr.NS_OK) {
+              // We are probably shutting down. We don't want to propagate the
+              // error, rejecting the promise.
+              resolve();
+              return;
+            }
+
             for (let item of request.result) {
               let principal = Services.scriptSecurityManager.createCodebasePrincipalFromOrigin(item.origin);
               let uri = principal.URI;
               if (uri.scheme == "http" || uri.scheme == "https" || uri.scheme == "file") {
                 promises.push(new Promise(r => {
                   let req = quotaManagerService.clearStoragesForPrincipal(principal, null, false);
                   req.callback = () => { r(); };
                 }));
--- a/browser/components/extensions/ext-browsingData.js
+++ b/browser/components/extensions/ext-browsingData.js
@@ -83,16 +83,23 @@ const clearHistory = options => {
   return sanitizer.items.history.clear(makeRange(options));
 };
 
 const clearIndexedDB = async function(options) {
   let promises = [];
 
   await new Promise(resolve => {
     quotaManagerService.getUsage(request => {
+      if (request.resultCode != Components.results.NS_OK) {
+        // We are probably shutting down. We don't want to propagate the error,
+        // rejecting the promise.
+        resolve();
+        return;
+      }
+
       for (let item of request.result) {
         let principal = Services.scriptSecurityManager.createCodebasePrincipalFromOrigin(item.origin);
         let uri = principal.URI;
         if (uri.scheme == "http" || uri.scheme == "https" || uri.scheme == "file") {
           promises.push(new Promise(r => {
             let req = quotaManagerService.clearStoragesForPrincipal(principal, null, false);
             req.callback = () => { r(); };
           }));