execution_context_priority_decorator.cc 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/performance_manager/execution_context_priority/execution_context_priority_decorator.h"
  5. #include "components/performance_manager/public/execution_context/execution_context_registry.h"
  6. namespace performance_manager {
  7. namespace execution_context_priority {
  8. ExecutionContextPriorityDecorator::ExecutionContextPriorityDecorator() {
  9. // The following schema describes the structure of the voting tree. Arrows are
  10. // voting channels.
  11. //
  12. // Note: |ad_frame_voter_| is currently the only downvoter but there could
  13. // possibly be more should the need arise. Their votes would be aggregated
  14. // using some sort of MinVoteAggregator.
  15. //
  16. // |root_vote_observer_|
  17. // ^
  18. // |
  19. // |override_vote_aggregator_|
  20. // ^ ^
  21. // | (override) | (default)
  22. // | |
  23. // Downvoter |max_vote_aggregator_|
  24. // ^ ^ ^
  25. // / | \
  26. // / | \
  27. // Voter1, Voter2, ..., VoterN
  28. //
  29. // Set up the voting tree from top to bottom.
  30. override_vote_aggregator_.SetUpstreamVotingChannel(
  31. root_vote_observer_.GetVotingChannel());
  32. max_vote_aggregator_.SetUpstreamVotingChannel(
  33. override_vote_aggregator_.GetDefaultVotingChannel());
  34. // Set up downvoter.
  35. ad_frame_voter_.SetVotingChannel(
  36. override_vote_aggregator_.GetOverrideVotingChannel());
  37. // Set up voters.
  38. frame_visibility_voter_.SetVotingChannel(
  39. max_vote_aggregator_.GetVotingChannel());
  40. frame_audible_voter_.SetVotingChannel(
  41. max_vote_aggregator_.GetVotingChannel());
  42. inherit_client_priority_voter_.SetVotingChannel(
  43. max_vote_aggregator_.GetVotingChannel());
  44. }
  45. ExecutionContextPriorityDecorator::~ExecutionContextPriorityDecorator() =
  46. default;
  47. void ExecutionContextPriorityDecorator::OnPassedToGraph(Graph* graph) {
  48. // Subscribe voters to the graph.
  49. graph->AddFrameNodeObserver(&ad_frame_voter_);
  50. graph->AddFrameNodeObserver(&frame_visibility_voter_);
  51. graph->AddFrameNodeObserver(&frame_audible_voter_);
  52. graph->AddFrameNodeObserver(&inherit_client_priority_voter_);
  53. graph->AddWorkerNodeObserver(&inherit_client_priority_voter_);
  54. }
  55. void ExecutionContextPriorityDecorator::OnTakenFromGraph(Graph* graph) {
  56. // Unsubscribe voters from the graph.
  57. graph->RemoveWorkerNodeObserver(&inherit_client_priority_voter_);
  58. graph->RemoveFrameNodeObserver(&inherit_client_priority_voter_);
  59. graph->RemoveFrameNodeObserver(&frame_audible_voter_);
  60. graph->RemoveFrameNodeObserver(&frame_visibility_voter_);
  61. graph->RemoveFrameNodeObserver(&ad_frame_voter_);
  62. }
  63. } // namespace execution_context_priority
  64. } // namespace performance_manager