inherit_client_priority_voter.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_INHERIT_CLIENT_PRIORITY_VOTER_H_
  5. #define COMPONENTS_PERFORMANCE_MANAGER_EXECUTION_CONTEXT_PRIORITY_INHERIT_CLIENT_PRIORITY_VOTER_H_
  6. #include "components/performance_manager/execution_context_priority/max_vote_aggregator.h"
  7. #include "components/performance_manager/public/execution_context_priority/execution_context_priority.h"
  8. #include "components/performance_manager/public/graph/frame_node.h"
  9. #include "components/performance_manager/public/graph/worker_node.h"
  10. namespace performance_manager {
  11. namespace execution_context_priority {
  12. // This voter ensures the priority of a client is inherited by its children
  13. // workers.
  14. class InheritClientPriorityVoter : public FrameNode::ObserverDefaultImpl,
  15. public WorkerNode::ObserverDefaultImpl {
  16. public:
  17. static const char kPriorityInheritedReason[];
  18. InheritClientPriorityVoter();
  19. ~InheritClientPriorityVoter() override;
  20. InheritClientPriorityVoter(const InheritClientPriorityVoter&) = delete;
  21. InheritClientPriorityVoter& operator=(const InheritClientPriorityVoter&) =
  22. delete;
  23. // Sets the voting channel where the votes will be cast.
  24. void SetVotingChannel(VotingChannel voting_channel);
  25. // FrameNodeObserver:
  26. void OnFrameNodeAdded(const FrameNode* frame_node) override;
  27. void OnBeforeFrameNodeRemoved(const FrameNode* frame_node) override;
  28. void OnPriorityAndReasonChanged(
  29. const FrameNode* frame_node,
  30. const PriorityAndReason& previous_value) override;
  31. // WorkerNodeObserver:
  32. void OnWorkerNodeAdded(const WorkerNode* worker_node) override;
  33. void OnBeforeWorkerNodeRemoved(const WorkerNode* worker_node) override;
  34. void OnClientFrameAdded(const WorkerNode* worker_node,
  35. const FrameNode* client_frame_node) override;
  36. void OnBeforeClientFrameRemoved(const WorkerNode* worker_node,
  37. const FrameNode* client_frame_node) override;
  38. void OnClientWorkerAdded(const WorkerNode* worker_node,
  39. const WorkerNode* client_worker_node) override;
  40. void OnBeforeClientWorkerRemoved(
  41. const WorkerNode* worker_node,
  42. const WorkerNode* client_worker_node) override;
  43. void OnPriorityAndReasonChanged(
  44. const WorkerNode* worker_node,
  45. const PriorityAndReason& previous_value) override;
  46. private:
  47. void OnExecutionContextAdded(const ExecutionContext* execution_context);
  48. void OnBeforeExecutionContextRemoved(
  49. const ExecutionContext* execution_context);
  50. void OnPriorityAndReasonChanged(const ExecutionContext* execution_context,
  51. const PriorityAndReason& previous_value);
  52. // Aggregates the votes from multiple clients of the same child worker.
  53. MaxVoteAggregator max_vote_aggregator_;
  54. // Each frame or worker gets a VotingChannel to cast votes for its children.
  55. base::flat_map<const ExecutionContext*, VotingChannel> voting_channels_;
  56. };
  57. } // namespace execution_context_priority
  58. } // namespace performance_manager
  59. #endif // COMPONENTS_PERFORMANCE_MANAGER_EXECUTION_CONTEXT_PRIORITY_INHERIT_CLIENT_PRIORITY_VOTER_H_