Commit c15b478b authored by Denis Bessonov's avatar Denis Bessonov Committed by Commit Bot

Use for loop instead of while in GetExistingProcessHost

In RenderProcessHostImpl::GetExistingProcessHost, there is a loop
that enumerates all current process hosts. It is implement as a
while loop having iter.Advance() at the end.

Lets assume a situation when one decides to prohibit some process
host from being put to suitable_renderers list. The obvious solution
is to check some condition and use continue statement to move to
next loop iteration... which results in an infinite loop if
iter.Advance() isn't called prior to continue.

So it looks more safe to use for loop instead as it executes its
3rd part automatically reducing the human factor influence.

This CL is a pure refactoring so there is no behavior change at all.

Change-Id: I456cd2ff5348172419e8561d4ebf75d886a02e15
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2071016
Commit-Queue: Alex Moshchuk <alexmos@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Auto-Submit: Denis Bessonov <dbessonov@yandex-team.ru>
Cr-Commit-Position: refs/heads/master@{#744396}
parent 190b80ce
...@@ -4093,8 +4093,7 @@ RenderProcessHost* RenderProcessHostImpl::GetExistingProcessHost( ...@@ -4093,8 +4093,7 @@ RenderProcessHost* RenderProcessHostImpl::GetExistingProcessHost(
std::vector<RenderProcessHost*> suitable_renderers; std::vector<RenderProcessHost*> suitable_renderers;
suitable_renderers.reserve(GetAllHosts().size()); suitable_renderers.reserve(GetAllHosts().size());
iterator iter(AllHostsIterator()); for (iterator iter(AllHostsIterator()); !iter.IsAtEnd(); iter.Advance()) {
while (!iter.IsAtEnd()) {
if (iter.GetCurrentValue()->MayReuseHost() && if (iter.GetCurrentValue()->MayReuseHost() &&
RenderProcessHostImpl::IsSuitableHost( RenderProcessHostImpl::IsSuitableHost(
iter.GetCurrentValue(), site_instance->GetIsolationContext(), iter.GetCurrentValue(), site_instance->GetIsolationContext(),
...@@ -4107,7 +4106,6 @@ RenderProcessHost* RenderProcessHostImpl::GetExistingProcessHost( ...@@ -4107,7 +4106,6 @@ RenderProcessHost* RenderProcessHostImpl::GetExistingProcessHost(
suitable_renderers.push_back(iter.GetCurrentValue()); suitable_renderers.push_back(iter.GetCurrentValue());
} }
iter.Advance();
} }
// Now pick a random suitable renderer, if we have any. // Now pick a random suitable renderer, if we have any.
......
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