Bug 1346583 - Remove the PContent::Msg_OpenAnonymousTemporaryFile sync IPC; r=billm
authorEhsan Akhgari <ehsan@mozilla.com>
Sat, 18 Mar 2017 23:58:37 -0400
changeset 348685 3d6ca79155559e8290b0d87e22db63d1f8449ee4
parent 348684 b89cd59e4ff6185266b496978c2bd1f56dc2cf68
child 348686 3ec06476d7306e8a12f6ee4f56472948a3c114d6
push id31533
push userkwierso@gmail.com
push dateTue, 21 Mar 2017 23:08:53 +0000
treeherdermozilla-central@8744e9f8eb99 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1346583
milestone55.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 1346583 - Remove the PContent::Msg_OpenAnonymousTemporaryFile sync IPC; r=billm
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
dom/ipc/PContent.ipdl
ipc/ipdl/sync-messages.ini
xpcom/io/nsAnonymousTemporaryFile.cpp
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -4156,34 +4156,16 @@ ContentParent::RecvRequestAnonymousTempo
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return IPC_OK();
   }
 
   rv = NS_OK;
   return IPC_OK();
 }
 
-mozilla::ipc::IPCResult
-ContentParent::RecvOpenAnonymousTemporaryFile(FileDescOrError *aFD)
-{
-  PRFileDesc *prfd;
-  nsresult rv = NS_OpenAnonymousTemporaryFile(&prfd);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    // Returning false will kill the child process; instead
-    // propagate the error and let the child handle it.
-    *aFD = rv;
-    return IPC_OK();
-  }
-  *aFD = FileDescriptor(FileDescriptor::PlatformHandleType(PR_FileDesc2NativeHandle(prfd)));
-  // The FileDescriptor object owns a duplicate of the file handle; we
-  // must close the original (and clean up the NSPR descriptor).
-  PR_Close(prfd);
-  return IPC_OK();
-}
-
 static NS_DEFINE_CID(kFormProcessorCID, NS_FORMPROCESSOR_CID);
 
 mozilla::ipc::IPCResult
 ContentParent::RecvKeygenProcessValue(const nsString& oldValue,
                                       const nsString& challenge,
                                       const nsString& keytype,
                                       const nsString& keyparams,
                                       nsString* newValue)
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -1057,19 +1057,16 @@ private:
 
   virtual mozilla::ipc::IPCResult
   RecvBackUpXResources(const FileDescriptor& aXSocketFd) override;
 
   virtual mozilla::ipc::IPCResult
   RecvRequestAnonymousTemporaryFile(const uint64_t& aID) override;
 
   virtual mozilla::ipc::IPCResult
-  RecvOpenAnonymousTemporaryFile(FileDescOrError* aFD) override;
-
-  virtual mozilla::ipc::IPCResult
   RecvKeygenProcessValue(const nsString& oldValue, const nsString& challenge,
                          const nsString& keytype, const nsString& keyparams,
                          nsString* newValue) override;
 
   virtual mozilla::ipc::IPCResult
   RecvKeygenProvideContent(nsString* aAttribute,
                            nsTArray<nsString>* aContent) override;
 
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -871,18 +871,16 @@ parent:
      * parent process from crashing on X errors if, e.g., the plugin
      * crashes *just before* a repaint and the parent process tries to
      * use the newly-invalid surface.
      */
     async BackUpXResources(FileDescriptor aXSocketFd);
 
     async RequestAnonymousTemporaryFile(uint64_t aID);
 
-    sync OpenAnonymousTemporaryFile() returns (FileDescOrError aFD);
-
     /**
      * Keygen requires us to call it after a <keygen> element is parsed and
      * before one is submitted. This is urgent because an extension might use
      * a CPOW to synchronously submit a keygen element.
      */
     nested(inside_cpow) sync KeygenProcessValue(nsString oldValue,
                                                 nsString challenge,
                                                 nsString keytype,
--- a/ipc/ipdl/sync-messages.ini
+++ b/ipc/ipdl/sync-messages.ini
@@ -791,18 +791,16 @@ description =
 [PContent::NotifyKeywordSearchLoading]
 description =
 [PContent::AllocateLayerTreeId]
 description =
 [PContent::BeginDriverCrashGuard]
 description =
 [PContent::EndDriverCrashGuard]
 description =
-[PContent::OpenAnonymousTemporaryFile]
-description =
 [PContent::KeygenProcessValue]
 description =
 [PContent::KeygenProvideContent]
 description =
 [PContent::AllocateTabId]
 description =
 [PContent::GetGraphicsDeviceInitData]
 description =
--- a/xpcom/io/nsAnonymousTemporaryFile.cpp
+++ b/xpcom/io/nsAnonymousTemporaryFile.cpp
@@ -1,26 +1,23 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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/. */
 
 
-#include "mozilla/dom/ContentChild.h"
-#include "mozilla/SyncRunnable.h"
 #include "nsAnonymousTemporaryFile.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsXULAppAPI.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "prio.h"
-#include "private/pprio.h"
 
 #ifdef XP_WIN
 #include "nsIObserver.h"
 #include "nsIObserverService.h"
 #include "mozilla/Services.h"
 #include "nsIIdleService.h"
 #include "nsISimpleEnumerator.h"
 #include "nsIFile.h"
@@ -78,64 +75,25 @@ GetTempDir(nsIFile** aTempDir)
   }
 #endif
 
   tmpFile.forget(aTempDir);
 
   return NS_OK;
 }
 
-namespace {
-
-class nsRemoteAnonymousTemporaryFileRunnable : public Runnable
-{
-public:
-  dom::FileDescOrError *mResultPtr;
-  explicit nsRemoteAnonymousTemporaryFileRunnable(dom::FileDescOrError *aResultPtr)
-  : mResultPtr(aResultPtr)
-  { }
-
-protected:
-  NS_IMETHOD Run() override {
-    dom::ContentChild* child = dom::ContentChild::GetSingleton();
-    MOZ_ASSERT(child);
-    child->SendOpenAnonymousTemporaryFile(mResultPtr);
-    return NS_OK;
-  }
-};
-
-} // namespace
-
 nsresult
 NS_OpenAnonymousTemporaryFile(PRFileDesc** aOutFileDesc)
 {
+  MOZ_ASSERT(XRE_IsParentProcess());
+
   if (NS_WARN_IF(!aOutFileDesc)) {
     return NS_ERROR_INVALID_ARG;
   }
 
-  if (dom::ContentChild* child = dom::ContentChild::GetSingleton()) {
-    dom::FileDescOrError fd = NS_OK;
-    if (NS_IsMainThread()) {
-      child->SendOpenAnonymousTemporaryFile(&fd);
-    } else {
-      nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
-      MOZ_ASSERT(mainThread);
-      SyncRunnable::DispatchToThread(mainThread,
-        new nsRemoteAnonymousTemporaryFileRunnable(&fd));
-    }
-    if (fd.type() == dom::FileDescOrError::Tnsresult) {
-      nsresult rv = fd.get_nsresult();
-      MOZ_ASSERT(NS_FAILED(rv));
-      return rv;
-    }
-    auto rawFD = fd.get_FileDescriptor().ClonePlatformHandle();
-    *aOutFileDesc = PR_ImportFile(PROsfd(rawFD.release()));
-    return NS_OK;
-  }
-
   nsresult rv;
   nsCOMPtr<nsIFile> tmpFile;
   rv = GetTempDir(getter_AddRefs(tmpFile));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Give the temp file a name with a random element. CreateUnique will also