Bug 888784 - Make sure Fennec's Sanitizer.jsm resolves a clearing Promise only after a data clearing attempt has finished. r?Grisha draft
authorMike Conley <mconley@mozilla.com>
Tue, 09 Jan 2018 15:48:33 -0500
changeset 723117 402a7c0cbd467b52841f7ae8a2e08a104572d0bb
parent 723116 9695f645a9e79b9b885701974e8699975fcd5f17
child 723118 248a1bd926505df4712d228662e8913969f9ed38
push id96341
push usermconley@mozilla.com
push dateMon, 22 Jan 2018 16:46:17 +0000
reviewersGrisha
bugs888784
milestone60.0a1
Bug 888784 - Make sure Fennec's Sanitizer.jsm resolves a clearing Promise only after a data clearing attempt has finished. r?Grisha MozReview-Commit-ID: 62JjwgozS5b
mobile/android/modules/Sanitizer.jsm
--- a/mobile/android/modules/Sanitizer.jsm
+++ b/mobile/android/modules/Sanitizer.jsm
@@ -50,20 +50,26 @@ Sanitizer.prototype = {
       return this._clear(aItemName);
     }
   },
 
  _clear: function(aItemName, options) {
     let item = this.items[aItemName];
     let canClear = item.canClear;
     if (typeof canClear == "function") {
-      canClear(function clearCallback(aCanClear) {
-        if (aCanClear)
+      let maybeDoClear = async () => {
+        let canClearResult = await new Promise(resolve => {
+          canClear(resolve);
+        });
+
+        if (canClearResult) {
           return item.clear(options);
-      });
+        }
+      };
+      return maybeDoClear();
     } else if (canClear) {
       return item.clear(options);
     }
   },
 
   items: {
     cache: {
       clear: function() {
@@ -232,20 +238,22 @@ Sanitizer.prototype = {
           let refObj = {};
           TelemetryStopwatch.start("FX_SANITIZE_FORMDATA", refObj);
 
           // Conver time to microseconds
           let time = startTime * 1000;
           FormHistory.update({
             op: "remove",
             firstUsedStart: time
+          }, {
+            handleCompletion() {
+              TelemetryStopwatch.finish("FX_SANITIZE_FORMDATA", refObj);
+              resolve();
+            }
           });
-
-          TelemetryStopwatch.finish("FX_SANITIZE_FORMDATA", refObj);
-          resolve();
         });
       },
 
       canClear: function(aCallback) {
         let count = 0;
         let countDone = {
           handleResult: function(aResult) { count = aResult; },
           handleError: function(aError) { Cu.reportError(aError); },