Bug 1245065 - Making sanitize.js handle properly nsCookieService shutdown;r?mak draft
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Fri, 05 Feb 2016 13:53:13 +0100
changeset 329189 9e366f40a1706b3dff2e220de195594eb0d20507
parent 328969 5e024441510f6d2b460e570d0e6d2dee0dc89723
child 513923 a5a5deddb7bc0606974a9581b1b7d848a8882f17
push id10486
push userdteller@mozilla.com
push dateFri, 05 Feb 2016 15:52:48 +0000
reviewersmak
bugs1245065, 1245578
milestone47.0a1
Bug 1245065 - Making sanitize.js handle properly nsCookieService shutdown;r?mak These days, the sanitizer often attempts to cleanup cookies during shutdown *after* the cookie service has been disconnected, hence when it is too late. This causes privacy issues and is suspected of causing shutdown hangs/crashes. Bug 1245578 introduces a shutdownClient for the nsCookieService. In this patch, we make use of this shutdownClient to properly handle sanitization of the cookies during shutdown.
browser/base/content/sanitize.js
--- a/browser/base/content/sanitize.js
+++ b/browser/base/content/sanitize.js
@@ -689,32 +689,39 @@ Sanitizer.showUI = function(aParentWindo
 Sanitizer.sanitize = function(aParentWindow)
 {
   Sanitizer.showUI(aParentWindow);
 };
 
 Sanitizer.onStartup = Task.async(function*() {
   // Make sure that we are triggered during shutdown, at the right time,
   // and only once.
-  let placesClient = Cc["@mozilla.org/browser/nav-history-service;1"]     .getService(Ci.nsPIPlacesDatabase)
+  let placesClient = Cc["@mozilla.org/browser/nav-history-service;1"]
+     .getService(Ci.nsPIPlacesDatabase)
      .shutdownClient
      .jsclient;
+  let cookieClient = Components.classes["@mozilla.org/cookiemanager;1"]
+      .getService(Ci.nsICookieManager)
+      .shutdownClient
+      .jsclient;
 
   let deferredSanitization = PromiseUtils.defer();
   let sanitizationInProgress = false;
   let doSanitize = function() {
     if (sanitizationInProgress) {
       return deferredSanitization.promise;
     }
     sanitizationInProgress = true;
     Sanitizer.onShutdown().catch(er => {Promise.reject(er) /* Do not return rejected promise */;}).then(() =>
       deferredSanitization.resolve()
     );
+    return deferredSanitization.promise;
   }
   placesClient.addBlocker("sanitize.js: Sanitize on shutdown", doSanitize);
+  cookieClient.addBlocker("sanitize.js: Sanitize on shutdown", doSanitize);
 
   // Handle incomplete sanitizations
   if (Preferences.has(Sanitizer.PREF_SANITIZE_IN_PROGRESS)) {
     // Firefox crashed during sanitization.
     let s = new Sanitizer();
     let json = Preferences.get(Sanitizer.PREF_SANITIZE_IN_PROGRESS);
     let itemsToClear = JSON.parse(json);
     yield s.sanitize(itemsToClear);