Commit e4603aa4 authored by Nicolas Ouellet-Payeur's avatar Nicolas Ouellet-Payeur Committed by Commit Bot

[Reporting] Fix a crash in ~ExtensionRequestObserver()

The DestroyProfileOnBrowserClose experiment
(see go/destroy-profile-on-browser-close) changes profile teardown,
and introduced a new crash. ExtensionRequestObservers should be
destroyed before the Profile is destroyed, not during BrowserProcess
teardown.

Listen to OnProfileWillBeDestroyed() events for _all_ profiles, because
they can get destroyed at any time. Previously, we only did this for
some profiles.

Bug: 88586, 1140492
Change-Id: I8657119ae36c763b6e2e515185f1d2f15586376c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2485176
Commit-Queue: Nicolas Ouellet-Payeur <nicolaso@chromium.org>
Reviewed-by: default avatarOwen Min <zmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819062}
parent a9b6d2bd
......@@ -24,9 +24,13 @@ ExtensionRequestObserverFactory::ExtensionRequestObserverFactory(
}
ExtensionRequestObserverFactory::~ExtensionRequestObserverFactory() {
if (profile_) {
profile_->RemoveObserver(this);
} else if (g_browser_process->profile_manager()) {
// Remove any pending observers.
for (const auto& entry : observers_) {
Profile* profile = entry.first;
profile->RemoveObserver(this);
}
if (!profile_ && g_browser_process->profile_manager()) {
g_browser_process->profile_manager()->RemoveObserver(this);
}
}
......@@ -40,29 +44,22 @@ void ExtensionRequestObserverFactory::OnProfileAdded(Profile* profile) {
if (profile_ && (profile_ != profile || !observers_.empty()))
return;
if (profile_)
profile->AddObserver(this);
// Listen for OnProfileWillBeDestroyed() on this profile.
profile->AddObserver(this);
observers_.emplace(profile,
std::make_unique<ExtensionRequestObserver>(profile));
}
void ExtensionRequestObserverFactory::OnProfileMarkedForPermanentDeletion(
Profile* profile) {
if (profile_ && profile_ == profile)
profile->RemoveObserver(this);
profile->RemoveObserver(this);
observers_.erase(profile);
}
void ExtensionRequestObserverFactory::OnProfileWillBeDestroyed(
Profile* profile) {
DCHECK(profile_);
if (profile_ == profile) {
profile->RemoveObserver(this);
observers_.erase(profile);
}
profile->RemoveObserver(this);
observers_.erase(profile);
}
ExtensionRequestObserver*
......
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