Commit 9c1bd002 authored by Patrick Monette's avatar Patrick Monette Committed by Commit Bot

[PM] Migrate BoostingVoteAggregator to VotingChannelWrapper.

Bug: 971272
Change-Id: I8beac0e036d84884e4c13a2b7d84c4d8b2d1ce6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2533535
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828604}
parent 53445e10
......@@ -256,10 +256,7 @@ VotingChannel BoostingVoteAggregator::GetVotingChannel() {
}
void BoostingVoteAggregator::SetUpstreamVotingChannel(VotingChannel&& channel) {
DCHECK(channel.IsValid());
DCHECK(nodes_.empty());
DCHECK(!channel_.IsValid());
channel_ = std::move(channel);
channel_.SetVotingChannel(std::move(channel));
}
bool BoostingVoteAggregator::IsSetup() const {
......@@ -549,8 +546,10 @@ void BoostingVoteAggregator::UpstreamVoteIfNeeded(
// default priority level of every execution context in the absence of any
// specific higher votes.
if (priority == base::TaskPriority::LOWEST) {
if (node_data->HasOutgoingVote())
if (node_data->HasOutgoingVote()) {
channel_.InvalidateVote(execution_context);
node_data->CancelOutgoingVote();
}
return;
}
......@@ -560,13 +559,13 @@ void BoostingVoteAggregator::UpstreamVoteIfNeeded(
// If the node already has a vote, then change it. This is a nop if the vote
// details are identical.
if (node_data->HasOutgoingVote()) {
node_data->ChangeOutgoingVote(priority, reason);
channel_.ChangeVote(execution_context, Vote(priority, reason));
return;
}
// Create an outgoing vote.
node_data->SetOutgoingVoteReceipt(
channel_.SubmitVote(execution_context, Vote(priority, reason)));
node_data->SetHasOutgoingVote();
channel_.SubmitVote(execution_context, Vote(priority, reason));
}
void BoostingVoteAggregator::UpstreamChanges(const NodeDataPtrSet& changes) {
......
......@@ -128,7 +128,6 @@ class BoostingVoteAggregator : public VoteObserver {
~NodeData();
const Vote& incoming_vote() const { return incoming_vote_.value(); }
const VoteReceipt& receipt() const { return receipt_; }
void SetIncomingVote(const Vote& incoming_vote) {
DCHECK(!incoming_vote_.has_value());
......@@ -143,13 +142,13 @@ class BoostingVoteAggregator : public VoteObserver {
incoming_vote_ = base::nullopt;
}
// For modifying |receipt_|.
void ChangeOutgoingVote(base::TaskPriority priority, const char* reason) {
receipt_.ChangeVote(priority, reason);
void CancelOutgoingVote() {
DCHECK(has_outgoing_vote_);
has_outgoing_vote_ = false;
}
void CancelOutgoingVote() { receipt_.Reset(); }
void SetOutgoingVoteReceipt(VoteReceipt&& receipt) {
receipt_ = std::move(receipt);
void SetHasOutgoingVote() {
DCHECK(!has_outgoing_vote_);
has_outgoing_vote_ = true;
}
// Returns true if this node has an active |incoming| vote. If false that
......@@ -157,9 +156,8 @@ class BoostingVoteAggregator : public VoteObserver {
// Same as |incoming_vote_.has_value()|, but more readable.
bool HasIncomingVote() const { return incoming_vote_.has_value(); }
// Returns true if this node has an active outgoing vote. Same as
// |receipt_.HasVote()|, but more readable.
bool HasOutgoingVote() const { return receipt_.HasVote(); }
// Returns true if this node has an active outgoing vote.
bool HasOutgoingVote() const { return has_outgoing_vote_; }
// Returns true if this node is involved in any edges.
bool HasEdges() const { return edge_count_ > 0; }
......@@ -183,8 +181,9 @@ class BoostingVoteAggregator : public VoteObserver {
// The input vote we've received, if any.
base::Optional<Vote> incoming_vote_;
// The receipt for the vote we've upstreamed, if any.
VoteReceipt receipt_;
// Indicates that a corresponding vote has been emitted via the
// voting channel.
bool has_outgoing_vote_ = false;
};
// NOTE: It is important that NodeDataMap preserve pointers to NodeData
......@@ -371,7 +370,7 @@ class BoostingVoteAggregator : public VoteObserver {
voting::VoterId<Vote> input_voter_id_ = voting::kInvalidVoterId<Vote>;
// Our channel for upstreaming our votes.
VotingChannel channel_;
VotingChannelWrapper channel_;
// Provides a VotingChannel to our input voter.
VoteConsumerDefaultImpl vote_consumer_default_impl_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment