The PriorityVotingSystem is responsible for assigning the priority of the votable nodes in the graph.
This is done through a system of voting where each voter can independently increase the priority of a graph node, and the vote with the highest priority determines which priority that graph node will be assigned.
A VoteContext identifies the graph node that a vote targets. It is a std::variant that explicitly lists the votable node types (currently FrameNode, WorkerNode, PageNode and ProcessNode). Voting on any other node type fails to compile.
Frames
======
PageToFrameVoteExpander -+
+-> MaxVoteAggregator -> PrioritySetter -> FrameNode -> ProcessPriorityAggregator
Other voters -+
Workers
=======
Voters -> MaxVoteAggregator -> PrioritySetter -> WorkerNode -> ProcessPriorityAggregator
Processes
=========
ProcessPriorityAggregator -+
+-> MaxVoteAggregator -> PrioritySetter -> ProcessNode
Other voters -+
Pages
=====
Voters -> MaxVoteAggregator -> PageToFrameVoteExpander
Every vote goes into a single MaxVoteAggregator, through a voting channel. The top vote of a node in the aggregator is therefore its final priority.
Each voter tracks a single property of a vote context and casts their vote via their voting channel to the MaxVoteAggregator.
The observers of the MaxVoteAggregator are:
The ProcessPriorityAggregator follows the priority of every frame and worker (as set by the PrioritySetter), and casts the highest priority of the frames and workers hosted by a process as a vote on that process, where it is aggregated with the votes cast directly on the process. This vote is cast even when it is the lowest priority, so that a process drops from its initial high priority once it hosts a frame or worker.
The PriorityVotingSystem owns the MaxVoteAggregator, and builds each of these from it. It also verifies that no votes are leaked.
Some voters (e.g. InheritClientPriorityVoter) also derive votes from the priority of other nodes. They are voters because they implement an optional policy. The derived votes cast on frames (from their page) and on processes (from their frames and workers) are part of the voting system itself: they are always needed for the priorities to be correct.