Bug 1142935 - Reset transports with NuwaAddConstructor(). r=tlee, a=bajaj
authorCervantes Yu <cyu@mozilla.com>
Mon, 16 Mar 2015 22:25:59 -0700
changeset 237801 1e583b3818dbe36f2dc93162c5fb4e1a59b642bd
parent 237800 1bc1a4e156ccef41ddf94e9d803aa7a3af50a24a
child 237802 5af675b6ffd37fe02b4cf48f047022dd38171d40
push id354
push userryanvm@gmail.com
push dateThu, 19 Mar 2015 13:39:11 +0000
treeherdermozilla-b2g37_v2_2@1e583b3818db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstlee, bajaj
bugs1142935
milestone37.0
Bug 1142935 - Reset transports with NuwaAddConstructor(). r=tlee, a=bajaj
dom/ipc/ContentChild.cpp
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -543,16 +543,35 @@ InitOnContentProcessCreated()
     if (!smc) {
         NS_WARNING("Failed to initialize system-message-cache service!");
     }
 
     // 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
@@ -640,16 +659,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
@@ -2348,28 +2373,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;
     }
 };