OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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_SESSION_STATE_CONTROLLER_H_ | |
6 #define ASH_WM_SESSION_STATE_CONTROLLER_H_ | |
7 | |
8 #include "ash/ash_export.h" | |
9 #include "ash/shell_observer.h" | |
10 #include "ash/wm/session_state_animator.h" | |
11 #include "base/basictypes.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/time.h" | |
14 #include "base/timer.h" | |
15 #include "ui/aura/root_window_observer.h" | |
16 | |
17 namespace gfx { | |
18 class Rect; | |
19 class Size; | |
20 } | |
21 | |
22 namespace ui { | |
23 class Layer; | |
24 } | |
25 | |
26 namespace ash { | |
27 | |
28 namespace test { | |
29 class PowerButtonControllerTest; | |
30 } | |
31 | |
32 namespace internal { | |
33 // Amount of time that the power button needs to be held before we lock the | |
34 // screen. | |
35 const int kLockTimeoutMs = 400; | |
36 | |
37 // Amount of time that the power button needs to be held before we shut down. | |
38 const int kShutdownTimeoutMs = 400; | |
39 | |
40 // Amount of time to wait for our lock requests to be honored before giving up. | |
41 const int kLockFailTimeoutMs = 4000; | |
42 | |
43 // When the button has been held continuously from the unlocked state, amount of | |
44 // time that we wait after the screen locker window is shown before starting the | |
45 // pre-shutdown animation. | |
46 const int kLockToShutdownTimeoutMs = 150; | |
47 | |
48 // Amount of time taken to scale the snapshot of the screen down to a | |
49 // slightly-smaller size once the user starts holding the power button. Used | |
50 // for both the pre-lock and pre-shutdown animations. | |
51 const int kSlowCloseAnimMs = 400; | |
52 | |
53 // Amount of time taken to scale the snapshot of the screen back to its original | |
54 // size when the button is released. | |
55 const int kUndoSlowCloseAnimMs = 100; | |
56 | |
57 // Amount of time taken to scale the snapshot down to a point in the center of | |
58 // the screen once the screen has been locked or we've been notified that the | |
59 // system is shutting down. | |
60 const int kFastCloseAnimMs = 150; | |
61 | |
62 // Additional time (beyond kFastCloseAnimMs) to wait after starting the | |
63 // fast-close shutdown animation before actually requesting shutdown, to give | |
64 // the animation time to finish. | |
65 const int kShutdownRequestDelayMs = 50; | |
66 } | |
67 | |
68 // Performs system-related functions on behalf of SessionStateController. | |
69 class ASH_EXPORT SessionStateControllerDelegate { | |
70 public: | |
71 SessionStateControllerDelegate() {} | |
72 virtual ~SessionStateControllerDelegate() {} | |
73 | |
74 virtual void RequestLockScreen() = 0; | |
75 virtual void RequestShutdown() = 0; | |
76 | |
77 private: | |
78 DISALLOW_COPY_AND_ASSIGN(SessionStateControllerDelegate); | |
79 }; | |
80 | |
81 // Displays onscreen animations and locks or suspends the system in response to | |
82 // the power button being pressed or released. | |
83 class ASH_EXPORT SessionStateController : public aura::RootWindowObserver, | |
84 public ShellObserver { | |
85 public: | |
86 | |
87 // Helper class used by tests to access internal state. | |
88 class ASH_EXPORT TestApi { | |
89 public: | |
90 explicit TestApi(SessionStateController* controller); | |
91 | |
92 virtual ~TestApi(); | |
93 | |
94 bool lock_timer_is_running() const { | |
95 return controller_->lock_timer_.IsRunning(); | |
96 } | |
97 bool lock_fail_timer_is_running() const { | |
98 return controller_->lock_fail_timer_.IsRunning(); | |
99 } | |
100 bool lock_to_shutdown_timer_is_running() const { | |
101 return controller_->lock_to_shutdown_timer_.IsRunning(); | |
102 } | |
103 bool shutdown_timer_is_running() const { | |
104 return controller_->pre_shutdown_timer_.IsRunning(); | |
105 } | |
106 bool real_shutdown_timer_is_running() const { | |
107 return controller_->real_shutdown_timer_.IsRunning(); | |
108 } | |
109 | |
110 void trigger_lock_timeout() { | |
111 controller_->OnLockTimeout(); | |
112 controller_->lock_timer_.Stop(); | |
113 } | |
114 void trigger_lock_fail_timeout() { | |
115 controller_->OnLockFailTimeout(); | |
116 controller_->lock_fail_timer_.Stop(); | |
117 } | |
118 void trigger_lock_to_shutdown_timeout() { | |
119 controller_->OnLockToShutdownTimeout(); | |
120 controller_->lock_to_shutdown_timer_.Stop(); | |
121 } | |
122 void trigger_shutdown_timeout() { | |
123 controller_->OnPreShutdownAnimationTimeout(); | |
124 controller_->pre_shutdown_timer_.Stop(); | |
125 } | |
126 void trigger_real_shutdown_timeout() { | |
127 controller_->OnRealShutdownTimeout(); | |
128 controller_->real_shutdown_timer_.Stop(); | |
129 } | |
130 private: | |
131 SessionStateController* controller_; // not owned | |
132 | |
133 DISALLOW_COPY_AND_ASSIGN(TestApi); | |
134 }; | |
135 | |
136 SessionStateController(); | |
137 virtual ~SessionStateController(); | |
138 | |
139 void set_delegate(SessionStateControllerDelegate* delegate) { | |
140 delegate_.reset(delegate); | |
141 } | |
142 | |
143 // Returns true iff when we're in state when user session can be locked. | |
144 virtual bool IsEligibleForLock(); | |
145 | |
146 // Returns true if system is locked. | |
147 virtual bool IsLocked(); | |
148 | |
149 // Starts locking (with slow animation) that can be cancelled. | |
150 // After locking and |kLockToShutdownTimeoutMs| StartCancellableShutdown() | |
Daniel Erat
2012/10/11 16:26:56
s/StartCancellableShutdown/StartShutdownAnimation/
Denis Kuznetsov (DE-MUC)
2012/10/15 11:49:58
Done.
| |
151 // will be called unless CancelShutdown() is called. | |
152 virtual void StartLockAnimation(); | |
153 | |
154 // Starts shutting down (with slow animation) that can be cancelled. | |
155 virtual void StartShutdownAnimation(); | |
156 | |
157 // Starts shutdown that can not be undone. | |
158 virtual void ShutdownImmediately(); | |
159 | |
160 // Starts usual lock animation, but lock immediately. | |
161 virtual void StartLockAnimationAndLockImmediately(); | |
162 | |
163 // Returns true if we have requested system to lock, but haven't recieved | |
164 // confirmation yet. | |
165 virtual bool LockRequested(); | |
166 | |
167 // Returns true if we are shutting down. | |
168 virtual bool IsShuttingDown(); | |
Daniel Erat
2012/10/11 16:26:56
ShutdownRequested()?
Denis Kuznetsov (DE-MUC)
2012/10/15 11:49:58
Done.
| |
169 | |
170 // Returns true if we are within cancellable lock timeframe. | |
171 virtual bool CanCancelLockAnimation(); | |
172 | |
173 // Cancels locking and reverts lock animation. | |
174 virtual void CancelLockAnimation(); | |
175 | |
176 // Cancels locking and reverts lock animation with slightly different | |
177 // parameters. Seems to be some bug, but refactoring should keep all bugs. | |
178 //ToDo(antrim): remove this, animations should actually be the same. | |
Daniel Erat
2012/10/11 16:26:56
nit: should be:
// TODO(antrim): ...
Denis Kuznetsov (DE-MUC)
2012/10/15 11:49:58
Done.
| |
179 virtual void CancelLockWithOtherAnimation(); | |
180 | |
181 // Returns true if we are within cancellable shutdown timeframe. | |
182 virtual bool CanCancelShutdownAnimation(); | |
183 | |
184 // Cancels shutting down and reverts shutdown animation. | |
185 virtual void CancelShutdownAnimation(); | |
186 | |
187 // Called when Chrome gets a request to display the lock screen. | |
188 virtual void OnStartingLock(); | |
189 | |
190 // Displays the shutdown animation and requests shutdown when it's done. | |
191 virtual void RequestShutdown(); | |
Daniel Erat
2012/10/11 16:26:56
do you really need both this and ShutdownImmediate
Denis Kuznetsov (DE-MUC)
2012/10/15 11:49:58
Good catch, I've missed it.
| |
192 | |
193 | |
Daniel Erat
2012/10/11 16:26:56
nit: delete extra blank line
Denis Kuznetsov (DE-MUC)
2012/10/15 11:49:58
Done.
| |
194 // RootWindowObserver override: | |
195 virtual void OnRootWindowHostCloseRequested( | |
196 const aura::RootWindow* root) OVERRIDE; | |
197 | |
198 // ShellObserver overrides: | |
199 virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE; | |
200 virtual void OnAppTerminating() OVERRIDE; | |
201 virtual void OnLockStateChanged(bool locked) OVERRIDE; | |
202 | |
203 protected: | |
204 friend class test::PowerButtonControllerTest; | |
205 | |
206 bool LoggedInAsNonGuest() const; | |
207 | |
208 private: | |
209 void RequestShutdownImpl(); | |
210 | |
211 // Starts lock timer. | |
212 void StartLockTimer(); | |
213 | |
214 // Requests that the screen be locked and starts |lock_fail_timer_|. | |
215 void OnLockTimeout(); | |
216 | |
217 // Reverts the pre-lock animation, reports the error. | |
218 void OnLockFailTimeout(); | |
219 | |
220 // Starts timer for gap between lock and shutdown. | |
221 void StartLockToShutdownTimer(); | |
222 // Calls StartCancellableShutdown(). | |
Daniel Erat
2012/10/11 16:26:56
nit: add blank line before this line
Denis Kuznetsov (DE-MUC)
2012/10/15 11:49:58
Done.
| |
223 void OnLockToShutdownTimeout(); | |
224 | |
225 // Starts timer for undoable shutdown animation. | |
226 void StartPreShutdownAnimationTimer(); | |
227 | |
228 // Calls RequestShutdownImpl(); | |
229 void OnPreShutdownAnimationTimeout(); | |
230 | |
231 // Starts timer for final shutdown animation. | |
232 void StartRealShutdownTimer(); | |
233 | |
234 // Requests that the machine be shut down. | |
235 void OnRealShutdownTimeout(); | |
236 | |
237 // The current login status. | |
238 user::LoginStatus login_status_; | |
239 | |
240 // Original login status during locked. LOGGED_IN_NONE if it's not locked. | |
241 user::LoginStatus unlocked_login_status_; | |
242 | |
243 // Are we in the process of shutting the machine down? | |
244 bool shutting_down_; | |
245 | |
246 // Indicates whether controller should proceed to (cancellable) shutdown after | |
247 // locking. | |
248 bool shutdown_after_lock_; | |
249 | |
250 // Started when the user first presses the power button while in a | |
251 // logged-in-as-a-non-guest-user, unlocked state. When it fires, we lock the | |
252 // screen. | |
253 base::OneShotTimer<SessionStateController> lock_timer_; | |
254 | |
255 // Started when we request that the screen be locked. When it fires, we | |
256 // assume that our request got dropped. | |
257 base::OneShotTimer<SessionStateController> lock_fail_timer_; | |
258 | |
259 // Started when the screen is locked while the power button is held. Adds a | |
260 // delay between the appearance of the lock screen and the beginning of the | |
261 // pre-shutdown animation. | |
262 base::OneShotTimer<SessionStateController> lock_to_shutdown_timer_; | |
263 | |
264 // Started when we begin displaying the pre-shutdown animation. When it | |
265 // fires, we start the shutdown animation and get ready to request shutdown. | |
266 base::OneShotTimer<SessionStateController> pre_shutdown_timer_; | |
267 | |
268 // Started when we display the shutdown animation. When it fires, we actually | |
269 // request shutdown. Gives the animation time to complete before Chrome, X, | |
270 // etc. are shut down. | |
271 base::OneShotTimer<SessionStateController> real_shutdown_timer_; | |
272 | |
273 scoped_ptr<internal::SessionStateAnimator> animator_; | |
274 | |
275 scoped_ptr<SessionStateControllerDelegate> delegate_; | |
276 | |
277 DISALLOW_COPY_AND_ASSIGN(SessionStateController); | |
278 }; | |
279 | |
280 } // namespace ash | |
281 | |
282 #endif // ASH_WM_SESSION_STATE_CONTROLLER_H_ | |
OLD | NEW |