Bug 956833 - Clear manifests cache on memory pressure. r=gal, a=1.3+
authorFabrice Desré <fabrice@mozilla.com>
Mon, 06 Jan 2014 13:03:50 -0800
changeset 175571 4b45e4f20261d08982b944f15cc8dda5d6cb735b
parent 175570 dc95e43fc5dd0d3110b1d8be11cf804fa2b833a4
child 175572 758629e75ddfee6eb4ed92fa87656c3469863e85
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgal, 1
bugs956833
milestone28.0a2
Bug 956833 - Clear manifests cache on memory pressure. r=gal, a=1.3+
dom/apps/src/Webapps.js
dom/apps/src/Webapps.jsm
--- a/dom/apps/src/Webapps.js
+++ b/dom/apps/src/Webapps.js
@@ -290,16 +290,25 @@ let manifestCache = {
       if (aInnerWindowID in winObjs) {
         delete winObjs[aInnerWindowID];
       }
 
       if (Object.keys(winObjs).length == 0) {
         delete this._cache[aManifestURL];
       }
     }
+  },
+
+  observe: function(aSubject, aTopic, aData) {
+    // Clear the cache on memory pressure.
+    this._cache = { };
+  },
+
+  init: function() {
+    Services.obs.addObserver(this, "memory-pressure", false);
   }
 };
 
 function createApplicationObject(aWindow, aApp) {
   let app = Cc["@mozilla.org/webapps/application;1"].createInstance(Ci.mozIDOMApplication);
   app.wrappedJSObject.init(aWindow, aApp);
   return app;
 }
@@ -796,10 +805,12 @@ WebappsApplicationMgmt.prototype = {
 
   classInfo: XPCOMUtils.generateCI({classID: Components.ID("{8c1bca96-266f-493a-8d57-ec7a95098c15}"),
                                     contractID: "@mozilla.org/webapps/application-mgmt;1",
                                     interfaces: [Ci.mozIDOMApplicationMgmt],
                                     flags: Ci.nsIClassInfo.DOM_OBJECT,
                                     classDescription: "Webapps Application Mgmt"})
 }
 
+manifestCache.init();
+
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WebappsRegistry,
                                                      WebappsApplication]);
--- a/dom/apps/src/Webapps.jsm
+++ b/dom/apps/src/Webapps.jsm
@@ -150,16 +150,17 @@ this.DOMApplicationRegistry = {
 
     this.messages.forEach((function(msgName) {
       ppmm.addMessageListener(msgName, this);
     }).bind(this));
 
     cpmm.addMessageListener("Activities:Register:OK", this);
 
     Services.obs.addObserver(this, "xpcom-shutdown", false);
+    Services.obs.addObserver(this, "memory-pressure", false);
 
     AppDownloadManager.registerCancelFunction(this.cancelDownload.bind(this));
 
     this.appsFile = FileUtils.getFile(DIRECTORY_NAME,
                                       ["webapps", "webapps.json"], true);
 
     this.loadAndUpdateApps();
   },
@@ -956,16 +957,19 @@ this.DOMApplicationRegistry = {
   observe: function(aSubject, aTopic, aData) {
     if (aTopic == "xpcom-shutdown") {
       this.messages.forEach((function(msgName) {
         ppmm.removeMessageListener(msgName, this);
       }).bind(this));
       Services.obs.removeObserver(this, "xpcom-shutdown");
       cpmm = null;
       ppmm = null;
+    } else if (aTopic == "memory-pressure") {
+      // Clear the manifest cache on memory pressure.
+      this._manifestCache = {};
     }
   },
 
   _loadJSONAsync: function(aFile, aCallback) {
     try {
       let channel = NetUtil.newChannel(aFile);
       channel.contentType = "application/json";
       NetUtil.asyncFetch(channel, function(aStream, aResult) {