From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- dom/base/ProcessSelector.sys.mjs | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 dom/base/ProcessSelector.sys.mjs (limited to 'dom/base/ProcessSelector.sys.mjs') diff --git a/dom/base/ProcessSelector.sys.mjs b/dom/base/ProcessSelector.sys.mjs new file mode 100644 index 0000000000..59319f7bf6 --- /dev/null +++ b/dom/base/ProcessSelector.sys.mjs @@ -0,0 +1,58 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Fills up aProcesses until max and then selects randomly from the available +// ones. +export function RandomSelector() {} + +RandomSelector.prototype = { + classID: Components.ID("{c616fcfd-9737-41f1-aa74-cee72a38f91b}"), + QueryInterface: ChromeUtils.generateQI(["nsIContentProcessProvider"]), + + provideProcess(aType, aProcesses, aMaxCount) { + if (aProcesses.length < aMaxCount) { + return Ci.nsIContentProcessProvider.NEW_PROCESS; + } + + return Math.floor(Math.random() * aMaxCount); + }, +}; + +// Fills up aProcesses until max and then selects one from the available +// ones that host the least number of tabs. +export function MinTabSelector() {} + +MinTabSelector.prototype = { + classID: Components.ID("{2dc08eaf-6eef-4394-b1df-a3a927c1290b}"), + QueryInterface: ChromeUtils.generateQI(["nsIContentProcessProvider"]), + + provideProcess(aType, aProcesses, aMaxCount) { + 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 + // 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++) { + let process = aProcesses[i]; + let tabCount = process.tabCount; + if (tabCount < min) { + min = tabCount; + candidate = i; + } + } + + // 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; + }, +}; -- cgit v1.2.3