Commit 2bf4e675 authored by Lukasz Anforowicz's avatar Lukasz Anforowicz Committed by Commit Bot

Avoid infinite loops in SpellcheckService::OnCustomDictionaryChanged.

r567099 introduced a bug, where the loop in
SpellcheckService::OnCustomDictionaryChanged could spin forever
without calling RenderProcessHost::iterator::Advance.  This CL fixes
this.

Bug: 854540
Change-Id: I6a1829a3595a1414ceb75b125b54a4576b3c02a6
Reviewed-on: https://chromium-review.googlesource.com/1108540Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569489}
parent b37aa2ad
...@@ -283,14 +283,14 @@ void SpellcheckService::OnCustomDictionaryChanged( ...@@ -283,14 +283,14 @@ void SpellcheckService::OnCustomDictionaryChanged(
const SpellcheckCustomDictionary::Change& change) { const SpellcheckCustomDictionary::Change& change) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
auto process_hosts(content::RenderProcessHost::AllHostsIterator());
const std::vector<std::string> additions(change.to_add().begin(), const std::vector<std::string> additions(change.to_add().begin(),
change.to_add().end()); change.to_add().end());
const std::vector<std::string> deletions(change.to_remove().begin(), const std::vector<std::string> deletions(change.to_remove().begin(),
change.to_remove().end()); change.to_remove().end());
while (!process_hosts.IsAtEnd()) { for (content::RenderProcessHost::iterator it(
content::RenderProcessHost* process = process_hosts.GetCurrentValue(); content::RenderProcessHost::AllHostsIterator());
!it.IsAtEnd(); it.Advance()) {
content::RenderProcessHost* process = it.GetCurrentValue();
if (!process->IsInitializedAndNotDead()) if (!process->IsInitializedAndNotDead())
continue; continue;
...@@ -302,7 +302,6 @@ void SpellcheckService::OnCustomDictionaryChanged( ...@@ -302,7 +302,6 @@ void SpellcheckService::OnCustomDictionaryChanged(
renderer_identity.instance()), renderer_identity.instance()),
&spellchecker); &spellchecker);
spellchecker->CustomDictionaryChanged(additions, deletions); spellchecker->CustomDictionaryChanged(additions, deletions);
process_hosts.Advance();
} }
} }
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "components/spellcheck/common/spellcheck_common.h" #include "components/spellcheck/common/spellcheck_common.h"
#include "components/spellcheck/common/spellcheck_result.h" #include "components/spellcheck/common/spellcheck_result.h"
#include "components/user_prefs/user_prefs.h" #include "components/user_prefs/user_prefs.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/mock_render_process_host.h" #include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
...@@ -386,6 +387,28 @@ IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, CustomDictionaryChanged) { ...@@ -386,6 +387,28 @@ IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, CustomDictionaryChanged) {
EXPECT_TRUE(GetCustomDictionaryChangedState()); EXPECT_TRUE(GetCustomDictionaryChangedState());
} }
// Regression test for https://crbug.com/854540.
IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest,
CustomDictionaryChangedAfterRendererCrash) {
InitSpellcheck(true, "en-US", "");
EXPECT_TRUE(GetEnableSpellcheckState());
// Kill the renderer process.
content::RenderProcessHost* process = browser()
->tab_strip_model()
->GetActiveWebContents()
->GetMainFrame()
->GetProcess();
content::RenderProcessHostWatcher crash_observer(
process, content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
EXPECT_TRUE(process->Shutdown(0));
crash_observer.Wait();
// Change the custom dictionary - the test passes if there were no crashes or
// hangs.
ChangeCustomDictionary();
}
// Starting with only a single-language spellcheck setting, the host should // Starting with only a single-language spellcheck setting, the host should
// initialize the renderer's spellcheck system, and the same if the renderer // initialize the renderer's spellcheck system, and the same if the renderer
// explicity requests the spellcheck dictionaries. // explicity requests the spellcheck dictionaries.
......
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