Bug 1142935 - reset transports with NuwaAddConstructor(). r=tlee
authorCervantes Yu <cyu@mozilla.com>
Mon, 16 Mar 2015 22:25:59 -0700
changeset 233807 546a273cc8232788e2027248a34043542688046e
parent 233806 05de3bd817332467d47ccf991913becaf32f8686
child 233808 1033b252a92495388d8ffcc5c238d786ab7669c9
push id14524
push usermchang@mozilla.com
push dateTue, 17 Mar 2015 05:26:34 +0000
treeherderb2g-inbound@546a273cc823 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstlee
bugs1142935
milestone39.0a1
Bug 1142935 - reset transports with NuwaAddConstructor(). r=tlee
dom/ipc/ContentChild.cpp
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -544,16 +544,35 @@ InitOnContentProcessCreated()
     nsCOMPtr<nsISystemMessageCache> smc =
         do_GetService("@mozilla.org/system-message-cache;1");
     NS_WARN_IF(!smc);
 
     // This will register cross-process observer.
     mozilla::dom::time::InitializeDateCacheCleaner();
 }
 
+#ifdef MOZ_NUWA_PROCESS
+static void
+ResetTransports(void* aUnused) {
+  ContentChild* child = ContentChild::GetSingleton();
+  mozilla::ipc::Transport* transport = child->GetTransport();
+  int fd = transport->GetFileDescriptor();
+  transport->ResetFileDescriptor(fd);
+
+  IToplevelProtocol* toplevel = child->GetFirstOpenedActors();
+  while (toplevel != nullptr) {
+      transport = toplevel->GetTransport();
+      fd = transport->GetFileDescriptor();
+      transport->ResetFileDescriptor(fd);
+
+      toplevel = toplevel->getNext();
+  }
+}
+#endif
+
 #if defined(MOZ_TASK_TRACER) && defined(MOZ_NUWA_PROCESS)
 static void
 ReinitTaskTracer(void* /*aUnused*/)
 {
     mozilla::tasktracer::InitTaskTracer(
         mozilla::tasktracer::FORKED_AFTER_NUWA);
 }
 #endif
@@ -649,16 +668,22 @@ ContentChild::Init(MessageLoop* aIOLoop,
     InitProcessAttributes();
 
 #if defined(MOZ_TASK_TRACER) && defined (MOZ_NUWA_PROCESS)
     if (IsNuwaProcess()) {
         NuwaAddConstructor(ReinitTaskTracer, nullptr);
     }
 #endif
 
+#ifdef MOZ_NUWA_PROCESS
+    if (IsNuwaProcess()) {
+      NuwaAddConstructor(ResetTransports, nullptr);
+    }
+#endif
+
     return true;
 }
 
 void
 ContentChild::InitProcessAttributes()
 {
 #ifdef MOZ_WIDGET_GONK
 #ifdef MOZ_NUWA_PROCESS
@@ -2410,28 +2435,16 @@ public:
         NuwaSpawn();
         if (IsNuwaProcess()) {
             return NS_OK;
         }
 
         // In the new process.
         ContentChild* child = ContentChild::GetSingleton();
         child->SetProcessName(NS_LITERAL_STRING("(Preallocated app)"), false);
-        mozilla::ipc::Transport* transport = child->GetTransport();
-        int fd = transport->GetFileDescriptor();
-        transport->ResetFileDescriptor(fd);
-
-        IToplevelProtocol* toplevel = child->GetFirstOpenedActors();
-        while (toplevel != nullptr) {
-            transport = toplevel->GetTransport();
-            fd = transport->GetFileDescriptor();
-            transport->ResetFileDescriptor(fd);
-
-            toplevel = toplevel->getNext();
-        }
 
         // Perform other after-fork initializations.
         InitOnContentProcessCreated();
 
         return NS_OK;
     }
 };