Index: chromeos/dbus/power_manager_client.cc |
diff --git a/chromeos/dbus/power_manager_client.cc b/chromeos/dbus/power_manager_client.cc |
index d8d835da398e1bd93743d9706a0c4d6cb54fca69..8431a96ca2dd833def57f4e4923ccd6b008f23d8 100644 |
--- a/chromeos/dbus/power_manager_client.cc |
+++ b/chromeos/dbus/power_manager_client.cc |
@@ -543,6 +543,7 @@ class PowerManagerClientImpl : public PowerManagerClient { |
suspend_is_pending_ = true; |
suspending_from_dark_resume_ = in_dark_resume; |
num_pending_suspend_readiness_callbacks_ = 0; |
+ |
if (suspending_from_dark_resume_) |
FOR_EACH_OBSERVER(Observer, observers_, DarkSuspendImminent()); |
else |
@@ -567,9 +568,23 @@ class PowerManagerClientImpl : public PowerManagerClient { |
<< " suspend_id=" << proto.suspend_id() |
<< " duration=" << duration.InSeconds() << " sec"; |
- if (render_process_manager_delegate_) |
+ // RenderProcessManagerDelegate is only notified that suspend is imminent |
+ // when readiness is being reported to powerd. If the suspend attempt was |
+ // cancelled before then, we shouldn't notify the delegate about completion. |
+ const bool cancelled_while_regular_suspend_pending = |
+ suspend_is_pending_ && !suspending_from_dark_resume_; |
+ if (render_process_manager_delegate_ && |
+ !cancelled_while_regular_suspend_pending) |
render_process_manager_delegate_->SuspendDone(); |
+ // powerd always pairs each SuspendImminent signal with SuspendDone before |
+ // starting the next suspend attempt, so we should no longer report |
+ // readiness for any in-progress suspend attempts. |
+ pending_suspend_id_ = -1; |
+ suspend_is_pending_ = false; |
+ suspending_from_dark_resume_ = false; |
+ num_pending_suspend_readiness_callbacks_ = 0; |
+ |
FOR_EACH_OBSERVER( |
PowerManagerClient::Observer, observers_, SuspendDone(duration)); |
base::PowerMonitorDeviceSource::HandleSystemResumed(); |
@@ -711,7 +726,9 @@ class PowerManagerClientImpl : public PowerManagerClient { |
// Reports suspend readiness to powerd if no observers are still holding |
// suspend readiness callbacks. |
void MaybeReportSuspendReadiness() { |
- if (!suspend_is_pending_ || num_pending_suspend_readiness_callbacks_ > 0) |
+ CHECK(suspend_is_pending_); |
+ |
+ if (num_pending_suspend_readiness_callbacks_ > 0) |
return; |
std::string method_name; |
@@ -756,16 +773,16 @@ class PowerManagerClientImpl : public PowerManagerClient { |
dbus::ObjectProxy* power_manager_proxy_; |
base::ObserverList<Observer> observers_; |
- // The delay_id_ obtained from the RegisterSuspendDelay request. |
+ // The delay ID obtained from the RegisterSuspendDelay request. |
int32_t suspend_delay_id_; |
bool has_suspend_delay_id_; |
- // The delay_id_ obtained from the RegisterDarkSuspendDelay request. |
+ // The delay ID obtained from the RegisterDarkSuspendDelay request. |
int32_t dark_suspend_delay_id_; |
bool has_dark_suspend_delay_id_; |
- // powerd-supplied ID corresponding to an imminent suspend attempt that is |
- // currently being delayed. |
+ // powerd-supplied ID corresponding to an imminent (either regular or dark) |
+ // suspend attempt that is currently being delayed. |
int32_t pending_suspend_id_; |
bool suspend_is_pending_; |