execution_context_priority_decorator.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #ifndef COMPONENTS_PERFORMANCE_MANAGER_EXECUTION_CONTEXT_PRIORITY_EXECUTION_CONTEXT_PRIORITY_DECORATOR_H_
  5. #define COMPONENTS_PERFORMANCE_MANAGER_EXECUTION_CONTEXT_PRIORITY_EXECUTION_CONTEXT_PRIORITY_DECORATOR_H_
  6. #include "components/performance_manager/execution_context_priority/ad_frame_voter.h"
  7. #include "components/performance_manager/execution_context_priority/frame_audible_voter.h"
  8. #include "components/performance_manager/execution_context_priority/frame_visibility_voter.h"
  9. #include "components/performance_manager/execution_context_priority/inherit_client_priority_voter.h"
  10. #include "components/performance_manager/execution_context_priority/max_vote_aggregator.h"
  11. #include "components/performance_manager/execution_context_priority/override_vote_aggregator.h"
  12. #include "components/performance_manager/execution_context_priority/root_vote_observer.h"
  13. #include "components/performance_manager/public/graph/graph.h"
  14. namespace performance_manager {
  15. namespace execution_context_priority {
  16. // The ExecutionContextPriorityDecorator's responsibility is to own the voting
  17. // system that assigns the priority of every frame and worker in the graph.
  18. //
  19. // See the README.md for more details on the voting system.
  20. class ExecutionContextPriorityDecorator final : public GraphOwned {
  21. public:
  22. ExecutionContextPriorityDecorator();
  23. ~ExecutionContextPriorityDecorator() override;
  24. ExecutionContextPriorityDecorator(const ExecutionContextPriorityDecorator&) =
  25. delete;
  26. ExecutionContextPriorityDecorator& operator=(
  27. const ExecutionContextPriorityDecorator&) = delete;
  28. private:
  29. void OnPassedToGraph(Graph* graph) override;
  30. void OnTakenFromGraph(Graph* graph) override;
  31. // Takes in the aggregated votes and applies them to the execution contexts in
  32. // the graph.
  33. RootVoteObserver root_vote_observer_;
  34. // Used to cast a negative vote that overrides the vote from
  35. // |max_vote_aggregator_|.
  36. OverrideVoteAggregator override_vote_aggregator_;
  37. // Aggregates all the votes from the voters.
  38. MaxVoteAggregator max_vote_aggregator_;
  39. // Note: Voters should be added below this line so that they are destroyed
  40. // before the aggregators.
  41. // Casts a downvote for ad frames.
  42. AdFrameVoter ad_frame_voter_;
  43. // Casts a USER_VISIBLE vote when a frame is visible.
  44. FrameVisibilityVoter frame_visibility_voter_;
  45. // Casts a USER_VISIBLE vote when a frame is audible.
  46. FrameAudibleVoter frame_audible_voter_;
  47. // Casts a vote for each child worker with the client's priority.
  48. InheritClientPriorityVoter inherit_client_priority_voter_;
  49. };
  50. } // namespace execution_context_priority
  51. } // namespace performance_manager
  52. #endif // COMPONENTS_PERFORMANCE_MANAGER_EXECUTION_CONTEXT_PRIORITY_EXECUTION_CONTEXT_PRIORITY_DECORATOR_H_