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
3 // found in the LICENSE file.
5 #ifndef ASH_WM_LOCK_STATE_CONTROLLER_IMPL2_H_
6 #define ASH_WM_LOCK_STATE_CONTROLLER_IMPL2_H_
8 #include "ash/ash_export.h"
9 #include "ash/shell_observer.h"
10 #include "ash/wm/lock_state_controller.h"
11 #include "ash/wm/session_state_animator.h"
12 #include "base/basictypes.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/time/time.h"
15 #include "base/timer/timer.h"
16 #include "ui/aura/root_window_observer.h"
30 class LockStateControllerImpl2Test
;
33 // Displays onscreen animations and locks or suspends the system in response to
34 // the power button being pressed or released.
37 // * StartLockAnimation (bool shutdown after lock) - starts lock that can be
39 // * StartLockAnimationAndLockImmediately - starts uninterruptible lock
41 // This leads to call of either StartImmediatePreLockAnimation or
42 // StartCancellablePreLockAnimation. Once they complete
43 // PreLockAnimationFinished is called, and system lock is requested.
44 // Once system locks and lock UI is created, OnLockStateChanged is called, and
45 // StartPostLockAnimation is called. In PostLockAnimationFinished two
46 // things happen : EVENT_LOCK_ANIMATION_FINISHED notification is sent (it
47 // triggers third part of animation within lock UI), and check for continuing to
51 // WebUI does first part of animation, and calls OnLockScreenHide(callback) that
52 // triggers StartUnlockAnimationBeforeUIDestroyed(callback). Once callback is
53 // called at the end of the animation, lock UI is deleted, system unlocks, and
54 // OnLockStateChanged is called. It leads to
55 // StartUnlockAnimationAfterUIDestroyed.
57 class ASH_EXPORT LockStateControllerImpl2
: public LockStateController
{
60 // Helper class used by tests to access internal state.
61 class ASH_EXPORT TestApi
{
63 explicit TestApi(LockStateControllerImpl2
* controller
);
67 bool lock_fail_timer_is_running() const {
68 return controller_
->lock_fail_timer_
.IsRunning();
70 bool lock_to_shutdown_timer_is_running() const {
71 return controller_
->lock_to_shutdown_timer_
.IsRunning();
73 bool shutdown_timer_is_running() const {
74 return controller_
->pre_shutdown_timer_
.IsRunning();
76 bool real_shutdown_timer_is_running() const {
77 return controller_
->real_shutdown_timer_
.IsRunning();
79 bool is_animating_lock() const {
80 return controller_
->animating_lock_
;
82 bool is_lock_cancellable() const {
83 return controller_
->CanCancelLockAnimation();
86 void trigger_lock_fail_timeout() {
87 controller_
->OnLockFailTimeout();
88 controller_
->lock_fail_timer_
.Stop();
90 void trigger_lock_to_shutdown_timeout() {
91 controller_
->OnLockToShutdownTimeout();
92 controller_
->lock_to_shutdown_timer_
.Stop();
94 void trigger_shutdown_timeout() {
95 controller_
->OnPreShutdownAnimationTimeout();
96 controller_
->pre_shutdown_timer_
.Stop();
98 void trigger_real_shutdown_timeout() {
99 controller_
->OnRealShutdownTimeout();
100 controller_
->real_shutdown_timer_
.Stop();
103 LockStateControllerImpl2
* controller_
; // not owned
105 DISALLOW_COPY_AND_ASSIGN(TestApi
);
108 LockStateControllerImpl2();
109 virtual ~LockStateControllerImpl2();
111 // RootWindowObserver override:
112 virtual void OnRootWindowHostCloseRequested(
113 const aura::RootWindow
* root
) OVERRIDE
;
115 // ShellObserver overrides:
116 virtual void OnLoginStateChanged(user::LoginStatus status
) OVERRIDE
;
117 virtual void OnAppTerminating() OVERRIDE
;
118 virtual void OnLockStateChanged(bool locked
) OVERRIDE
;
120 // LockStateController overrides:
121 virtual void StartLockAnimation(bool shutdown_after_lock
) OVERRIDE
;
123 virtual void StartShutdownAnimation() OVERRIDE
;
124 virtual void StartLockAnimationAndLockImmediately() OVERRIDE
;
126 virtual bool LockRequested() OVERRIDE
;
127 virtual bool ShutdownRequested() OVERRIDE
;
129 virtual bool CanCancelLockAnimation() OVERRIDE
;
130 virtual void CancelLockAnimation() OVERRIDE
;
132 virtual bool CanCancelShutdownAnimation() OVERRIDE
;
133 virtual void CancelShutdownAnimation() OVERRIDE
;
135 virtual void OnStartingLock() OVERRIDE
;
136 virtual void RequestShutdown() OVERRIDE
;
138 virtual void OnLockScreenHide(base::Closure
& callback
) OVERRIDE
;
139 virtual void SetLockScreenDisplayedCallback(base::Closure
& callback
) OVERRIDE
;
142 friend class test::LockStateControllerImpl2Test
;
145 struct UnlockedStateProperties
{
146 bool background_is_hidden
;
149 void RequestShutdownImpl();
151 // Reverts the pre-lock animation, reports the error.
152 void OnLockFailTimeout();
154 // Starts timer for gap between lock and shutdown.
155 void StartLockToShutdownTimer();
157 // Calls StartShutdownAnimation().
158 void OnLockToShutdownTimeout();
160 // Starts timer for undoable shutdown animation.
161 void StartPreShutdownAnimationTimer();
163 // Calls RequestShutdownImpl();
164 void OnPreShutdownAnimationTimeout();
166 // Starts timer for final shutdown animation.
167 // If |with_animation_time| is true, it will also include time of "fade to
168 // white" shutdown animation.
169 void StartRealShutdownTimer(bool with_animation_time
);
171 // Requests that the machine be shut down.
172 void OnRealShutdownTimeout();
174 // Starts shutdown animation that can be cancelled and starts pre-shutdown
176 void StartCancellableShutdownAnimation();
178 // Starts non-cancellable animation and starts real shutdown timer that
179 // includes animation time.
180 void StartShutdownAnimationImpl();
182 // Triggers late animations on the lock screen.
183 void OnLockScreenAnimationFinished();
185 // If |request_lock_on_completion| is true, a lock request will be sent
186 // after the pre-lock animation completes. (The pre-lock animation is
187 // also displayed in response to already-in-progress lock requests; in
188 // these cases an additional lock request is undesirable.)
189 void StartImmediatePreLockAnimation(bool request_lock_on_completion
);
190 void StartCancellablePreLockAnimation();
191 void CancelPreLockAnimation();
192 void StartPostLockAnimation();
193 // This method calls |callback| when animation completes.
194 void StartUnlockAnimationBeforeUIDestroyed(base::Closure
&callback
);
195 void StartUnlockAnimationAfterUIDestroyed();
197 // These methods are called when corresponding animation completes.
198 void LockAnimationCancelled();
199 void PreLockAnimationFinished(bool request_lock
);
200 void PostLockAnimationFinished();
201 void UnlockAnimationAfterUIDestroyedFinished();
203 // Stores properties of UI that have to be temporarily modified while locking.
204 void StoreUnlockedProperties();
205 void RestoreUnlockedProperties();
207 // Fades in background layer with |speed| if it was hidden in unlocked state.
208 void AnimateBackgroundAppearanceIfNecessary(
209 ash::internal::SessionStateAnimator::AnimationSpeed speed
,
210 ui::LayerAnimationObserver
* observer
);
212 // Fades out background layer with |speed| if it was hidden in unlocked state.
213 void AnimateBackgroundHidingIfNecessary(
214 ash::internal::SessionStateAnimator::AnimationSpeed speed
,
215 ui::LayerAnimationObserver
* observer
);
217 // The current login status, or original login status from before we locked.
218 user::LoginStatus login_status_
;
220 // Current lock status.
221 bool system_is_locked_
;
223 // Are we in the process of shutting the machine down?
226 // Indicates whether controller should proceed to (cancellable) shutdown after
228 bool shutdown_after_lock_
;
230 // Indicates that controller displays lock animation.
231 bool animating_lock_
;
233 // Indicates that lock animation can be undone.
234 bool can_cancel_lock_animation_
;
236 scoped_ptr
<UnlockedStateProperties
> unlocked_properties_
;
238 // Started when we request that the screen be locked. When it fires, we
239 // assume that our request got dropped.
240 base::OneShotTimer
<LockStateControllerImpl2
> lock_fail_timer_
;
242 // Started when the screen is locked while the power button is held. Adds a
243 // delay between the appearance of the lock screen and the beginning of the
244 // pre-shutdown animation.
245 base::OneShotTimer
<LockStateControllerImpl2
> lock_to_shutdown_timer_
;
247 // Started when we begin displaying the pre-shutdown animation. When it
248 // fires, we start the shutdown animation and get ready to request shutdown.
249 base::OneShotTimer
<LockStateControllerImpl2
> pre_shutdown_timer_
;
251 // Started when we display the shutdown animation. When it fires, we actually
252 // request shutdown. Gives the animation time to complete before Chrome, X,
253 // etc. are shut down.
254 base::OneShotTimer
<LockStateControllerImpl2
> real_shutdown_timer_
;
256 base::Closure lock_screen_displayed_callback_
;
258 DISALLOW_COPY_AND_ASSIGN(LockStateControllerImpl2
);
263 #endif // ASH_WM_LOCK_STATE_CONTROLLER_IMPL2_H_