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