OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef ASH_WM_LOCK_STATE_CONTROLLER_IMPL2_H_ | |
6 #define ASH_WM_LOCK_STATE_CONTROLLER_IMPL2_H_ | |
7 | |
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" | |
17 | |
18 namespace gfx { | |
19 class Rect; | |
20 class Size; | |
21 } | |
22 | |
23 namespace ui { | |
24 class Layer; | |
25 } | |
26 | |
27 namespace ash { | |
28 | |
29 namespace test { | |
30 class LockStateControllerImpl2Test; | |
31 } | |
32 | |
33 // Displays onscreen animations and locks or suspends the system in response to | |
34 // the power button being pressed or released. | |
35 // Lock workflow: | |
36 // Entry points: | |
37 // * StartLockAnimation (bool shutdown after lock) - starts lock that can be | |
38 // cancelled. | |
39 // * StartLockAnimationAndLockImmediately - starts uninterruptible lock | |
40 // animation. | |
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 | |
48 // shutdown is made. | |
49 // | |
50 // Unlock workflow: | |
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. | |
56 | |
57 class ASH_EXPORT LockStateControllerImpl2 : public LockStateController { | |
58 public: | |
59 | |
60 // Helper class used by tests to access internal state. | |
61 class ASH_EXPORT TestApi { | |
62 public: | |
63 explicit TestApi(LockStateControllerImpl2* controller); | |
64 | |
65 virtual ~TestApi(); | |
66 | |
67 bool lock_fail_timer_is_running() const { | |
68 return controller_->lock_fail_timer_.IsRunning(); | |
69 } | |
70 bool lock_to_shutdown_timer_is_running() const { | |
71 return controller_->lock_to_shutdown_timer_.IsRunning(); | |
72 } | |
73 bool shutdown_timer_is_running() const { | |
74 return controller_->pre_shutdown_timer_.IsRunning(); | |
75 } | |
76 bool real_shutdown_timer_is_running() const { | |
77 return controller_->real_shutdown_timer_.IsRunning(); | |
78 } | |
79 bool is_animating_lock() const { | |
80 return controller_->animating_lock_; | |
81 } | |
82 bool is_lock_cancellable() const { | |
83 return controller_->CanCancelLockAnimation(); | |
84 } | |
85 | |
86 void trigger_lock_fail_timeout() { | |
87 controller_->OnLockFailTimeout(); | |
88 controller_->lock_fail_timer_.Stop(); | |
89 } | |
90 void trigger_lock_to_shutdown_timeout() { | |
91 controller_->OnLockToShutdownTimeout(); | |
92 controller_->lock_to_shutdown_timer_.Stop(); | |
93 } | |
94 void trigger_shutdown_timeout() { | |
95 controller_->OnPreShutdownAnimationTimeout(); | |
96 controller_->pre_shutdown_timer_.Stop(); | |
97 } | |
98 void trigger_real_shutdown_timeout() { | |
99 controller_->OnRealShutdownTimeout(); | |
100 controller_->real_shutdown_timer_.Stop(); | |
101 } | |
102 private: | |
103 LockStateControllerImpl2* controller_; // not owned | |
104 | |
105 DISALLOW_COPY_AND_ASSIGN(TestApi); | |
106 }; | |
107 | |
108 LockStateControllerImpl2(); | |
109 virtual ~LockStateControllerImpl2(); | |
110 | |
111 // RootWindowObserver override: | |
112 virtual void OnRootWindowHostCloseRequested( | |
113 const aura::RootWindow* root) OVERRIDE; | |
114 | |
115 // ShellObserver overrides: | |
116 virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE; | |
117 virtual void OnAppTerminating() OVERRIDE; | |
118 virtual void OnLockStateChanged(bool locked) OVERRIDE; | |
119 | |
120 // LockStateController overrides: | |
121 virtual void StartLockAnimation(bool shutdown_after_lock) OVERRIDE; | |
122 | |
123 virtual void StartShutdownAnimation() OVERRIDE; | |
124 virtual void StartLockAnimationAndLockImmediately() OVERRIDE; | |
125 | |
126 virtual bool LockRequested() OVERRIDE; | |
127 virtual bool ShutdownRequested() OVERRIDE; | |
128 | |
129 virtual bool CanCancelLockAnimation() OVERRIDE; | |
130 virtual void CancelLockAnimation() OVERRIDE; | |
131 | |
132 virtual bool CanCancelShutdownAnimation() OVERRIDE; | |
133 virtual void CancelShutdownAnimation() OVERRIDE; | |
134 | |
135 virtual void OnStartingLock() OVERRIDE; | |
136 virtual void RequestShutdown() OVERRIDE; | |
137 | |
138 virtual void OnLockScreenHide(base::Closure& callback) OVERRIDE; | |
139 virtual void SetLockScreenDisplayedCallback(base::Closure& callback) OVERRIDE; | |
140 | |
141 protected: | |
142 friend class test::LockStateControllerImpl2Test; | |
143 | |
144 private: | |
145 struct UnlockedStateProperties { | |
146 bool background_is_hidden; | |
147 }; | |
148 | |
149 void RequestShutdownImpl(); | |
150 | |
151 // Reverts the pre-lock animation, reports the error. | |
152 void OnLockFailTimeout(); | |
153 | |
154 // Starts timer for gap between lock and shutdown. | |
155 void StartLockToShutdownTimer(); | |
156 | |
157 // Calls StartShutdownAnimation(). | |
158 void OnLockToShutdownTimeout(); | |
159 | |
160 // Starts timer for undoable shutdown animation. | |
161 void StartPreShutdownAnimationTimer(); | |
162 | |
163 // Calls RequestShutdownImpl(); | |
164 void OnPreShutdownAnimationTimeout(); | |
165 | |
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); | |
170 | |
171 // Requests that the machine be shut down. | |
172 void OnRealShutdownTimeout(); | |
173 | |
174 // Starts shutdown animation that can be cancelled and starts pre-shutdown | |
175 // timer. | |
176 void StartCancellableShutdownAnimation(); | |
177 | |
178 // Starts non-cancellable animation and starts real shutdown timer that | |
179 // includes animation time. | |
180 void StartShutdownAnimationImpl(); | |
181 | |
182 // Triggers late animations on the lock screen. | |
183 void OnLockScreenAnimationFinished(); | |
184 | |
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(); | |
196 | |
197 // These methods are called when corresponding animation completes. | |
198 void LockAnimationCancelled(); | |
199 void PreLockAnimationFinished(bool request_lock); | |
200 void PostLockAnimationFinished(); | |
201 void UnlockAnimationAfterUIDestroyedFinished(); | |
202 | |
203 // Stores properties of UI that have to be temporarily modified while locking. | |
204 void StoreUnlockedProperties(); | |
205 void RestoreUnlockedProperties(); | |
206 | |
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); | |
211 | |
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); | |
216 | |
217 // The current login status, or original login status from before we locked. | |
218 user::LoginStatus login_status_; | |
219 | |
220 // Current lock status. | |
221 bool system_is_locked_; | |
222 | |
223 // Are we in the process of shutting the machine down? | |
224 bool shutting_down_; | |
225 | |
226 // Indicates whether controller should proceed to (cancellable) shutdown after | |
227 // locking. | |
228 bool shutdown_after_lock_; | |
229 | |
230 // Indicates that controller displays lock animation. | |
231 bool animating_lock_; | |
232 | |
233 // Indicates that lock animation can be undone. | |
234 bool can_cancel_lock_animation_; | |
235 | |
236 scoped_ptr<UnlockedStateProperties> unlocked_properties_; | |
237 | |
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_; | |
241 | |
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_; | |
246 | |
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_; | |
250 | |
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_; | |
255 | |
256 base::Closure lock_screen_displayed_callback_; | |
257 | |
258 DISALLOW_COPY_AND_ASSIGN(LockStateControllerImpl2); | |
259 }; | |
260 | |
261 } // namespace ash | |
262 | |
263 #endif // ASH_WM_LOCK_STATE_CONTROLLER_IMPL2_H_ | |
OLD | NEW |