diff --git a/dom/base/ProcessSelector.jsm b/dom/base/ProcessSelector.jsm index 0372d6b60250..b86352eb66fe 100644 --- a/dom/base/ProcessSelector.jsm +++ b/dom/base/ProcessSelector.jsm @@ -39,16 +39,19 @@ MinTabSelector.prototype = { QueryInterface: ChromeUtils.generateQI([Ci.nsIContentProcessProvider]), provideProcess(aType, aOpener, aProcesses, aMaxCount) { + if (aProcesses.length < aMaxCount) { + return Ci.nsIContentProcessProvider.NEW_PROCESS; + } + let min = Number.MAX_VALUE; let candidate = Ci.nsIContentProcessProvider.NEW_PROCESS; - // The reason for not directly using aProcesses.length here is because if - // we keep processes alive for testing but want a test to use only single + // Note, that at this point aMaxCount is in the valid range and + // the reason for not using aProcesses.length here is because if we keep + // processes alive for testing but want a test to use only single // content process we can just keep relying on dom.ipc.processCount = 1 // this way. - let numIters = Math.min(aProcesses.length, aMaxCount); - - for (let i = 0; i < numIters; i++) { + for (let i = 0; i < aMaxCount; i++) { let process = aProcesses[i]; let tabCount = process.tabCount; if (process.opener === aOpener && tabCount < min) { @@ -57,13 +60,6 @@ MinTabSelector.prototype = { } } - // If all current processes have at least one tab and we have not yet - // reached the maximum, spawn a new process. - if (min > 0 && aProcesses.length < aMaxCount) { - return Ci.nsIContentProcessProvider.NEW_PROCESS; - } - - // Otherwise we use candidate. return candidate; }, }; diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 138a39a4cee8..41fc1b0a2037 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -860,14 +860,6 @@ already_AddRefed ContentParent::MinTabSelect( } } - // If all current processes have at least one tab and we have not yet reached - // the maximum, use a new process. - if (min > 0 && - aContentParents.Length() < static_cast(aMaxContentParents)) { - return nullptr; - } - - // Otherwise we return candidate. return candidate.forget(); } @@ -924,7 +916,8 @@ already_AddRefed ContentParent::GetUsedBrowserProcess( // selection. NS_WARNING("nsIContentProcessProvider failed to return a process"); RefPtr random; - if ((random = MinTabSelect(aContentParents, aOpener, aMaxContentParents))) { + if (aContentParents.Length() >= aMaxContentParents && + (random = MinTabSelect(aContentParents, aOpener, aMaxContentParents))) { MOZ_LOG(ContentParent::GetLog(), LogLevel::Debug, ("GetUsedProcess: Reused random process %p (%d) for %s", random.get(), (unsigned int)random->ChildID(),