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() { ...@@ -256,10 +256,7 @@ VotingChannel BoostingVoteAggregator::GetVotingChannel() {
} }
void BoostingVoteAggregator::SetUpstreamVotingChannel(VotingChannel&& channel) { void BoostingVoteAggregator::SetUpstreamVotingChannel(VotingChannel&& channel) {
DCHECK(channel.IsValid()); channel_.SetVotingChannel(std::move(channel));
DCHECK(nodes_.empty());
DCHECK(!channel_.IsValid());
channel_ = std::move(channel);
} }
bool BoostingVoteAggregator::IsSetup() const { bool BoostingVoteAggregator::IsSetup() const {
...@@ -549,8 +546,10 @@ void BoostingVoteAggregator::UpstreamVoteIfNeeded( ...@@ -549,8 +546,10 @@ void BoostingVoteAggregator::UpstreamVoteIfNeeded(
// default priority level of every execution context in the absence of any // default priority level of every execution context in the absence of any
// specific higher votes. // specific higher votes.
if (priority == base::TaskPriority::LOWEST) { if (priority == base::TaskPriority::LOWEST) {
if (node_data->HasOutgoingVote()) if (node_data->HasOutgoingVote()) {
channel_.InvalidateVote(execution_context);
node_data->CancelOutgoingVote(); node_data->CancelOutgoingVote();
}
return; return;
} }
...@@ -560,13 +559,13 @@ void BoostingVoteAggregator::UpstreamVoteIfNeeded( ...@@ -560,13 +559,13 @@ void BoostingVoteAggregator::UpstreamVoteIfNeeded(
// If the node already has a vote, then change it. This is a nop if the vote // If the node already has a vote, then change it. This is a nop if the vote
// details are identical. // details are identical.
if (node_data->HasOutgoingVote()) { if (node_data->HasOutgoingVote()) {
node_data->ChangeOutgoingVote(priority, reason); channel_.ChangeVote(execution_context, Vote(priority, reason));
return; return;
} }
// Create an outgoing vote. // Create an outgoing vote.
node_data->SetOutgoingVoteReceipt( node_data->SetHasOutgoingVote();
channel_.SubmitVote(execution_context, Vote(priority, reason))); channel_.SubmitVote(execution_context, Vote(priority, reason));
} }
void BoostingVoteAggregator::UpstreamChanges(const NodeDataPtrSet& changes) { void BoostingVoteAggregator::UpstreamChanges(const NodeDataPtrSet& changes) {
......
...@@ -128,7 +128,6 @@ class BoostingVoteAggregator : public VoteObserver { ...@@ -128,7 +128,6 @@ class BoostingVoteAggregator : public VoteObserver {
~NodeData(); ~NodeData();
const Vote& incoming_vote() const { return incoming_vote_.value(); } const Vote& incoming_vote() const { return incoming_vote_.value(); }
const VoteReceipt& receipt() const { return receipt_; }
void SetIncomingVote(const Vote& incoming_vote) { void SetIncomingVote(const Vote& incoming_vote) {
DCHECK(!incoming_vote_.has_value()); DCHECK(!incoming_vote_.has_value());
...@@ -143,13 +142,13 @@ class BoostingVoteAggregator : public VoteObserver { ...@@ -143,13 +142,13 @@ class BoostingVoteAggregator : public VoteObserver {
incoming_vote_ = base::nullopt; incoming_vote_ = base::nullopt;
} }
// For modifying |receipt_|. void CancelOutgoingVote() {
void ChangeOutgoingVote(base::TaskPriority priority, const char* reason) { DCHECK(has_outgoing_vote_);
receipt_.ChangeVote(priority, reason); has_outgoing_vote_ = false;
} }
void CancelOutgoingVote() { receipt_.Reset(); } void SetHasOutgoingVote() {
void SetOutgoingVoteReceipt(VoteReceipt&& receipt) { DCHECK(!has_outgoing_vote_);
receipt_ = std::move(receipt); has_outgoing_vote_ = true;
} }
// Returns true if this node has an active |incoming| vote. If false that // Returns true if this node has an active |incoming| vote. If false that
...@@ -157,9 +156,8 @@ class BoostingVoteAggregator : public VoteObserver { ...@@ -157,9 +156,8 @@ class BoostingVoteAggregator : public VoteObserver {
// Same as |incoming_vote_.has_value()|, but more readable. // Same as |incoming_vote_.has_value()|, but more readable.
bool HasIncomingVote() const { return incoming_vote_.has_value(); } bool HasIncomingVote() const { return incoming_vote_.has_value(); }
// Returns true if this node has an active outgoing vote. Same as // Returns true if this node has an active outgoing vote.
// |receipt_.HasVote()|, but more readable. bool HasOutgoingVote() const { return has_outgoing_vote_; }
bool HasOutgoingVote() const { return receipt_.HasVote(); }
// Returns true if this node is involved in any edges. // Returns true if this node is involved in any edges.
bool HasEdges() const { return edge_count_ > 0; } bool HasEdges() const { return edge_count_ > 0; }
...@@ -183,8 +181,9 @@ class BoostingVoteAggregator : public VoteObserver { ...@@ -183,8 +181,9 @@ class BoostingVoteAggregator : public VoteObserver {
// The input vote we've received, if any. // The input vote we've received, if any.
base::Optional<Vote> incoming_vote_; base::Optional<Vote> incoming_vote_;
// The receipt for the vote we've upstreamed, if any. // Indicates that a corresponding vote has been emitted via the
VoteReceipt receipt_; // voting channel.
bool has_outgoing_vote_ = false;
}; };
// NOTE: It is important that NodeDataMap preserve pointers to NodeData // NOTE: It is important that NodeDataMap preserve pointers to NodeData
...@@ -371,7 +370,7 @@ class BoostingVoteAggregator : public VoteObserver { ...@@ -371,7 +370,7 @@ class BoostingVoteAggregator : public VoteObserver {
voting::VoterId<Vote> input_voter_id_ = voting::kInvalidVoterId<Vote>; voting::VoterId<Vote> input_voter_id_ = voting::kInvalidVoterId<Vote>;
// Our channel for upstreaming our votes. // Our channel for upstreaming our votes.
VotingChannel channel_; VotingChannelWrapper channel_;
// Provides a VotingChannel to our input voter. // Provides a VotingChannel to our input voter.
VoteConsumerDefaultImpl vote_consumer_default_impl_; 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