1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/performance_manager/execution_context_priority/root_vote_observer.h"
#include "components/performance_manager/graph/frame_node_impl.h"
#include "components/performance_manager/graph/worker_node_impl.h"
#include "components/performance_manager/public/execution_context/execution_context.h"
namespace performance_manager {
namespace execution_context_priority {
namespace {
// Sets the priority of an execution context.
void SetPriorityAndReason(
const execution_context::ExecutionContext* execution_context,
const PriorityAndReason& priority_and_reason) {
// No property changes while the node is leaving graph.
if (execution_context->GetNodeState() == NodeState::kLeavingGraph) {
return;
}
switch (execution_context->GetType()) {
case execution_context::ExecutionContextType::kFrameNode:
FrameNodeImpl::FromNode(execution_context->GetFrameNode())
->SetPriorityAndReason(priority_and_reason);
break;
case execution_context::ExecutionContextType::kWorkerNode:
WorkerNodeImpl::FromNode(execution_context->GetWorkerNode())
->SetPriorityAndReason(priority_and_reason);
break;
}
}
} // namespace
RootVoteObserver::RootVoteObserver() = default;
RootVoteObserver::~RootVoteObserver() = default;
VotingChannel RootVoteObserver::GetVotingChannel() {
DCHECK_EQ(0u, voting_channel_factory_.voting_channels_issued());
auto channel = voting_channel_factory_.BuildVotingChannel();
voter_id_ = channel.voter_id();
return channel;
}
void RootVoteObserver::OnVoteSubmitted(
VoterId voter_id,
const ExecutionContext* execution_context,
const Vote& vote) {
DCHECK_EQ(voter_id_, voter_id);
SetPriorityAndReason(execution_context,
PriorityAndReason(vote.value(), vote.reason()));
}
void RootVoteObserver::OnVoteChanged(VoterId voter_id,
const ExecutionContext* execution_context,
const Vote& new_vote) {
DCHECK_EQ(voter_id_, voter_id);
SetPriorityAndReason(execution_context,
PriorityAndReason(new_vote.value(), new_vote.reason()));
}
void RootVoteObserver::OnVoteInvalidated(
VoterId voter_id,
const ExecutionContext* execution_context) {
DCHECK_EQ(voter_id_, voter_id);
SetPriorityAndReason(
execution_context,
PriorityAndReason(base::TaskPriority::LOWEST,
FrameNodeImpl::kDefaultPriorityReason));
}
} // namespace execution_context_priority
} // namespace performance_manager
|