Bug 1422365 - Introduce nsIClearDataService - part 11 - history, r=johannh
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 01 Jun 2018 14:30:01 +0200
changeset 475098 59a46331ca79bc5851fc38c98a7429717fbec69f
parent 475097 876254607268d4f9ff9f3269b143d828a1279d75
child 475099 22de53cb87c4a41098bd7a3b2569bf05f1f753cd
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [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 11 - history, 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
@@ -330,45 +330,23 @@ var Sanitizer = {
     offlineApps: {
       async clear(range) {
         await clearData(range, Ci.nsIClearDataService.CLEAR_DOM_STORAGES);
       }
     },
 
     history: {
       async clear(range) {
-        let seenException;
         let refObj = {};
         TelemetryStopwatch.start("FX_SANITIZE_HISTORY", refObj);
-        try {
-          if (range) {
-            await PlacesUtils.history.removeVisitsByFilter({
-              beginDate: new Date(range[0] / 1000),
-              endDate: new Date(range[1] / 1000)
-            });
-          } else {
-            // Remove everything.
-            await PlacesUtils.history.clear();
-          }
-        } catch (ex) {
-          seenException = ex;
-        } finally {
-          TelemetryStopwatch.finish("FX_SANITIZE_HISTORY", refObj);
-        }
+        await clearData(range, Ci.nsIClearDataService.CLEAR_HISTORY);
+        TelemetryStopwatch.finish("FX_SANITIZE_HISTORY", refObj);
 
-        try {
-          let clearStartingTime = range ? String(range[0]) : "";
-          Services.obs.notifyObservers(null, "browser:purge-session-history", clearStartingTime);
-        } catch (ex) {
-          seenException = ex;
-        }
-
-        if (seenException) {
-          throw seenException;
-        }
+        let clearStartingTime = range ? String(range[0]) : "";
+        Services.obs.notifyObservers(null, "browser:purge-session-history", clearStartingTime);
       }
     },
 
     formdata: {
       async clear(range) {
         let seenException;
         let refObj = {};
         TelemetryStopwatch.start("FX_SANITIZE_FORMDATA", refObj);
--- a/toolkit/components/cleardata/ClearDataService.js
+++ b/toolkit/components/cleardata/ClearDataService.js
@@ -7,16 +7,17 @@
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   setTimeout: "resource://gre/modules/Timer.jsm",
   Downloads: "resource://gre/modules/Downloads.jsm",
   OfflineAppCacheHelper: "resource://gre/modules/offlineAppCache.jsm",
   ServiceWorkerCleanUp: "resource://gre/modules/ServiceWorkerCleanUp.jsm",
+  PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
 });
 
 XPCOMUtils.defineLazyServiceGetter(this, "sas",
                                    "@mozilla.org/storage/activity-service;1",
                                    "nsIStorageActivityService");
 
 // A Cleaner is an object with 3 methods. These methods must return a Promise
 // object. Here a description of these methods:
@@ -424,16 +425,33 @@ const PushNotificationsCleaner = {
         } else {
           aResolve();
         }
       });
     });
   },
 };
 
+const HistoryCleaner = {
+  deleteByHost(aHost, aOriginAttributes) {
+    return PlacesUtils.history.removeByFilter({ host: "." + aHost });
+  },
+
+  deleteByRange(aFrom, aTo) {
+    return PlacesUtils.history.removeVisitsByFilter({
+      beginDate: new Date(aFrom / 1000),
+      endDate: new Date(aTo / 1000)
+    });
+  },
+
+  deleteAll() {
+    return PlacesUtils.history.clear();
+  },
+};
+
 // Here the map of Flags-Cleaner.
 const FLAGS_MAP = [
  { flag: Ci.nsIClearDataService.CLEAR_COOKIES,
    cleaner: CookieCleaner },
 
  { flag: Ci.nsIClearDataService.CLEAR_NETWORK_CACHE,
    cleaner: NetworkCacheCleaner },
 
@@ -458,16 +476,19 @@ const FLAGS_MAP = [
  { flag: Ci.nsIClearDataService.CLEAR_DOM_QUOTA,
    cleaner: QuotaCleaner, },
 
  { flag: Ci.nsIClearDataService.CLEAR_PREDICTOR_NETWORK_DATA,
    cleaner: PredictorNetworkCleaner, },
 
  { flag: Ci.nsIClearDataService.CLEAR_DOM_PUSH_NOTIFICATIONS,
    cleaner: PushNotificationsCleaner, },
+
+ { flag: Ci.nsIClearDataService.CLEAR_HISTORY,
+   cleaner: HistoryCleaner, },
 ];
 
 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
@@ -133,23 +133,27 @@ interface nsIClearDataService : nsISuppo
    */
   const uint32_t CLEAR_PREDICTOR_NETWORK_DATA = 1 << 9;
 
   /**
    * DOM Push notifications
    */
   const uint32_t CLEAR_DOM_PUSH_NOTIFICATIONS = 1 << 10;
 
+  /**
+   * Places history
+   */
+  const uint32_t CLEAR_HISTORY = 1 << 11;
+
   /* 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_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;
   */
 
   /**
    * Use this value to delete all the data.
@@ -167,20 +171,16 @@ interface nsIClearDataService : nsISuppo
    */
   const uint32_t CLEAR_ALL_CACHES = CLEAR_NETWORK_CACHE | CLEAR_IMAGE_CACHE;
 
   /**
    * Delete all DOM storages
    * TODO: add CLEAR_FORMDATA | CLEAR_SESSION_HISTORY;
    */
   const uint32_t CLEAR_DOM_STORAGES = CLEAR_APPCACHE | CLEAR_DOM_QUOTA | CLEAR_DOM_PUSH_NOTIFICATIONS;
-
-  /*
-  const uint32_t CLEAR_BROWSER_DATA = CLEAR_DOWNLOADS | CLEAR_PASSWORDS | CLEAR_PERMISSIONS | CLEAR_CONTENT_PREFERENCES | CLEAR_HISTORY | CLEAR_LOGINS;
-  */
 };
 
 /**
  * This is a companion interface for
  * nsIClearDataService::deleteDataFromPrincipal().
  */
 [function, scriptable, uuid(e225517b-24c5-498a-b9fb-9993e341a398)]
 interface nsIClearDataCallback : nsISupports
--- a/toolkit/forgetaboutsite/ForgetAboutSite.jsm
+++ b/toolkit/forgetaboutsite/ForgetAboutSite.jsm
@@ -2,18 +2,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
-ChromeUtils.defineModuleGetter(this, "PlacesUtils",
-                               "resource://gre/modules/PlacesUtils.jsm");
 
 var EXPORTED_SYMBOLS = ["ForgetAboutSite"];
 
 /**
  * Returns true if the string passed in is part of the root domain of the
  * current string.  For example, if this is "www.mozilla.org", and we pass in
  * "mozilla.org", this will return true.  It would return false the other way
  * around.
@@ -33,18 +31,16 @@ function hasRootDomain(str, aDomain) {
   // exact match) the character before the index is a dot or slash.
   let prevChar = str[index - 1];
   return (index == (str.length - aDomain.length)) &&
          (prevChar == "." || prevChar == "/");
 }
 
 var ForgetAboutSite = {
   async removeDataFromDomain(aDomain) {
-    await PlacesUtils.history.removeByFilter({ host: "." + aDomain });
-
     let promises = [];
 
     ["http://", "https://"].forEach(scheme => {
       promises.push(new Promise(resolve => {
         Services.clearData.deleteDataFromHost(aDomain, true /* user request */,
                                               Ci.nsIClearDataService.CLEAR_ALL,
                                               resolve);
       }));