Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2840)

Unified Diff: ash/system/chromeos/power/power_event_observer.cc

Issue 2296003002: ABANDONED: chromeos: Resume displays when suspend is cancelled. (Closed)
Patch Set: fix comment Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/system/chromeos/power/power_event_observer.cc
diff --git a/ash/system/chromeos/power/power_event_observer.cc b/ash/system/chromeos/power/power_event_observer.cc
index 663a8a613876b67e12d9c7bb4aae4bf5a22c3336..768d8c28d5070cf8b275f1f6f948b2fd1210067d 100644
--- a/ash/system/chromeos/power/power_event_observer.cc
+++ b/ash/system/chromeos/power/power_event_observer.cc
@@ -9,6 +9,7 @@
#include "ash/common/wm_shell.h"
#include "ash/shell.h"
#include "ash/wm/power_button_controller.h"
+#include "base/threading/thread_task_runner_handle.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
@@ -36,15 +37,14 @@ void ResumeRenderingRequests() {
window->GetHost()->compositor()->SetVisible(true);
}
-void OnSuspendDisplaysCompleted(const base::Closure& suspend_callback,
- bool status) {
- suspend_callback.Run();
-}
-
} // namespace
PowerEventObserver::PowerEventObserver()
- : screen_locked_(false), waiting_for_lock_screen_animations_(false) {
+ : screen_locked_(false),
+ waiting_for_lock_screen_animations_(false),
+ suspend_displays_in_progress_(false),
+ should_undo_suspend_displays_(false),
+ weak_ptr_factory_(this) {
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(
this);
chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(
@@ -117,15 +117,34 @@ void PowerEventObserver::SuspendImminent() {
StopRenderingRequests();
}
+ // Ignore mouse events that might be generated by suspending the displays.
ui::UserActivityDetector::Get()->OnDisplayPowerChanging();
- Shell::GetInstance()->display_configurator()->SuspendDisplays(base::Bind(
- &OnSuspendDisplaysCompleted, chromeos::DBusThreadManager::Get()
- ->GetPowerManagerClient()
- ->GetSuspendReadinessCallback()));
+
+ should_undo_suspend_displays_ = false;
+ undo_suspend_displays_callback_.Cancel();
+ if (!suspend_displays_in_progress_) {
+ suspend_displays_in_progress_ = true;
+ Shell::GetInstance()->display_configurator()->SuspendDisplays(base::Bind(
+ &PowerEventObserver::OnSuspendDisplaysCompleted,
+ weak_ptr_factory_.GetWeakPtr(), chromeos::DBusThreadManager::Get()
+ ->GetPowerManagerClient()
+ ->GetSuspendReadinessCallback()));
+ }
}
-void PowerEventObserver::SuspendDone(const base::TimeDelta& sleep_duration) {
+void PowerEventObserver::ResumeDisplays() {
+ // If there's an async display-suspending task running, wait until it finishes
+ // to resume the displays.
+ if (suspend_displays_in_progress_) {
+ should_undo_suspend_displays_ = true;
+ return;
+ }
+
Shell::GetInstance()->display_configurator()->ResumeDisplays();
+}
+
+void PowerEventObserver::SuspendDone(const base::TimeDelta& sleep_duration) {
+ ResumeDisplays();
WmShell::Get()->system_tray_notifier()->NotifyRefreshClock();
// If the suspend request was being blocked while waiting for the lock
@@ -154,4 +173,24 @@ void PowerEventObserver::ScreenIsUnlocked() {
screen_locked_ = false;
}
+void PowerEventObserver::OnSuspendDisplaysCompleted(
+ const base::Closure& suspend_callback,
+ bool status) {
+ suspend_displays_in_progress_ = false;
+
+ // If the suspend attempt completed while we were in the process of suspending
+ // displays, we need to resume them now. This needs to happen asynchronously,
+ // as ui::DisplayConfigurator doesn't support having new configure requests
+ // submitted while it's running callbacks from an earlier configure request.
+ if (should_undo_suspend_displays_) {
+ should_undo_suspend_displays_ = false;
+ undo_suspend_displays_callback_.Reset(base::Bind(
+ &PowerEventObserver::ResumeDisplays, weak_ptr_factory_.GetWeakPtr()));
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, undo_suspend_displays_callback_.callback());
+ }
+
+ suspend_callback.Run();
+}
+
} // namespace ash
« no previous file with comments | « ash/system/chromeos/power/power_event_observer.h ('k') | ash/system/chromeos/power/power_event_observer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698