Bug 1422365 - Introduce nsIClearDataService - part 7 - appCache, r=johannh
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 01 Jun 2018 14:30:00 +0200
changeset 420841 6652b69cb5d06143464b29d4a9b5309f9aedc72c
parent 420840 9c6127c3f4a8393217b1b9fccb02daf984b7ddfb
child 420842 3b9b4cca1b33e7034ca4eb699c856d313b3d1c3d
push id103898
push useramarchesini@mozilla.com
push dateFri, 01 Jun 2018 12:31:55 +0000
treeherdermozilla-inbound@ee1e13b50338 [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 7 - appCache, r=johannh
browser/modules/Sanitizer.jsm
toolkit/components/cleardata/ClearDataService.js
toolkit/components/cleardata/nsIClearDataService.idl
--- a/browser/modules/Sanitizer.jsm
+++ b/browser/modules/Sanitizer.jsm
@@ -9,17 +9,16 @@ ChromeUtils.import("resource://gre/modul
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   AppConstants: "resource://gre/modules/AppConstants.jsm",
   PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
   FormHistory: "resource://gre/modules/FormHistory.jsm",
   TelemetryStopwatch: "resource://gre/modules/TelemetryStopwatch.jsm",
   ServiceWorkerCleanUp: "resource://gre/modules/ServiceWorkerCleanUp.jsm",
-  OfflineAppCacheHelper: "resource://gre/modules/offlineAppCache.jsm",
   ContextualIdentityService: "resource://gre/modules/ContextualIdentityService.jsm",
 });
 
 XPCOMUtils.defineLazyServiceGetter(this, "sas",
                                    "@mozilla.org/storage/activity-service;1",
                                    "nsIStorageActivityService");
 XPCOMUtils.defineLazyServiceGetter(this, "quotaManagerService",
                                    "@mozilla.org/dom/quota-manager-service;1",
@@ -329,18 +328,17 @@ var Sanitizer = {
                                Ci.nsIClearDataService.CLEAR_PLUGIN_DATA |
                                Ci.nsIClearDataService.CLEAR_MEDIA_DEVICES);
         TelemetryStopwatch.finish("FX_SANITIZE_COOKIES_2", refObj);
       },
     },
 
     offlineApps: {
       async clear(range) {
-        // AppCache: this doesn't wait for the cleanup to be complete.
-        OfflineAppCacheHelper.clear();
+        await clearData(range, Ci.nsIClearDataService.CLEAR_DOM_STORAGES);
 
         if (range) {
           let principals = sas.getActiveOrigins(range[0], range[1])
                               .QueryInterface(Ci.nsIArray);
 
           let promises = [];
 
           for (let i = 0; i < principals.length; ++i) {
--- a/toolkit/components/cleardata/ClearDataService.js
+++ b/toolkit/components/cleardata/ClearDataService.js
@@ -1,18 +1,22 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
-ChromeUtils.import("resource://gre/modules/Timer.jsm");
-ChromeUtils.import("resource://gre/modules/Downloads.jsm");
+
+XPCOMUtils.defineLazyModuleGetters(this, {
+  setTimeout: "resource://gre/modules/Timer.jsm",
+  Downloads: "resource://gre/modules/Downloads.jsm",
+  OfflineAppCacheHelper: "resource://gre/modules/offlineAppCache.jsm",
+});
 
 // A Cleaner is an object with 3 methods. These methods must return a Promise
 // object. Here a description of these methods:
 // * deleteAll() - this method _must_ exist. When called, it deletes all the
 //                 data owned by the cleaner.
 // * deleteByHost() - this method is implemented only if the cleaner knows
 //                    how to delete data by host + originAttributes pattern. If
 //                    not implemented, deleteAll() will be used as fallback.
@@ -244,16 +248,24 @@ const MediaDevicesCleaner = {
       let mediaMgr = Cc["@mozilla.org/mediaManagerService;1"]
                        .getService(Ci.nsIMediaManagerService);
       mediaMgr.sanitizeDeviceIds(null);
       aResolve();
     });
   },
 };
 
+const AppCacheCleaner = {
+  deleteAll() {
+    // AppCache: this doesn't wait for the cleanup to be complete.
+    OfflineAppCacheHelper.clear();
+    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 },
 
@@ -266,16 +278,19 @@ const FLAGS_MAP = [
  { flag: Ci.nsIClearDataService.CLEAR_DOWNLOADS,
    cleaner: DownloadsCleaner, },
 
  { flag: Ci.nsIClearDataService.CLEAR_PASSWORDS,
    cleaner: PasswordsCleaner, },
 
  { flag: Ci.nsIClearDataService.CLEAR_MEDIA_DEVICES,
    cleaner: MediaDevicesCleaner, },
+
+ { flag: Ci.nsIClearDataService.CLEAR_APPCACHE,
+   cleaner: AppCacheCleaner, },
 ];
 
 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
@@ -113,16 +113,21 @@ interface nsIClearDataService : nsISuppo
    */
   const uint32_t CLEAR_PASSWORDS = 1 << 5;
 
   /**
    * Media devices.
    */
   const uint32_t CLEAR_MEDIA_DEVICES = 1 << 6;
 
+  /**
+   * AppCache.
+   */
+  const uint32_t CLEAR_APPCACHE = 1 << 7;
+
   /* TODO
   const uint32_t CLEAR_EME = 1 << 4;
   const uint32_t CLEAR_PERMISSIONS = 1 << 7;
   const uint32_t CLEAR_DOM_QUOTA = 1 << 8;
   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;
@@ -145,19 +150,21 @@ interface nsIClearDataService : nsISuppo
    */
 
   /**
    * Delete all the possible caches.
    * TODO: add CLEAR_PREDICTOR_CACHE ?
    */
   const uint32_t CLEAR_ALL_CACHES = CLEAR_NETWORK_CACHE | CLEAR_IMAGE_CACHE;
 
-  /*
-  const uint32_t CLEAR_DOM_STORAGES = CLEAR_DOM_QUOTA | CLEAR_DOM_PUSH_NOTIFICATIONS | CLEAR_FORMDATA | CLEAR_SESSION_HISTORY;
-  */
+  /**
+   * Delete all DOM storages
+   * TODO: add CLEAR_DOM_QUOTA | CLEAR_DOM_PUSH_NOTIFICATIONS | CLEAR_FORMDATA | CLEAR_SESSION_HISTORY;
+   */
+  const uint32_t CLEAR_DOM_STORAGES = CLEAR_APPCACHE;
 
   /*
   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