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/public/interfaces/shutdown.mojom.h" | |
James Cook
2016/11/02 20:20:03
Can this be forward declared?
Elliot Glaysher
2016/11/02 21:45:16
Done.
| |
12 #include "ash/wm/session_state_animator.h" | 13 #include "ash/wm/session_state_animator.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "base/timer/elapsed_timer.h" | 17 #include "base/timer/elapsed_timer.h" |
17 #include "base/timer/timer.h" | 18 #include "base/timer/timer.h" |
18 #include "ui/aura/window_tree_host_observer.h" | 19 #include "ui/aura/window_tree_host_observer.h" |
19 | 20 |
20 namespace gfx { | 21 namespace gfx { |
21 class Rect; | 22 class Rect; |
22 class Size; | 23 class Size; |
23 } | 24 } |
24 | 25 |
26 namespace service_manager { | |
27 class Connector; | |
28 } | |
29 | |
25 namespace ui { | 30 namespace ui { |
26 class Layer; | 31 class Layer; |
27 } | 32 } |
28 | 33 |
29 namespace ash { | 34 namespace ash { |
30 | 35 |
31 namespace test { | 36 namespace test { |
32 class LockStateControllerTest; | 37 class LockStateControllerTest; |
33 class PowerButtonControllerTest; | 38 class PowerButtonControllerTest; |
34 } | 39 } |
35 | 40 |
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 | 41 // Displays onscreen animations and locks or suspends the system in response to |
49 // the power button being pressed or released. | 42 // the power button being pressed or released. |
50 // Lock workflow: | 43 // Lock workflow: |
51 // Entry points: | 44 // Entry points: |
52 // * StartLockAnimation (bool shutdown after lock) - starts lock that can be | 45 // * StartLockAnimation (bool shutdown after lock) - starts lock that can be |
53 // cancelled. | 46 // cancelled. |
54 // * StartLockAnimationAndLockImmediately (bool shutdown after lock) - starts | 47 // * StartLockAnimationAndLockImmediately (bool shutdown after lock) - starts |
55 // uninterruptible lock animation. | 48 // uninterruptible lock animation. |
56 // This leads to call of either StartImmediatePreLockAnimation or | 49 // This leads to call of either StartImmediatePreLockAnimation or |
57 // StartCancellablePreLockAnimation. Once they complete | 50 // StartCancellablePreLockAnimation. Once they complete |
(...skipping 28 matching lines...) Expand all Loading... | |
86 // of time that we wait after the screen locker window is shown before | 79 // of time that we wait after the screen locker window is shown before |
87 // starting the pre-shutdown animation. | 80 // starting the pre-shutdown animation. |
88 static const int kLockToShutdownTimeoutMs; | 81 static const int kLockToShutdownTimeoutMs; |
89 | 82 |
90 // Additional time (beyond kFastCloseAnimMs) to wait after starting the | 83 // Additional time (beyond kFastCloseAnimMs) to wait after starting the |
91 // fast-close shutdown animation before actually requesting shutdown, to give | 84 // fast-close shutdown animation before actually requesting shutdown, to give |
92 // the animation time to finish. | 85 // the animation time to finish. |
93 static const int kShutdownRequestDelayMs; | 86 static const int kShutdownRequestDelayMs; |
94 | 87 |
95 // Helper class used by tests to access internal state. | 88 // Helper class used by tests to access internal state. |
96 class ASH_EXPORT TestApi { | 89 class ASH_EXPORT TestApi { |
James Cook
2016/11/02 20:20:03
What do you think about moving the test API to a s
| |
97 public: | 90 public: |
98 explicit TestApi(LockStateController* controller); | 91 explicit TestApi(LockStateController* controller); |
99 | 92 |
100 virtual ~TestApi(); | 93 virtual ~TestApi(); |
101 | 94 |
95 void SetShutdownClient(std::unique_ptr<mojom::ShutdownClient> client); | |
96 | |
102 bool lock_fail_timer_is_running() const { | 97 bool lock_fail_timer_is_running() const { |
103 return controller_->lock_fail_timer_.IsRunning(); | 98 return controller_->lock_fail_timer_.IsRunning(); |
104 } | 99 } |
105 bool lock_to_shutdown_timer_is_running() const { | 100 bool lock_to_shutdown_timer_is_running() const { |
106 return controller_->lock_to_shutdown_timer_.IsRunning(); | 101 return controller_->lock_to_shutdown_timer_.IsRunning(); |
107 } | 102 } |
108 bool shutdown_timer_is_running() const { | 103 bool shutdown_timer_is_running() const { |
109 return controller_->pre_shutdown_timer_.IsRunning(); | 104 return controller_->pre_shutdown_timer_.IsRunning(); |
110 } | 105 } |
111 bool real_shutdown_timer_is_running() const { | 106 bool real_shutdown_timer_is_running() const { |
(...skipping 20 matching lines...) Expand all Loading... | |
132 controller_->OnRealPowerTimeout(); | 127 controller_->OnRealPowerTimeout(); |
133 controller_->real_shutdown_timer_.Stop(); | 128 controller_->real_shutdown_timer_.Stop(); |
134 } | 129 } |
135 | 130 |
136 private: | 131 private: |
137 LockStateController* controller_; // not owned | 132 LockStateController* controller_; // not owned |
138 | 133 |
139 DISALLOW_COPY_AND_ASSIGN(TestApi); | 134 DISALLOW_COPY_AND_ASSIGN(TestApi); |
140 }; | 135 }; |
141 | 136 |
142 LockStateController(); | 137 LockStateController(service_manager::Connector* connector); |
James Cook
2016/11/02 20:20:03
nit: explicit
Elliot Glaysher
2016/11/02 21:45:16
Done.
| |
143 ~LockStateController() override; | 138 ~LockStateController() override; |
144 | 139 |
145 void SetDelegate(std::unique_ptr<LockStateControllerDelegate> delegate); | |
146 | |
147 // Starts locking (with slow animation) that can be cancelled. | 140 // Starts locking (with slow animation) that can be cancelled. |
148 // After locking and |kLockToShutdownTimeoutMs| StartShutdownAnimation() | 141 // After locking and |kLockToShutdownTimeoutMs| StartShutdownAnimation() |
149 // will be called unless CancelShutdownAnimation() is called, if | 142 // will be called unless CancelShutdownAnimation() is called, if |
150 // |shutdown_after_lock| is true. | 143 // |shutdown_after_lock| is true. |
151 void StartLockAnimation(bool shutdown_after_lock); | 144 void StartLockAnimation(bool shutdown_after_lock); |
152 | 145 |
153 // Starts shutting down (with slow animation) that can be cancelled. | 146 // Starts shutting down (with slow animation) that can be cancelled. |
154 void StartShutdownAnimation(); | 147 void StartShutdownAnimation(); |
155 | 148 |
156 // Starts usual lock animation, but locks immediately. After locking and | 149 // Starts usual lock animation, but locks immediately. After locking and |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 ash::SessionStateAnimator::AnimationSpeed speed, | 260 ash::SessionStateAnimator::AnimationSpeed speed, |
268 SessionStateAnimator::AnimationSequence* animation_sequence); | 261 SessionStateAnimator::AnimationSequence* animation_sequence); |
269 | 262 |
270 // Fades out wallpaper layer with |speed| if it was hidden in unlocked state. | 263 // Fades out wallpaper layer with |speed| if it was hidden in unlocked state. |
271 void AnimateWallpaperHidingIfNecessary( | 264 void AnimateWallpaperHidingIfNecessary( |
272 ash::SessionStateAnimator::AnimationSpeed speed, | 265 ash::SessionStateAnimator::AnimationSpeed speed, |
273 SessionStateAnimator::AnimationSequence* animation_sequence); | 266 SessionStateAnimator::AnimationSequence* animation_sequence); |
274 | 267 |
275 std::unique_ptr<SessionStateAnimator> animator_; | 268 std::unique_ptr<SessionStateAnimator> animator_; |
276 | 269 |
277 std::unique_ptr<LockStateControllerDelegate> delegate_; | |
278 | |
279 // The current login status, or original login status from before we locked. | 270 // The current login status, or original login status from before we locked. |
280 LoginStatus login_status_; | 271 LoginStatus login_status_; |
281 | 272 |
282 // Current lock status. | 273 // Current lock status. |
283 bool system_is_locked_; | 274 bool system_is_locked_; |
284 | 275 |
285 // Are we in the process of shutting the machine down? | 276 // Are we in the process of shutting the machine down? |
286 bool shutting_down_; | 277 bool shutting_down_; |
287 | 278 |
288 // Indicates whether controller should proceed to (cancellable) shutdown after | 279 // Indicates whether controller should proceed to (cancellable) shutdown after |
289 // locking. | 280 // locking. |
290 bool shutdown_after_lock_; | 281 bool shutdown_after_lock_; |
291 | 282 |
292 // Indicates that controller displays lock animation. | 283 // Indicates that controller displays lock animation. |
293 bool animating_lock_; | 284 bool animating_lock_; |
294 | 285 |
295 // Indicates that lock animation can be undone. | 286 // Indicates that lock animation can be undone. |
296 bool can_cancel_lock_animation_; | 287 bool can_cancel_lock_animation_; |
297 | 288 |
298 std::unique_ptr<UnlockedStateProperties> unlocked_properties_; | 289 std::unique_ptr<UnlockedStateProperties> unlocked_properties_; |
299 | 290 |
300 // How long has it been since the request to lock the screen? | 291 // How long has it been since the request to lock the screen? |
301 std::unique_ptr<base::ElapsedTimer> lock_duration_timer_; | 292 std::unique_ptr<base::ElapsedTimer> lock_duration_timer_; |
302 | 293 |
294 // The client that we request to shut down the machine. | |
295 std::unique_ptr<mojom::ShutdownClient> shutdown_client_; | |
296 | |
303 // Started when we request that the screen be locked. When it fires, we | 297 // Started when we request that the screen be locked. When it fires, we |
304 // assume that our request got dropped. | 298 // assume that our request got dropped. |
305 base::OneShotTimer lock_fail_timer_; | 299 base::OneShotTimer lock_fail_timer_; |
306 | 300 |
307 // Started when the screen is locked while the power button is held. Adds a | 301 // 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 | 302 // delay between the appearance of the lock screen and the beginning of the |
309 // pre-shutdown animation. | 303 // pre-shutdown animation. |
310 base::OneShotTimer lock_to_shutdown_timer_; | 304 base::OneShotTimer lock_to_shutdown_timer_; |
311 | 305 |
312 // Started when we begin displaying the pre-shutdown animation. When it | 306 // Started when we begin displaying the pre-shutdown animation. When it |
313 // fires, we start the shutdown animation and get ready to request shutdown. | 307 // fires, we start the shutdown animation and get ready to request shutdown. |
314 base::OneShotTimer pre_shutdown_timer_; | 308 base::OneShotTimer pre_shutdown_timer_; |
315 | 309 |
316 // Started when we display the shutdown animation. When it fires, we actually | 310 // Started when we display the shutdown animation. When it fires, we actually |
317 // request shutdown. Gives the animation time to complete before Chrome, X, | 311 // request shutdown. Gives the animation time to complete before Chrome, X, |
318 // etc. are shut down. | 312 // etc. are shut down. |
319 base::OneShotTimer real_shutdown_timer_; | 313 base::OneShotTimer real_shutdown_timer_; |
320 | 314 |
321 base::Closure lock_screen_displayed_callback_; | 315 base::Closure lock_screen_displayed_callback_; |
322 | 316 |
323 base::WeakPtrFactory<LockStateController> weak_ptr_factory_; | 317 base::WeakPtrFactory<LockStateController> weak_ptr_factory_; |
324 | 318 |
325 DISALLOW_COPY_AND_ASSIGN(LockStateController); | 319 DISALLOW_COPY_AND_ASSIGN(LockStateController); |
326 }; | 320 }; |
327 | 321 |
328 } // namespace ash | 322 } // namespace ash |
329 | 323 |
330 #endif // ASH_WM_LOCK_STATE_CONTROLLER_H_ | 324 #endif // ASH_WM_LOCK_STATE_CONTROLLER_H_ |
OLD | NEW |