Commit 1a1fd180 authored by chirantan's avatar chirantan Committed by Commit bot

Fix crash on suspend for chrome os

If RendererFreezer::SuspendImminent was called multiple times before it
had a chance to report readiness, it would post multiple tasks to do so
on the current message loop.  However the callback to report readiness
would be cleared after the first task ran and would cause a crash when
the next task tried to run it.  Fix this by not posting new tasks while
a callback is pending and just update the callback instead.

BUG=414396
Signed-off-by: default avatarChirantan Ekbote <chirantan@chromium.org>

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

Cr-Commit-Position: refs/heads/master@{#294916}
parent b44e27dd
...@@ -23,14 +23,21 @@ const char kThawCommand[] = "THAWED"; ...@@ -23,14 +23,21 @@ const char kThawCommand[] = "THAWED";
} // namespace } // namespace
void RendererFreezer::SuspendImminent() { void RendererFreezer::SuspendImminent() {
suspend_readiness_callback_ = DBusThreadManager::Get() // SuspendImminent() might end up being called multiple times before we run
->GetPowerManagerClient() // OnReadyToSuspend() (crbug.com/414396). In case a callback is already
->GetSuspendReadinessCallback(); // pending, we only store the new callback and do nothing else.
if (suspend_readiness_callback_.is_null()) {
// There is no callback pending so post the task.
base::MessageLoop::current()->PostTask( base::MessageLoop::current()->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(&RendererFreezer::OnReadyToSuspend, base::Bind(&RendererFreezer::OnReadyToSuspend,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
}
// Always update the callback because only the most recent one matters.
suspend_readiness_callback_ = DBusThreadManager::Get()
->GetPowerManagerClient()
->GetSuspendReadinessCallback();
} }
void RendererFreezer::SuspendDone(const base::TimeDelta& sleep_duration) { void RendererFreezer::SuspendDone(const base::TimeDelta& sleep_duration) {
...@@ -56,7 +63,7 @@ void RendererFreezer::OnReadyToSuspend() { ...@@ -56,7 +63,7 @@ void RendererFreezer::OnReadyToSuspend() {
frozen_ = true; frozen_ = true;
} }
DCHECK(!suspend_readiness_callback_.is_null()); CHECK(!suspend_readiness_callback_.is_null()); // crbug.com/414396
suspend_readiness_callback_.Run(); suspend_readiness_callback_.Run();
suspend_readiness_callback_.Reset(); suspend_readiness_callback_.Reset();
} }
......
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