blob: 77f9e8ab8e80be5d06a9fd9e2ef0991535ba1db7 [file] [log] [blame]
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_PERFORMANCE_MANAGER_DECORATORS_EXECUTION_CONTEXT_PRIORITY_FRAME_VISIBILITY_VOTER_H_
#define CHROME_BROWSER_PERFORMANCE_MANAGER_DECORATORS_EXECUTION_CONTEXT_PRIORITY_FRAME_VISIBILITY_VOTER_H_
#include "components/performance_manager/public/execution_context_priority/execution_context_priority.h"
#include "components/performance_manager/public/execution_context_priority/max_vote_aggregator.h"
#include "components/performance_manager/public/graph/frame_node.h"
namespace performance_manager {
namespace execution_context_priority {
// This voter tracks frame nodes and casts a vote for each of them, whose value
// depends on their visibility. A visible frame will receive a
// TaskPriority::USER_VISIBLE vote, while a non-visible frame will receive a
// TaskPriority::LOWEST vote.
class FrameVisibilityVoter : public FrameNode::ObserverDefaultImpl {
public:
static const char kFrameVisibilityReason[];
FrameVisibilityVoter();
~FrameVisibilityVoter() override;
FrameVisibilityVoter(const FrameVisibilityVoter&) = delete;
FrameVisibilityVoter& operator=(const FrameVisibilityVoter&) = delete;
// Sets the voting channel where the votes will be cast.
void SetVotingChannel(VotingChannel voting_channel);
// FrameNodeObserver:
void OnFrameNodeAdded(const FrameNode* frame_node) override;
void OnBeforeFrameNodeRemoved(const FrameNode* frame_node) override;
void OnFrameVisibilityChanged(const FrameNode* frame_node,
FrameNode::Visibility previous_value) override;
private:
VotingChannelWrapper voting_channel_;
};
} // namespace execution_context_priority
} // namespace performance_manager
#endif // CHROME_BROWSER_PERFORMANCE_MANAGER_DECORATORS_EXECUTION_CONTEXT_PRIORITY_FRAME_VISIBILITY_VOTER_H_