Commit c8fb7394 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Iterate over the ReceiverIds for FlushForTesting in ReceiverSet

This CL changes how to iterate |receivers_| for
FlushForTesting in ReceiverSet.
It snapshots the ReceiverIds first, then iterates over
them instead of directly accessing to |receivers_|
because it could be mutated during individual flush
operations.

The original CL is [1] for BindingSet.

[1]https://crrev.com/c/514465

Bug: 955171, 978694
Change-Id: Ie35573b6d59ba103818f6ce3e3ea7ad85de512ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1757649Reviewed-by: default avatarKen Rockot <rockot@google.com>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#689364}
parent c8d5ad5a
...@@ -231,9 +231,22 @@ class ReceiverSetBase { ...@@ -231,9 +231,22 @@ class ReceiverSetBase {
} }
void FlushForTesting() { void FlushForTesting() {
for (const auto& it : receivers_) { // We avoid flushing while iterating over |receivers_| because this set
if (it.second) // may be mutated during individual flush operations. Instead, snapshot
it.second->FlushForTesting(); // the ReceiverIds first, then iterate over them. This is less efficient,
// but it's only a testing API. This also allows for correct behavior in
// reentrant calls to FlushForTesting().
std::vector<ReceiverId> ids;
for (const auto& receiver : receivers_)
ids.push_back(receiver.first);
auto weak_self = weak_ptr_factory_.GetWeakPtr();
for (const auto& id : ids) {
if (!weak_self)
return;
auto it = receivers_.find(id);
if (it != receivers_.end())
it->second->FlushForTesting();
} }
} }
......
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