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 #ifndef ASH_WM_LOCK_STATE_CONTROLLER_H_ | 5 #ifndef ASH_WM_LOCK_STATE_CONTROLLER_H_ |
6 #define ASH_WM_LOCK_STATE_CONTROLLER_H_ | 6 #define ASH_WM_LOCK_STATE_CONTROLLER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "ash/ash_export.h" | 10 #include "ash/ash_export.h" |
11 #include "ash/common/shell_observer.h" | 11 #include "ash/common/shell_observer.h" |
12 #include "ash/wm/session_state_animator.h" | 12 #include "ash/wm/session_state_animator.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "base/timer/elapsed_timer.h" | 16 #include "base/timer/elapsed_timer.h" |
17 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
18 #include "ui/aura/window_tree_host_observer.h" | 18 #include "ui/aura/window_tree_host_observer.h" |
19 | 19 |
20 namespace gfx { | 20 namespace gfx { |
21 class Rect; | 21 class Rect; |
22 class Size; | 22 class Size; |
23 } | 23 } |
24 | 24 |
| 25 namespace service_manager { |
| 26 class Connector; |
| 27 } |
| 28 |
25 namespace ui { | 29 namespace ui { |
26 class Layer; | 30 class Layer; |
27 } | 31 } |
28 | 32 |
29 namespace ash { | 33 namespace ash { |
30 | 34 |
| 35 namespace mojom { |
| 36 class ShutdownClient; |
| 37 } |
| 38 |
31 namespace test { | 39 namespace test { |
32 class LockStateControllerTest; | 40 class LockStateControllerTest; |
| 41 class LockStateControllerTestApi; |
33 class PowerButtonControllerTest; | 42 class PowerButtonControllerTest; |
34 } | 43 } |
35 | 44 |
36 // Performs system-related functions on behalf of LockStateController. | |
37 class ASH_EXPORT LockStateControllerDelegate { | |
38 public: | |
39 LockStateControllerDelegate() {} | |
40 virtual ~LockStateControllerDelegate() {} | |
41 | |
42 virtual void RequestShutdown() = 0; | |
43 | |
44 private: | |
45 DISALLOW_COPY_AND_ASSIGN(LockStateControllerDelegate); | |
46 }; | |
47 | |
48 // Displays onscreen animations and locks or suspends the system in response to | 45 // Displays onscreen animations and locks or suspends the system in response to |
49 // the power button being pressed or released. | 46 // the power button being pressed or released. |
50 // Lock workflow: | 47 // Lock workflow: |
51 // Entry points: | 48 // Entry points: |
52 // * StartLockAnimation (bool shutdown after lock) - starts lock that can be | 49 // * StartLockAnimation (bool shutdown after lock) - starts lock that can be |
53 // cancelled. | 50 // cancelled. |
54 // * StartLockAnimationAndLockImmediately (bool shutdown after lock) - starts | 51 // * StartLockAnimationAndLockImmediately (bool shutdown after lock) - starts |
55 // uninterruptible lock animation. | 52 // uninterruptible lock animation. |
56 // This leads to call of either StartImmediatePreLockAnimation or | 53 // This leads to call of either StartImmediatePreLockAnimation or |
57 // StartCancellablePreLockAnimation. Once they complete | 54 // StartCancellablePreLockAnimation. Once they complete |
(...skipping 27 matching lines...) Expand all Loading... |
85 // When the button has been held continuously from the unlocked state, amount | 82 // When the button has been held continuously from the unlocked state, amount |
86 // of time that we wait after the screen locker window is shown before | 83 // of time that we wait after the screen locker window is shown before |
87 // starting the pre-shutdown animation. | 84 // starting the pre-shutdown animation. |
88 static const int kLockToShutdownTimeoutMs; | 85 static const int kLockToShutdownTimeoutMs; |
89 | 86 |
90 // Additional time (beyond kFastCloseAnimMs) to wait after starting the | 87 // Additional time (beyond kFastCloseAnimMs) to wait after starting the |
91 // fast-close shutdown animation before actually requesting shutdown, to give | 88 // fast-close shutdown animation before actually requesting shutdown, to give |
92 // the animation time to finish. | 89 // the animation time to finish. |
93 static const int kShutdownRequestDelayMs; | 90 static const int kShutdownRequestDelayMs; |
94 | 91 |
95 // Helper class used by tests to access internal state. | 92 explicit LockStateController(service_manager::Connector* connector); |
96 class ASH_EXPORT TestApi { | |
97 public: | |
98 explicit TestApi(LockStateController* controller); | |
99 | |
100 virtual ~TestApi(); | |
101 | |
102 bool lock_fail_timer_is_running() const { | |
103 return controller_->lock_fail_timer_.IsRunning(); | |
104 } | |
105 bool lock_to_shutdown_timer_is_running() const { | |
106 return controller_->lock_to_shutdown_timer_.IsRunning(); | |
107 } | |
108 bool shutdown_timer_is_running() const { | |
109 return controller_->pre_shutdown_timer_.IsRunning(); | |
110 } | |
111 bool real_shutdown_timer_is_running() const { | |
112 return controller_->real_shutdown_timer_.IsRunning(); | |
113 } | |
114 bool is_animating_lock() const { return controller_->animating_lock_; } | |
115 bool is_lock_cancellable() const { | |
116 return controller_->CanCancelLockAnimation(); | |
117 } | |
118 | |
119 void trigger_lock_fail_timeout() { | |
120 controller_->OnLockFailTimeout(); | |
121 controller_->lock_fail_timer_.Stop(); | |
122 } | |
123 void trigger_lock_to_shutdown_timeout() { | |
124 controller_->OnLockToShutdownTimeout(); | |
125 controller_->lock_to_shutdown_timer_.Stop(); | |
126 } | |
127 void trigger_shutdown_timeout() { | |
128 controller_->OnPreShutdownAnimationTimeout(); | |
129 controller_->pre_shutdown_timer_.Stop(); | |
130 } | |
131 void trigger_real_shutdown_timeout() { | |
132 controller_->OnRealPowerTimeout(); | |
133 controller_->real_shutdown_timer_.Stop(); | |
134 } | |
135 | |
136 private: | |
137 LockStateController* controller_; // not owned | |
138 | |
139 DISALLOW_COPY_AND_ASSIGN(TestApi); | |
140 }; | |
141 | |
142 LockStateController(); | |
143 ~LockStateController() override; | 93 ~LockStateController() override; |
144 | 94 |
145 void SetDelegate(std::unique_ptr<LockStateControllerDelegate> delegate); | |
146 | |
147 // Starts locking (with slow animation) that can be cancelled. | 95 // Starts locking (with slow animation) that can be cancelled. |
148 // After locking and |kLockToShutdownTimeoutMs| StartShutdownAnimation() | 96 // After locking and |kLockToShutdownTimeoutMs| StartShutdownAnimation() |
149 // will be called unless CancelShutdownAnimation() is called, if | 97 // will be called unless CancelShutdownAnimation() is called, if |
150 // |shutdown_after_lock| is true. | 98 // |shutdown_after_lock| is true. |
151 void StartLockAnimation(bool shutdown_after_lock); | 99 void StartLockAnimation(bool shutdown_after_lock); |
152 | 100 |
153 // Starts shutting down (with slow animation) that can be cancelled. | 101 // Starts shutting down (with slow animation) that can be cancelled. |
154 void StartShutdownAnimation(); | 102 void StartShutdownAnimation(); |
155 | 103 |
156 // Starts usual lock animation, but locks immediately. After locking and | 104 // Starts usual lock animation, but locks immediately. After locking and |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 void OnAppTerminating() override; | 149 void OnAppTerminating() override; |
202 void OnLockStateChanged(bool locked) override; | 150 void OnLockStateChanged(bool locked) override; |
203 | 151 |
204 void set_animator_for_test(SessionStateAnimator* animator) { | 152 void set_animator_for_test(SessionStateAnimator* animator) { |
205 animator_.reset(animator); | 153 animator_.reset(animator); |
206 } | 154 } |
207 | 155 |
208 private: | 156 private: |
209 friend class test::PowerButtonControllerTest; | 157 friend class test::PowerButtonControllerTest; |
210 friend class test::LockStateControllerTest; | 158 friend class test::LockStateControllerTest; |
| 159 friend class test::LockStateControllerTestApi; |
211 | 160 |
212 struct UnlockedStateProperties { | 161 struct UnlockedStateProperties { |
213 bool wallpaper_is_hidden; | 162 bool wallpaper_is_hidden; |
214 }; | 163 }; |
215 | 164 |
216 // Reverts the pre-lock animation, reports the error. | 165 // Reverts the pre-lock animation, reports the error. |
217 void OnLockFailTimeout(); | 166 void OnLockFailTimeout(); |
218 | 167 |
219 // Starts timer for gap between lock and shutdown. | 168 // Starts timer for gap between lock and shutdown. |
220 void StartLockToShutdownTimer(); | 169 void StartLockToShutdownTimer(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 ash::SessionStateAnimator::AnimationSpeed speed, | 216 ash::SessionStateAnimator::AnimationSpeed speed, |
268 SessionStateAnimator::AnimationSequence* animation_sequence); | 217 SessionStateAnimator::AnimationSequence* animation_sequence); |
269 | 218 |
270 // Fades out wallpaper layer with |speed| if it was hidden in unlocked state. | 219 // Fades out wallpaper layer with |speed| if it was hidden in unlocked state. |
271 void AnimateWallpaperHidingIfNecessary( | 220 void AnimateWallpaperHidingIfNecessary( |
272 ash::SessionStateAnimator::AnimationSpeed speed, | 221 ash::SessionStateAnimator::AnimationSpeed speed, |
273 SessionStateAnimator::AnimationSequence* animation_sequence); | 222 SessionStateAnimator::AnimationSequence* animation_sequence); |
274 | 223 |
275 std::unique_ptr<SessionStateAnimator> animator_; | 224 std::unique_ptr<SessionStateAnimator> animator_; |
276 | 225 |
277 std::unique_ptr<LockStateControllerDelegate> delegate_; | |
278 | |
279 // The current login status, or original login status from before we locked. | 226 // The current login status, or original login status from before we locked. |
280 LoginStatus login_status_; | 227 LoginStatus login_status_; |
281 | 228 |
282 // Current lock status. | 229 // Current lock status. |
283 bool system_is_locked_; | 230 bool system_is_locked_; |
284 | 231 |
285 // Are we in the process of shutting the machine down? | 232 // Are we in the process of shutting the machine down? |
286 bool shutting_down_; | 233 bool shutting_down_; |
287 | 234 |
288 // Indicates whether controller should proceed to (cancellable) shutdown after | 235 // Indicates whether controller should proceed to (cancellable) shutdown after |
289 // locking. | 236 // locking. |
290 bool shutdown_after_lock_; | 237 bool shutdown_after_lock_; |
291 | 238 |
292 // Indicates that controller displays lock animation. | 239 // Indicates that controller displays lock animation. |
293 bool animating_lock_; | 240 bool animating_lock_; |
294 | 241 |
295 // Indicates that lock animation can be undone. | 242 // Indicates that lock animation can be undone. |
296 bool can_cancel_lock_animation_; | 243 bool can_cancel_lock_animation_; |
297 | 244 |
298 std::unique_ptr<UnlockedStateProperties> unlocked_properties_; | 245 std::unique_ptr<UnlockedStateProperties> unlocked_properties_; |
299 | 246 |
300 // How long has it been since the request to lock the screen? | 247 // How long has it been since the request to lock the screen? |
301 std::unique_ptr<base::ElapsedTimer> lock_duration_timer_; | 248 std::unique_ptr<base::ElapsedTimer> lock_duration_timer_; |
302 | 249 |
| 250 // The client that we request to shut down the machine. |
| 251 std::unique_ptr<mojom::ShutdownClient> shutdown_client_; |
| 252 |
303 // Started when we request that the screen be locked. When it fires, we | 253 // Started when we request that the screen be locked. When it fires, we |
304 // assume that our request got dropped. | 254 // assume that our request got dropped. |
305 base::OneShotTimer lock_fail_timer_; | 255 base::OneShotTimer lock_fail_timer_; |
306 | 256 |
307 // Started when the screen is locked while the power button is held. Adds a | 257 // Started when the screen is locked while the power button is held. Adds a |
308 // delay between the appearance of the lock screen and the beginning of the | 258 // delay between the appearance of the lock screen and the beginning of the |
309 // pre-shutdown animation. | 259 // pre-shutdown animation. |
310 base::OneShotTimer lock_to_shutdown_timer_; | 260 base::OneShotTimer lock_to_shutdown_timer_; |
311 | 261 |
312 // Started when we begin displaying the pre-shutdown animation. When it | 262 // Started when we begin displaying the pre-shutdown animation. When it |
313 // fires, we start the shutdown animation and get ready to request shutdown. | 263 // fires, we start the shutdown animation and get ready to request shutdown. |
314 base::OneShotTimer pre_shutdown_timer_; | 264 base::OneShotTimer pre_shutdown_timer_; |
315 | 265 |
316 // Started when we display the shutdown animation. When it fires, we actually | 266 // Started when we display the shutdown animation. When it fires, we actually |
317 // request shutdown. Gives the animation time to complete before Chrome, X, | 267 // request shutdown. Gives the animation time to complete before Chrome, X, |
318 // etc. are shut down. | 268 // etc. are shut down. |
319 base::OneShotTimer real_shutdown_timer_; | 269 base::OneShotTimer real_shutdown_timer_; |
320 | 270 |
321 base::Closure lock_screen_displayed_callback_; | 271 base::Closure lock_screen_displayed_callback_; |
322 | 272 |
323 base::WeakPtrFactory<LockStateController> weak_ptr_factory_; | 273 base::WeakPtrFactory<LockStateController> weak_ptr_factory_; |
324 | 274 |
325 DISALLOW_COPY_AND_ASSIGN(LockStateController); | 275 DISALLOW_COPY_AND_ASSIGN(LockStateController); |
326 }; | 276 }; |
327 | 277 |
328 } // namespace ash | 278 } // namespace ash |
329 | 279 |
330 #endif // ASH_WM_LOCK_STATE_CONTROLLER_H_ | 280 #endif // ASH_WM_LOCK_STATE_CONTROLLER_H_ |
OLD | NEW |