2016-11-02 02:02:43 +03:00
|
|
|
/* 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.
|
|
|
|
function RandomSelector() {}
|
|
|
|
|
|
|
|
RandomSelector.prototype = {
|
|
|
|
classID: Components.ID("{c616fcfd-9737-41f1-aa74-cee72a38f91b}"),
|
Bug 1649221: Update ChromeUtils.generateQI callers to pass strings. r=mccr8,remote-protocol-reviewers,marionette-reviewers,perftest-reviewers,webcompat-reviewers,geckoview-reviewers,preferences-reviewers,agi,whimboo,Bebe,twisniewski
Differential Revision: https://phabricator.services.mozilla.com/D81594
2020-07-11 02:58:28 +03:00
|
|
|
QueryInterface: ChromeUtils.generateQI(["nsIContentProcessProvider"]),
|
2016-11-02 02:02:43 +03:00
|
|
|
|
2020-06-26 19:26:50 +03:00
|
|
|
provideProcess(aType, aProcesses, aMaxCount) {
|
2019-05-13 18:58:01 +03:00
|
|
|
if (aProcesses.length < aMaxCount) {
|
2016-11-02 02:02:43 +03:00
|
|
|
return Ci.nsIContentProcessProvider.NEW_PROCESS;
|
|
|
|
}
|
|
|
|
|
2020-06-26 19:26:50 +03:00
|
|
|
return Math.floor(Math.random() * aMaxCount);
|
2016-11-02 02:02:43 +03:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-03-07 22:00:28 +03:00
|
|
|
// Fills up aProcesses until max and then selects one from the available
|
|
|
|
// ones that host the least number of tabs.
|
|
|
|
function MinTabSelector() {}
|
|
|
|
|
|
|
|
MinTabSelector.prototype = {
|
|
|
|
classID: Components.ID("{2dc08eaf-6eef-4394-b1df-a3a927c1290b}"),
|
Bug 1649221: Update ChromeUtils.generateQI callers to pass strings. r=mccr8,remote-protocol-reviewers,marionette-reviewers,perftest-reviewers,webcompat-reviewers,geckoview-reviewers,preferences-reviewers,agi,whimboo,Bebe,twisniewski
Differential Revision: https://phabricator.services.mozilla.com/D81594
2020-07-11 02:58:28 +03:00
|
|
|
QueryInterface: ChromeUtils.generateQI(["nsIContentProcessProvider"]),
|
2017-03-07 22:00:28 +03:00
|
|
|
|
2020-06-26 19:26:50 +03:00
|
|
|
provideProcess(aType, aProcesses, aMaxCount) {
|
2017-03-07 22:00:28 +03:00
|
|
|
let min = Number.MAX_VALUE;
|
|
|
|
let candidate = Ci.nsIContentProcessProvider.NEW_PROCESS;
|
|
|
|
|
2020-06-27 09:14:27 +03:00
|
|
|
// 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
|
2017-03-30 19:44:20 +03:00
|
|
|
// content process we can just keep relying on dom.ipc.processCount = 1
|
|
|
|
// this way.
|
2020-06-27 09:14:27 +03:00
|
|
|
let numIters = Math.min(aProcesses.length, aMaxCount);
|
|
|
|
|
|
|
|
for (let i = 0; i < numIters; i++) {
|
2017-03-07 22:00:28 +03:00
|
|
|
let process = aProcesses[i];
|
|
|
|
let tabCount = process.tabCount;
|
2020-06-26 19:26:50 +03:00
|
|
|
if (tabCount < min) {
|
2017-03-07 22:00:28 +03:00
|
|
|
min = tabCount;
|
|
|
|
candidate = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-27 09:14:27 +03:00
|
|
|
// 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.
|
2017-03-07 22:00:28 +03:00
|
|
|
return candidate;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-01-30 22:41:05 +03:00
|
|
|
var EXPORTED_SYMBOLS = ["RandomSelector", "MinTabSelector"];
|