Commit d6dcf872 authored by rchlodnicki's avatar rchlodnicki Committed by Commit bot

Fix crash on referencing deleted SignedInDevicesManager observer

Each profile creates new instance of SignedInDevicesManager so, for example,
opening incognito window and then closing it, destroyes an instance of
SignedInDevicesManager created for this profile. The code has forgot to remove
itself from the list of observers in EventRouter.
That caused crash when that event was triggered later in a normal profile as
EventRouter would reference stale pointer.

In tests observer is not added and profile_ is null so null-checking it.

R=rdevlin.cronin@chromium.org
BUG=

Review URL: https://codereview.chromium.org/980663002

Cr-Commit-Position: refs/heads/master@{#319755}
parent 7ac894e6
......@@ -104,7 +104,7 @@ SignedInDevicesManager::SignedInDevicesManager()
SignedInDevicesManager::SignedInDevicesManager(content::BrowserContext* context)
: profile_(Profile::FromBrowserContext(context)),
extension_registry_observer_(this) {
extensions::EventRouter* router = extensions::EventRouter::Get(profile_);
EventRouter* router = EventRouter::Get(profile_);
if (router) {
router->RegisterObserver(
this, api::signed_in_devices::OnDeviceInfoChange::kEventName);
......@@ -115,7 +115,13 @@ SignedInDevicesManager::SignedInDevicesManager(content::BrowserContext* context)
extension_registry_observer_.Add(ExtensionRegistry::Get(profile_));
}
SignedInDevicesManager::~SignedInDevicesManager() {}
SignedInDevicesManager::~SignedInDevicesManager() {
if (profile_) {
EventRouter* router = EventRouter::Get(profile_);
if (router)
router->UnregisterObserver(this);
}
}
void SignedInDevicesManager::OnListenerAdded(
const EventListenerInfo& details) {
......
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