ad_frame_voter.cc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/ad_frame_voter.h"
  5. #include <utility>
  6. #include "components/performance_manager/public/execution_context/execution_context_registry.h"
  7. #include "url/gurl.h"
  8. namespace performance_manager {
  9. namespace execution_context_priority {
  10. namespace {
  11. const execution_context::ExecutionContext* GetExecutionContext(
  12. const FrameNode* frame_node) {
  13. return execution_context::ExecutionContextRegistry::GetFromGraph(
  14. frame_node->GetGraph())
  15. ->GetExecutionContextForFrameNode(frame_node);
  16. }
  17. } // namespace
  18. // static
  19. const char AdFrameVoter::kAdFrameReason[] = "Ad frame.";
  20. AdFrameVoter::AdFrameVoter() = default;
  21. AdFrameVoter::~AdFrameVoter() = default;
  22. void AdFrameVoter::SetVotingChannel(VotingChannel voting_channel) {
  23. voting_channel_ = std::move(voting_channel);
  24. }
  25. void AdFrameVoter::OnFrameNodeAdded(const FrameNode* frame_node) {
  26. if (!frame_node->IsAdFrame())
  27. return;
  28. const Vote vote(base::TaskPriority::LOWEST, kAdFrameReason);
  29. voting_channel_.SubmitVote(GetExecutionContext(frame_node), vote);
  30. }
  31. void AdFrameVoter::OnBeforeFrameNodeRemoved(const FrameNode* frame_node) {
  32. if (!frame_node->IsAdFrame())
  33. return;
  34. voting_channel_.InvalidateVote(GetExecutionContext(frame_node));
  35. }
  36. void AdFrameVoter::OnIsAdFrameChanged(const FrameNode* frame_node) {
  37. if (frame_node->IsAdFrame()) {
  38. const Vote vote(base::TaskPriority::LOWEST, kAdFrameReason);
  39. voting_channel_.SubmitVote(GetExecutionContext(frame_node), vote);
  40. } else {
  41. voting_channel_.InvalidateVote(GetExecutionContext(frame_node));
  42. }
  43. }
  44. } // namespace execution_context_priority
  45. } // namespace performance_manager