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
--- 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); },