Bug 1422365 - Introduce nsIClearDataService - part 9 - network predictor, r=johannh
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 01 Jun 2018 14:30:00 +0200
changeset 420878 470c748aeffea5535d2148c1cad67a5ca448db1b
parent 420877 3b9b4cca1b33e7034ca4eb699c856d313b3d1c3d
child 420879 876254607268d4f9ff9f3269b143d828a1279d75
push id34083
push userapavel@mozilla.com
push dateSat, 02 Jun 2018 23:03:25 +0000
treeherdermozilla-central@1f62ecdf59b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1422365
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1422365 - Introduce nsIClearDataService - part 9 - network predictor, r=johannh
browser/modules/Sanitizer.jsm
toolkit/components/cleardata/ClearDataService.js
toolkit/components/cleardata/nsIClearDataService.idl
toolkit/forgetaboutsite/ForgetAboutSite.jsm
--- a/browser/modules/Sanitizer.jsm
+++ b/browser/modules/Sanitizer.jsm
@@ -356,24 +356,16 @@ var Sanitizer = {
 
         try {
           let clearStartingTime = range ? String(range[0]) : "";
           Services.obs.notifyObservers(null, "browser:purge-session-history", clearStartingTime);
         } catch (ex) {
           seenException = ex;
         }
 
-        try {
-          let predictor = Cc["@mozilla.org/network/predictor;1"]
-                            .getService(Ci.nsINetworkPredictor);
-          predictor.reset();
-        } catch (ex) {
-          seenException = ex;
-        }
-
         if (seenException) {
           throw seenException;
         }
       }
     },
 
     formdata: {
       async clear(range) {
--- a/toolkit/components/cleardata/ClearDataService.js
+++ b/toolkit/components/cleardata/ClearDataService.js
@@ -383,16 +383,27 @@ const QuotaCleaner = {
 
             Promise.all(promises).then(exceptionThrown ? aReject : aResolve);
           });
         });
       });
   },
 };
 
+const PredictorNetworkCleaner = {
+  deleteAll() {
+    // Predictive network data - like cache, no way to clear this per
+    // domain, so just trash it all
+    let np = Cc["@mozilla.org/network/predictor;1"].
+             getService(Ci.nsINetworkPredictor);
+    np.reset();
+    return Promise.resolve();
+  },
+};
+
 // Here the map of Flags-Cleaner.
 const FLAGS_MAP = [
  { flag: Ci.nsIClearDataService.CLEAR_COOKIES,
    cleaner: CookieCleaner },
 
  { flag: Ci.nsIClearDataService.CLEAR_NETWORK_CACHE,
    cleaner: NetworkCacheCleaner },
 
@@ -411,16 +422,19 @@ const FLAGS_MAP = [
  { flag: Ci.nsIClearDataService.CLEAR_MEDIA_DEVICES,
    cleaner: MediaDevicesCleaner, },
 
  { flag: Ci.nsIClearDataService.CLEAR_APPCACHE,
    cleaner: AppCacheCleaner, },
 
  { flag: Ci.nsIClearDataService.CLEAR_DOM_QUOTA,
    cleaner: QuotaCleaner, },
+
+ { flag: Ci.nsIClearDataService.CLEAR_PREDICTOR_NETWORK_DATA,
+   cleaner: PredictorNetworkCleaner, },
 ];
 
 this.ClearDataService = function() {};
 
 ClearDataService.prototype = Object.freeze({
   classID: Components.ID("{0c06583d-7dd8-4293-b1a5-912205f779aa}"),
   QueryInterface: ChromeUtils.generateQI([Ci.nsIClearDataService]),
   _xpcom_factory: XPCOMUtils.generateSingletonFactory(ClearDataService),
--- a/toolkit/components/cleardata/nsIClearDataService.idl
+++ b/toolkit/components/cleardata/nsIClearDataService.idl
@@ -123,21 +123,25 @@ interface nsIClearDataService : nsISuppo
    */
   const uint32_t CLEAR_APPCACHE = 1 << 7;
 
   /**
    * LocalStorage, IndexedDB, ServiceWorkers, DOM Cache and so on.
    */
   const uint32_t CLEAR_DOM_QUOTA = 1 << 8;
 
+  /**
+   * Predictor network data
+   */
+  const uint32_t CLEAR_PREDICTOR_NETWORK_DATA = 1 << 9;
+
   /* TODO
   const uint32_t CLEAR_EME = 1 << 4;
   const uint32_t CLEAR_PERMISSIONS = 1 << 7;
   const uint32_t CLEAR_CONTENT_PREFERENCES = 1 << 9;
-  const uint32_t CLEAR_PREDICTOR_CACHE = 1 << 10;
   const uint32_t CLEAR_DOM_PUSH_NOTIFICATIONS = 1 << 11;
   const uint32_t CLEAR_HSTS = 1 << 12;
   const uint32_t CLEAR_HPKP = 1 << 13;
   const uint32_t CLEAR_HISTORY = 1 << 14;
   const uint32_t CLEAR_SESSION_HISTORY = 1 << 15;
   const uint32_t CLEAR_FORMDATA = 1 << 16;
   const uint32_t CLEAR_AUTH_TOKENS = 1 << 17;
   const uint32_t CLEAR_LOGINS = 1 << 18;
--- a/toolkit/forgetaboutsite/ForgetAboutSite.jsm
+++ b/toolkit/forgetaboutsite/ForgetAboutSite.jsm
@@ -88,26 +88,16 @@ var ForgetAboutSite = {
           if (reason === cps2.COMPLETE_ERROR) {
             throw new Error("Exception occured while clearing content preferences");
           }
         },
         handleError() {}
       });
     })());
 
-    // Predictive network data - like cache, no way to clear this per
-    // domain, so just trash it all
-    promises.push((async function() {
-      let np = Cc["@mozilla.org/network/predictor;1"].
-               getService(Ci.nsINetworkPredictor);
-      np.reset();
-    })().catch(ex => {
-      throw new Error("Exception occured while clearing predictive network data: " + ex);
-    }));
-
     // Push notifications.
     promises.push((async function() {
       var push = Cc["@mozilla.org/push/Service;1"].
                  getService(Ci.nsIPushService);
       push.clearForDomain(aDomain, status => {
         if (!Components.isSuccessCode(status)) {
           throw new Error("Exception occured while clearing push notifications: " + status);
         }