Bug 1318371: Flush jar caches by path rather than creating a nsIFile in the content process. r=billm
authorKris Maglione <maglione.k@gmail.com>
Thu, 17 Nov 2016 20:00:30 -0800
changeset 323514 e4703e33bc324a75c325b9a17e3c0e58d18ea440
parent 323513 96186bf75ec2d6f2a83c0c663ea03a683cec5ea1
child 323515 1c7e3dc77f5688c3e76359fbd4684dc31b1e099d
push id30978
push usercbook@mozilla.com
push dateMon, 21 Nov 2016 14:44:46 +0000
treeherdermozilla-central@0534254e9a40 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1318371
milestone53.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 1318371: Flush jar caches by path rather than creating a nsIFile in the content process. r=billm MozReview-Commit-ID: 4J88w5lxEsP
modules/libjar/nsJAR.cpp
toolkit/components/extensions/ExtensionContent.jsm
toolkit/components/extensions/ExtensionTestCommon.jsm
toolkit/components/extensions/ExtensionUtils.jsm
toolkit/mozapps/extensions/internal/Content.js
--- a/modules/libjar/nsJAR.cpp
+++ b/modules/libjar/nsJAR.cpp
@@ -8,16 +8,17 @@
 #include "nsJAR.h"
 #include "nsIFile.h"
 #include "nsIX509Cert.h"
 #include "nsIConsoleService.h"
 #include "nsICryptoHash.h"
 #include "nsIDataSignatureVerifier.h"
 #include "prprf.h"
 #include "mozilla/Omnijar.h"
+#include "mozilla/Unused.h"
 
 #ifdef XP_UNIX
   #include <sys/stat.h>
 #elif defined (XP_WIN)
   #include <io.h>
 #endif
 
 using namespace mozilla;
@@ -1355,17 +1356,24 @@ nsZipReaderCache::Observe(nsISupports *a
   else if (strcmp(aTopic, "chrome-flush-caches") == 0) {
     MutexAutoLock lock(mLock);
     for (auto iter = mZips.Iter(); !iter.Done(); iter.Next()) {
       iter.UserData()->SetZipReaderCache(nullptr);
     }
     mZips.Clear();
   }
   else if (strcmp(aTopic, "flush-cache-entry") == 0) {
-    nsCOMPtr<nsIFile> file = do_QueryInterface(aSubject);
+    nsCOMPtr<nsIFile> file;
+    if (aSubject) {
+      file = do_QueryInterface(aSubject);
+    } else if (aSomeData) {
+      nsDependentString fileName(aSomeData);
+      Unused << NS_NewLocalFile(fileName, false, getter_AddRefs(file));
+    }
+
     if (!file)
       return NS_OK;
 
     nsAutoCString uri;
     if (NS_FAILED(file->GetNativePath(uri)))
       return NS_OK;
 
     uri.Insert(NS_LITERAL_CSTRING("file:"), 0);
--- a/toolkit/components/extensions/ExtensionContent.jsm
+++ b/toolkit/components/extensions/ExtensionContent.jsm
@@ -890,20 +890,17 @@ ExtensionManager = {
 
         DocumentManager.shutdownExtension(data.id);
 
         this.extensions.delete(data.id);
         break;
       }
 
       case "Extension:FlushJarCache": {
-        let nsIFile = Components.Constructor("@mozilla.org/file/local;1", "nsIFile",
-                                             "initWithPath");
-        let file = new nsIFile(data.path);
-        flushJarCache(file);
+        flushJarCache(data.path);
         Services.cpmm.sendAsyncMessage("Extension:FlushJarCacheComplete");
         break;
       }
     }
   },
 };
 
 class ExtensionGlobal {
--- a/toolkit/components/extensions/ExtensionTestCommon.jsm
+++ b/toolkit/components/extensions/ExtensionTestCommon.jsm
@@ -309,17 +309,17 @@ class ExtensionTestCommon {
    * new |Extension| instance which will execute it.
    *
    * @param {object} data
    * @returns {Extension}
    */
   static generate(data) {
     let file = this.generateXPI(data);
 
-    flushJarCache(file);
+    flushJarCache(file.path);
     Services.ppmm.broadcastAsyncMessage("Extension:FlushJarCache", {path: file.path});
 
     let fileURI = Services.io.newFileURI(file);
     let jarURI = Services.io.newURI("jar:" + fileURI.spec + "!/", null, null);
 
     // This may be "temporary" or "permanent".
     if (data.useAddonManager) {
       return new MockExtension(file, jarURI, data.useAddonManager);
--- a/toolkit/components/extensions/ExtensionUtils.jsm
+++ b/toolkit/components/extensions/ExtensionUtils.jsm
@@ -880,18 +880,18 @@ function promiseObserved(topic, test = (
 
 function getMessageManager(target) {
   if (target instanceof Ci.nsIFrameLoaderOwner) {
     return target.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader.messageManager;
   }
   return target.QueryInterface(Ci.nsIMessageSender);
 }
 
-function flushJarCache(jarFile) {
-  Services.obs.notifyObservers(jarFile, "flush-cache-entry", null);
+function flushJarCache(jarPath) {
+  Services.obs.notifyObservers(null, "flush-cache-entry", jarPath);
 }
 
 const PlatformInfo = Object.freeze({
   os: (function() {
     let os = AppConstants.platform;
     if (os == "macosx") {
       os = "mac";
     }
--- a/toolkit/mozapps/extensions/internal/Content.js
+++ b/toolkit/mozapps/extensions/internal/Content.js
@@ -7,29 +7,25 @@
 "use strict";
 
 (function() {
 
 var {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 var {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
 
-var nsIFile = Components.Constructor("@mozilla.org/file/local;1", "nsIFile",
-                                     "initWithPath");
-
 const MSG_JAR_FLUSH = "AddonJarFlush";
 const MSG_MESSAGE_MANAGER_CACHES_FLUSH = "AddonMessageManagerCachesFlush";
 
 
 try {
   if (Services.appinfo.processType !== Services.appinfo.PROCESS_TYPE_DEFAULT) {
     // Propagate JAR cache flush notifications across process boundaries.
     addMessageListener(MSG_JAR_FLUSH, function(message) {
-      let file = new nsIFile(message.data);
-      Services.obs.notifyObservers(file, "flush-cache-entry", null);
+      Services.obs.notifyObservers(null, "flush-cache-entry", message.data);
     });
     // Propagate message manager caches flush notifications across processes.
     addMessageListener(MSG_MESSAGE_MANAGER_CACHES_FLUSH, function() {
       Services.obs.notifyObservers(null, "message-manager-flush-caches", null);
     });
   }
 } catch (e) {
   Cu.reportError(e);