Commit 8438c305 authored by Ravjit Singh Uppal's avatar Ravjit Singh Uppal Committed by Chromium LUCI CQ

Fix crash in destructor of OneTimeGeolocationPermissionProvider in linux-chromeos builds.

The OneTimeGeolocationPermissionProvider tries to unregister itself from an already shutdown context, causing the crash.
Update the observer unregistration pattern in the OneTimeGeolocationPermissionProvider to handle the case of the context being already shutdown.

Bug: 1168488
Change-Id: Id92b9a3b15410b3732d9021a666282ad1f568036
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2640096
Commit-Queue: Ravjit Singh Uppal <ravjit@chromium.org>
Commit-Queue: Balazs Engedy <engedy@chromium.org>
Reviewed-by: default avatarRavjit Singh Uppal <ravjit@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845321}
parent 4de7bcf1
......@@ -45,15 +45,15 @@ class OneTimeRuleIterator : public content_settings::RuleIterator {
} // namespace
OneTimeGeolocationPermissionProvider::OneTimeGeolocationPermissionProvider(
content::BrowserContext* browser_context)
: browser_context_(browser_context) {
LastTabStandingTrackerFactory::GetForBrowserContext(browser_context)
->AddObserver(this);
content::BrowserContext* browser_context) {
last_tab_standing_tracker_ =
LastTabStandingTrackerFactory::GetForBrowserContext(browser_context);
last_tab_standing_tracker_->AddObserver(this);
}
OneTimeGeolocationPermissionProvider::~OneTimeGeolocationPermissionProvider() {
LastTabStandingTrackerFactory::GetForBrowserContext(browser_context_)
->RemoveObserver(this);
if (last_tab_standing_tracker_)
last_tab_standing_tracker_->RemoveObserver(this);
}
std::unique_ptr<content_settings::RuleIterator>
......@@ -136,3 +136,7 @@ void OneTimeGeolocationPermissionProvider::OnLastPageFromOriginClosed(
}
}
}
void OneTimeGeolocationPermissionProvider::OnShutdown() {
last_tab_standing_tracker_ = nullptr;
}
......@@ -15,6 +15,7 @@
namespace content {
class BrowserContext;
}
class LastTabStandingTracker;
// Stores one-time per-origin geolocation permissions grants that expire as
// soon as the last tab from an origin is closed but after one day at the
......@@ -59,9 +60,11 @@ class OneTimeGeolocationPermissionProvider
// LastTabStandingTrackerObserver:
void OnLastPageFromOriginClosed(const url::Origin&) override;
void OnShutdown() override;
private:
PatternToGrantTimeMap grants_with_open_tabs_;
content::BrowserContext* browser_context_;
LastTabStandingTracker* last_tab_standing_tracker_ = nullptr;
};
#endif // CHROME_BROWSER_CONTENT_SETTINGS_ONE_TIME_GEOLOCATION_PERMISSION_PROVIDER_H_
......@@ -12,6 +12,9 @@ LastTabStandingTracker::LastTabStandingTracker() = default;
LastTabStandingTracker::~LastTabStandingTracker() = default;
void LastTabStandingTracker::Shutdown() {
for (auto& observer : observer_list_) {
observer.OnShutdown();
}
observer_list_.Clear();
}
......
......@@ -13,6 +13,12 @@ class LastTabStandingTrackerObserver : public base::CheckedObserver {
// Event fired when the last tab in a given Profile whose top-level document
// is from |origin| is closed or navigated away.
virtual void OnLastPageFromOriginClosed(const url::Origin&) = 0;
// Event fired to let the observers know that the BrowserContext is going to
// shut down.
// The observers don't need to take care of removing themselves as an
// observer.
virtual void OnShutdown() = 0;
};
#endif // CHROME_BROWSER_PERMISSIONS_LAST_TAB_STANDING_TRACKER_OBSERVER_H_
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