Bug 1320395: Part 1 - Allow keeping non-default process types alive. r?bobowen draft
authorKris Maglione <maglione.k@gmail.com>
Sun, 27 Nov 2016 12:44:20 -0800
changeset 444202 549f8d1f218ed894125b17112bfd9954761a9069
parent 444110 5b45f7938182ea8bf814ab0bb6373bcf803755b5
child 444203 049c802e5b09dbbfc9a7a2be6d049b0d5b368e03
push id37231
push usermaglione.k@gmail.com
push dateSun, 27 Nov 2016 20:59:46 +0000
reviewersbobowen
bugs1320395
milestone53.0a1
Bug 1320395: Part 1 - Allow keeping non-default process types alive. r?bobowen MozReview-Commit-ID: 6TvKN3wFLms
dom/ipc/ContentParent.cpp
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -1610,31 +1610,37 @@ ContentParent::ShouldKeepProcessAlive() 
     return false;
   }
 
   // If we have already been marked as dead, don't prevent shutdown.
   if (!IsAlive()) {
     return false;
   }
 
-  // Only keep processes for the default remote type alive.
-  if (!mRemoteType.EqualsLiteral(DEFAULT_REMOTE_TYPE)) {
-    return false;
-  }
-
   auto contentParents = sBrowserContentParents->Get(mRemoteType);
   if (!contentParents) {
     return false;
   }
 
   // We might want to keep alive some content processes for testing, because of
   // performance reasons.
   // We don't want to alter behavior if the pref is not set, so default to 0.
-  int32_t processesToKeepAlive =
-    Preferences::GetInt("dom.ipc.keepProcessesAlive", 0);
+  int32_t processesToKeepAlive = 0;
+
+  nsAutoCString keepAlivePref("dom.ipc.keepProcessesAlive.");
+  keepAlivePref.Append(NS_ConvertUTF16toUTF8(mRemoteType));
+  if (NS_FAILED(Preferences::GetInt(keepAlivePref.get(), &processesToKeepAlive))) {
+    // Otherwise, only keep processes for the default remote type alive.
+    if (!mRemoteType.EqualsLiteral(DEFAULT_REMOTE_TYPE)) {
+      return false;
+    }
+
+    processesToKeepAlive = Preferences::GetInt("dom.ipc.keepProcessesAlive", 0);
+  }
+
   int32_t numberOfAliveProcesses = contentParents->Length();
 
   return numberOfAliveProcesses <= processesToKeepAlive;
 }
 
 void
 ContentParent::NotifyTabDestroying(const TabId& aTabId,
                                    const ContentParentId& aCpId)