Commit 515b9ac4 authored by Maksim Ivanov's avatar Maksim Ivanov Committed by Commit Bot

Fix DCHECK in TestBackgroundPageFirstLoadObserver

Fix the problem with the DCHECK in
TestBackgroundPageFirstLoadObserver::OnBackgroundHostCreated() being hit
in case when the extension's background page host gets destroyed and
recreated.

The DCHECK was fired because the class didn't expect to observe more
than one host at the same time. The underlying issue was that the class
didn't stop observing the deleted host, leading to the DCHECK hit and a
potential use-after-free (in tests).

Bug: 1090941
Test: stress-test the "CertificateProviderApiTest.LazyBackgroundPage" browser test after applying crrev.com/c/2312817
Change-Id: I91cf8f3bb0126a04b63e3a73d3f39259c621f330
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2312799Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Commit-Queue: Maksim Ivanov <emaxx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791054}
parent a0e43f30
...@@ -37,6 +37,14 @@ void TestBackgroundPageFirstLoadObserver::OnBackgroundHostCreated( ...@@ -37,6 +37,14 @@ void TestBackgroundPageFirstLoadObserver::OnBackgroundHostCreated(
} }
} }
void TestBackgroundPageFirstLoadObserver::OnExtensionHostDestroyed(
ExtensionHost* host) {
if (host->extension_id() == extension_id_) {
extension_host_observer_.Remove(host);
extension_host_ = nullptr;
}
}
void TestBackgroundPageFirstLoadObserver::OnExtensionHostDidStopFirstLoad( void TestBackgroundPageFirstLoadObserver::OnExtensionHostDidStopFirstLoad(
const ExtensionHost* host) { const ExtensionHost* host) {
run_loop_.Quit(); run_loop_.Quit();
......
...@@ -18,10 +18,10 @@ namespace content { ...@@ -18,10 +18,10 @@ namespace content {
class BrowserContext; class BrowserContext;
} }
// Allows to wait until the WebContents of an extension's ExtensionHost sees its
// first DidStopLoading().
namespace extensions { namespace extensions {
// Allows to wait until the WebContents of an extension's ExtensionHost sees its
// first DidStopLoading().
class TestBackgroundPageFirstLoadObserver : public ProcessManagerObserver, class TestBackgroundPageFirstLoadObserver : public ProcessManagerObserver,
public ExtensionHostObserver { public ExtensionHostObserver {
public: public:
...@@ -36,6 +36,7 @@ class TestBackgroundPageFirstLoadObserver : public ProcessManagerObserver, ...@@ -36,6 +36,7 @@ class TestBackgroundPageFirstLoadObserver : public ProcessManagerObserver,
void OnBackgroundHostCreated(ExtensionHost* host) override; void OnBackgroundHostCreated(ExtensionHost* host) override;
// ExtensionHostObserver: // ExtensionHostObserver:
void OnExtensionHostDestroyed(ExtensionHost* host) override;
void OnExtensionHostDidStopFirstLoad(const ExtensionHost* host) override; void OnExtensionHostDidStopFirstLoad(const ExtensionHost* host) override;
void OnObtainedExtensionHost(); void OnObtainedExtensionHost();
......
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