Bug 930282 - Part 3: Don't fork after xpcom shutdown. r=khuey, a=1.3+
authorPatrick Wang <kk1fff@patrickz.net>
Mon, 09 Dec 2013 22:42:48 +0800
changeset 224602 0caa220cef77554c3a879270ad1a5fd40537d4e1
parent 224601 199a446b8f42dc13166fbd4228464f81ceee7c76
child 224603 ee493ea80c8f88caea94165cb7fbc0f332e471a0
push id6
push userryanvm@gmail.com
push dateMon, 12 Jan 2015 22:04:06 +0000
treeherdermozilla-b2g37_v2_2@895c8fc7b734 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey, 1.3
bugs930282
milestone28.0a2
Bug 930282 - Part 3: Don't fork after xpcom shutdown. r=khuey, a=1.3+
dom/ipc/PreallocatedProcessManager.cpp
--- a/dom/ipc/PreallocatedProcessManager.cpp
+++ b/dom/ipc/PreallocatedProcessManager.cpp
@@ -83,16 +83,17 @@ private:
 
   void RereadPrefs();
   void Enable();
   void Disable();
 
   void ObserveProcessShutdown(nsISupports* aSubject);
 
   bool mEnabled;
+  bool mShutdown;
   nsRefPtr<ContentParent> mPreallocatedAppProcess;
 };
 
 /* static */ StaticRefPtr<PreallocatedProcessManagerImpl>
 PreallocatedProcessManagerImpl::sSingleton;
 
 /* static */ PreallocatedProcessManagerImpl*
 PreallocatedProcessManagerImpl::Singleton()
@@ -109,40 +110,45 @@ PreallocatedProcessManagerImpl::Singleto
 NS_IMPL_ISUPPORTS1(PreallocatedProcessManagerImpl, nsIObserver)
 
 PreallocatedProcessManagerImpl::PreallocatedProcessManagerImpl()
   : mEnabled(false)
 #ifdef MOZ_NUWA_PROCESS
   , mPreallocateAppProcessTask(nullptr)
   , mIsNuwaReady(false)
 #endif
+  , mShutdown(false)
 {}
 
 void
 PreallocatedProcessManagerImpl::Init()
 {
   Preferences::AddStrongObserver(this, "dom.ipc.processPrelaunch.enabled");
   nsCOMPtr<nsIObserverService> os = services::GetObserverService();
   if (os) {
     os->AddObserver(this, "ipc:content-shutdown",
                     /* weakRef = */ false);
+    os->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID,
+                    /* weakRef = */ false);
   }
   RereadPrefs();
 }
 
 NS_IMETHODIMP
 PreallocatedProcessManagerImpl::Observe(nsISupports* aSubject,
                                         const char* aTopic,
                                         const PRUnichar* aData)
 {
   if (!strcmp("ipc:content-shutdown", aTopic)) {
     ObserveProcessShutdown(aSubject);
   } else if (!strcmp("nsPref:changed", aTopic)) {
     // The only other observer we registered was for our prefs.
     RereadPrefs();
+  } else if (!strcmp(NS_XPCOM_SHUTDOWN_OBSERVER_ID, aTopic)) {
+    mShutdown = true;
   } else {
     MOZ_ASSERT(false);
   }
 
   return NS_OK;
 }
 
 void
@@ -235,17 +241,17 @@ PreallocatedProcessManagerImpl::Schedule
 void
 PreallocatedProcessManagerImpl::DelayedNuwaFork()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   mPreallocateAppProcessTask = nullptr;
 
   if (!mIsNuwaReady) {
-    if (!mPreallocatedAppProcess) {
+    if (!mPreallocatedAppProcess && !mShutdown) {
       mPreallocatedAppProcess = ContentParent::RunNuwaProcess();
     }
     // else mPreallocatedAppProcess is starting. It will NuwaFork() when ready.
   } else if (mSpareProcesses.IsEmpty()) {
     NuwaFork();
   }
 }