Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/system/chromeos/power/power_event_observer.h" | 5 #include "ash/system/chromeos/power/power_event_observer.h" |
| 6 | 6 |
| 7 #include "ash/common/session/session_state_delegate.h" | 7 #include "ash/common/session/session_state_delegate.h" |
| 8 #include "ash/common/system/tray/system_tray_notifier.h" | 8 #include "ash/common/system/tray/system_tray_notifier.h" |
| 9 #include "ash/common/wm_shell.h" | 9 #include "ash/common/wm_shell.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 // StopRenderingRequests() is just called directly from this function. If the | 84 // StopRenderingRequests() is just called directly from this function. If the |
| 85 // auto-screen-lock pref _is_ set, then the suspend needs to be delayed | 85 // auto-screen-lock pref _is_ set, then the suspend needs to be delayed |
| 86 // until the lock screen is fully visible. While it is sufficient from a | 86 // until the lock screen is fully visible. While it is sufficient from a |
| 87 // security perspective to block only until the lock screen is ready, which | 87 // security perspective to block only until the lock screen is ready, which |
| 88 // guarantees that the contents of the user's screen are no longer visible, | 88 // guarantees that the contents of the user's screen are no longer visible, |
| 89 // this leads to poor UX on the first resume since neither the user pod nor | 89 // this leads to poor UX on the first resume since neither the user pod nor |
| 90 // the header bar will be visible for a few hundred milliseconds until the GPU | 90 // the header bar will be visible for a few hundred milliseconds until the GPU |
| 91 // process starts rendering again. To deal with this, the suspend is delayed | 91 // process starts rendering again. To deal with this, the suspend is delayed |
| 92 // until all the lock screen animations have completed and the suspend request | 92 // until all the lock screen animations have completed and the suspend request |
| 93 // is unblocked from OnLockAnimationsComplete(). | 93 // is unblocked from OnLockAnimationsComplete(). |
| 94 if (!screen_locked_ && delegate->ShouldLockScreenAutomatically() && | 94 if (!screen_locked_ && delegate->ShouldLockScreenAutomatically() && |
|
James Cook
2017/02/14 21:10:31
Just as an FYI, ShouldLockScreenAutomatically is a
Daniel Erat
2017/02/14 21:17:46
hmm, is that going to be a problem for the 30-minu
| |
| 95 delegate->CanLockScreen()) { | 95 delegate->CanLockScreen()) { |
| 96 screen_lock_callback_ = chromeos::DBusThreadManager::Get() | 96 screen_lock_callback_ = chromeos::DBusThreadManager::Get() |
| 97 ->GetPowerManagerClient() | 97 ->GetPowerManagerClient() |
| 98 ->GetSuspendReadinessCallback(); | 98 ->GetSuspendReadinessCallback(); |
| 99 VLOG(1) << "Requesting screen lock from PowerEventObserver"; | 99 VLOG(1) << "Requesting screen lock from PowerEventObserver"; |
| 100 chromeos::DBusThreadManager::Get() | 100 chromeos::DBusThreadManager::Get() |
| 101 ->GetSessionManagerClient() | 101 ->GetSessionManagerClient() |
| 102 ->RequestLockScreen(); | 102 ->RequestLockScreen(); |
| 103 } else if (waiting_for_lock_screen_animations_) { | 103 } else if (waiting_for_lock_screen_animations_) { |
| 104 // The lock-before-suspending pref has been set and the lock screen is ready | 104 // The lock-before-suspending pref has been set and the lock screen is ready |
| 105 // but the animations have not completed yet. This can happen if a suspend | 105 // but the animations have not completed yet. This can happen if a suspend |
| 106 // request is canceled after the lock screen is ready but before the | 106 // request is canceled after the lock screen is ready but before the |
| 107 // animations have completed and then another suspend request is immediately | 107 // animations have completed and then another suspend request is immediately |
| 108 // started. In practice, it is highly unlikely that this will ever happen | 108 // started. In practice, it is highly unlikely that this will ever happen |
| 109 // but it's better to be safe since the cost of not dealing with it properly | 109 // but it's better to be safe since the cost of not dealing with it properly |
| 110 // is a memory leak in the GPU and weird artifacts on the screen. | 110 // is a memory leak in the GPU and weird artifacts on the screen. |
| 111 screen_lock_callback_ = chromeos::DBusThreadManager::Get() | 111 screen_lock_callback_ = chromeos::DBusThreadManager::Get() |
| 112 ->GetPowerManagerClient() | 112 ->GetPowerManagerClient() |
| 113 ->GetSuspendReadinessCallback(); | 113 ->GetSuspendReadinessCallback(); |
| 114 } else { | 114 } else { |
| 115 // The lock-before-suspending pref is not set or the screen has already been | 115 // The lock-before-suspending pref is not set or the screen has already been |
| 116 // locked and the animations have completed. Rendering can be stopped now. | 116 // locked and the animations have completed. Rendering can be stopped now. |
| 117 StopRenderingRequests(); | 117 StopRenderingRequests(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 ui::UserActivityDetector::Get()->OnDisplayPowerChanging(); | 120 ui::UserActivityDetector::Get()->OnDisplayPowerChanging(); |
| 121 Shell::GetInstance()->display_configurator()->SuspendDisplays(base::Bind( | 121 |
| 122 &OnSuspendDisplaysCompleted, chromeos::DBusThreadManager::Get() | 122 // TODO(derat): After mus exposes a method for suspending displays, call it |
| 123 ->GetPowerManagerClient() | 123 // here: http://crbug.com/692193 |
| 124 ->GetSuspendReadinessCallback())); | 124 if (!WmShell::Get()->IsRunningInMash()) { |
| 125 Shell::GetInstance()->display_configurator()->SuspendDisplays(base::Bind( | |
| 126 &OnSuspendDisplaysCompleted, chromeos::DBusThreadManager::Get() | |
| 127 ->GetPowerManagerClient() | |
| 128 ->GetSuspendReadinessCallback())); | |
| 129 } | |
| 125 } | 130 } |
| 126 | 131 |
| 127 void PowerEventObserver::SuspendDone(const base::TimeDelta& sleep_duration) { | 132 void PowerEventObserver::SuspendDone(const base::TimeDelta& sleep_duration) { |
| 128 Shell::GetInstance()->display_configurator()->ResumeDisplays(); | 133 // TODO(derat): After mus exposes a method for resuming displays, call it |
| 134 // here: http://crbug.com/692193 | |
| 135 if (!WmShell::Get()->IsRunningInMash()) | |
| 136 Shell::GetInstance()->display_configurator()->ResumeDisplays(); | |
| 129 WmShell::Get()->system_tray_notifier()->NotifyRefreshClock(); | 137 WmShell::Get()->system_tray_notifier()->NotifyRefreshClock(); |
| 130 | 138 |
| 131 // If the suspend request was being blocked while waiting for the lock | 139 // If the suspend request was being blocked while waiting for the lock |
| 132 // animation to complete, clear the blocker since the suspend has already | 140 // animation to complete, clear the blocker since the suspend has already |
| 133 // completed. This prevents rendering requests from being blocked after a | 141 // completed. This prevents rendering requests from being blocked after a |
| 134 // resume if the lock screen took too long to show. | 142 // resume if the lock screen took too long to show. |
| 135 screen_lock_callback_.Reset(); | 143 screen_lock_callback_.Reset(); |
| 136 | 144 |
| 137 ResumeRenderingRequests(); | 145 ResumeRenderingRequests(); |
| 138 } | 146 } |
| 139 | 147 |
| 140 void PowerEventObserver::ScreenIsLocked() { | 148 void PowerEventObserver::ScreenIsLocked() { |
| 141 screen_locked_ = true; | 149 screen_locked_ = true; |
| 142 waiting_for_lock_screen_animations_ = true; | 150 waiting_for_lock_screen_animations_ = true; |
| 143 | 151 |
| 144 // The screen is now locked but the pending suspend, if any, will be blocked | 152 // The screen is now locked but the pending suspend, if any, will be blocked |
| 145 // until all the animations have completed. | 153 // until all the animations have completed. |
| 146 if (!screen_lock_callback_.is_null()) { | 154 if (!screen_lock_callback_.is_null()) { |
| 147 VLOG(1) << "Screen locked due to suspend"; | 155 VLOG(1) << "Screen locked due to suspend"; |
| 148 } else { | 156 } else { |
| 149 VLOG(1) << "Screen locked without suspend"; | 157 VLOG(1) << "Screen locked without suspend"; |
| 150 } | 158 } |
| 151 } | 159 } |
| 152 | 160 |
| 153 void PowerEventObserver::ScreenIsUnlocked() { | 161 void PowerEventObserver::ScreenIsUnlocked() { |
| 154 screen_locked_ = false; | 162 screen_locked_ = false; |
| 155 } | 163 } |
| 156 | 164 |
| 157 } // namespace ash | 165 } // namespace ash |
| OLD | NEW |