Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: ash/wm/session_state_controller.cc

Issue 11091023: ash : Decouple power button controller and session state controller. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Post-Review fixes #3 Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #include "ash/wm/session_state_controller.h"
6
7 #include "ash/ash_switches.h"
8 #include "ash/shell.h"
9 #include "ash/shell_delegate.h"
10 #include "ash/shell_window_ids.h"
11 #include "ash/wm/session_state_animator.h"
12 #include "base/command_line.h"
13 #include "ui/aura/root_window.h"
14 #include "ui/aura/shared/compound_event_filter.h"
15
16 #if defined(OS_CHROMEOS)
17 #include "base/chromeos/chromeos_version.h"
18 #endif
19
Nikita (slow) 2012/10/16 12:43:45 nit: drop empty line.
Denis Kuznetsov (DE-MUC) 2012/10/16 14:24:53 Done.
20
21 namespace ash {
22
23 const int SessionStateController::kLockTimeoutMs = 400;
24 const int SessionStateController::kShutdownTimeoutMs = 400;
25 const int SessionStateController::kLockFailTimeoutMs = 4000;
26 const int SessionStateController::kLockToShutdownTimeoutMs = 150;
27 const int SessionStateController::kSlowCloseAnimMs = 400;
28 const int SessionStateController::kUndoSlowCloseAnimMs = 100;
29 const int SessionStateController::kFastCloseAnimMs = 150;
30 const int SessionStateController::kShutdownRequestDelayMs = 50;
31
Nikita (slow) 2012/10/16 12:43:45 Please add these: ///////////////////////////////
Daniel Erat 2012/10/16 14:04:16 I'm actually curious: what's the point of putting
32 SessionStateController::TestApi::TestApi(SessionStateController* controller)
33 : controller_(controller) {
34 }
35
36 SessionStateController::TestApi::~TestApi() {
37 }
38
39 SessionStateController::SessionStateController()
40 : login_status_(user::LOGGED_IN_NONE),
41 unlocked_login_status_(user::LOGGED_IN_NONE),
42 shutting_down_(false),
43 shutdown_after_lock_(false),
44 animator_(new internal::SessionStateAnimator()) {
45 Shell::GetPrimaryRootWindow()->AddRootWindowObserver(this);
46 }
47
48 SessionStateController::~SessionStateController() {
49 Shell::GetPrimaryRootWindow()->RemoveRootWindowObserver(this);
50 }
51
52 void SessionStateController::OnLoginStateChanged(user::LoginStatus status) {
53 login_status_ = status;
54 unlocked_login_status_ = user::LOGGED_IN_NONE;
55 }
56
57 void SessionStateController::OnAppTerminating() {
58 // If we hear that Chrome is exiting but didn't request it ourselves, all we
59 // can really hope for is that we'll have time to clear the screen.
60 if (!shutting_down_) {
61 shutting_down_ = true;
62 Shell* shell = ash::Shell::GetInstance();
63 shell->env_filter()->set_cursor_hidden_by_filter(false);
64 shell->cursor_manager()->ShowCursor(false);
65 animator_->ShowBlackLayer();
66 animator_->StartAnimation(
67 internal::SessionStateAnimator::kAllContainersMask,
68 internal::SessionStateAnimator::ANIMATION_HIDE);
69 }
70 }
71
72 void SessionStateController::OnLockStateChanged(bool locked) {
73 if (shutting_down_ || (login_status_ == user::LOGGED_IN_LOCKED) == locked)
Daniel Erat 2012/10/15 13:24:47 nit: i think you can change "(login_status_ == use
Denis Kuznetsov (DE-MUC) 2012/10/16 14:24:53 Done.
74 return;
75
76 if (!locked && login_status_ == user::LOGGED_IN_LOCKED) {
77 login_status_ = unlocked_login_status_;
78 unlocked_login_status_ = user::LOGGED_IN_NONE;
79 } else {
80 unlocked_login_status_ = login_status_;
81 login_status_ = user::LOGGED_IN_LOCKED;
82 }
83
84 if (locked) {
85 animator_->StartAnimation(
86 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
87 internal::SessionStateAnimator::ANIMATION_FADE_IN);
88 lock_timer_.Stop();
89 lock_fail_timer_.Stop();
90
91 if (shutdown_after_lock_) {
92 shutdown_after_lock_ = false;
93 StartLockToShutdownTimer();
94 }
95 } else {
96 animator_->StartAnimation(
97 internal::SessionStateAnimator::DESKTOP_BACKGROUND |
98 internal::SessionStateAnimator::LAUNCHER |
99 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
100 internal::SessionStateAnimator::ANIMATION_RESTORE);
101 animator_->DropBlackLayer();
102 }
103 }
104
105 void SessionStateController::OnStartingLock() {
106 if (shutting_down_ || login_status_ == user::LOGGED_IN_LOCKED)
107 return;
108
109 // Ensure that the black layer is visible -- if the screen was locked via
110 // the wrench menu, we won't have already shown the black background
111 // as part of the slow-close animation.
112 animator_->ShowBlackLayer();
113
114 animator_->StartAnimation(
115 internal::SessionStateAnimator::LAUNCHER,
116 internal::SessionStateAnimator::ANIMATION_HIDE);
117
118 animator_->StartAnimation(
119 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
120 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE);
121
122 // Hide the screen locker containers so we can make them fade in later.
123 animator_->StartAnimation(
124 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
125 internal::SessionStateAnimator::ANIMATION_HIDE);
126 }
127
128 void SessionStateController::StartLockAnimationAndLockImmediately() {
129 animator_->ShowBlackLayer();
130 animator_->StartAnimation(
131 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
132 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE);
133 OnLockTimeout();
134 }
135
136 void SessionStateController::StartLockAnimation() {
137 shutdown_after_lock_ = true;
138
139 animator_->ShowBlackLayer();
140 animator_->StartAnimation(
141 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
142 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE);
143 StartLockTimer();
144 }
145
146 void SessionStateController::StartShutdownAnimation() {
147 animator_->ShowBlackLayer();
148 animator_->StartAnimation(
149 internal::SessionStateAnimator::kAllContainersMask,
150 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE);
151
152 StartPreShutdownAnimationTimer();
153 }
154
155 bool SessionStateController::IsEligibleForLock() {
156 return LoggedInAsNonGuest() && !IsLocked();
Daniel Erat 2012/10/15 13:24:47 should this also have && !LockRequested()?
Denis Kuznetsov (DE-MUC) 2012/10/16 14:24:53 It seems logical, I will add this, but I thought a
157 }
158
159 bool SessionStateController::IsLocked() {
160 return login_status_ == user::LOGGED_IN_LOCKED;
161 }
162
163 bool SessionStateController::LockRequested() {
164 return lock_fail_timer_.IsRunning();
165 }
166
167 bool SessionStateController::ShutdownRequested() {
168 return shutting_down_;
169 }
170
171 bool SessionStateController::CanCancelLockAnimation() {
172 return lock_timer_.IsRunning();
173 }
174
175 void SessionStateController::CancelLockAnimation() {
176 if (!CanCancelLockAnimation())
177 return;
178 shutdown_after_lock_ = false;
179 animator_->StartAnimation(
180 internal::SessionStateAnimator::kAllContainersMask,
181 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE);
182 animator_->ScheduleDropBlackLayer();
183 lock_timer_.Stop();
184 }
185
186 void SessionStateController::CancelLockWithOtherAnimation() {
187 if (!CanCancelLockAnimation())
188 return;
189 shutdown_after_lock_ = false;
190 animator_->StartAnimation(
191 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
192 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE);
193 animator_->ScheduleDropBlackLayer();
194 lock_timer_.Stop();
195 }
196
197 bool SessionStateController::CanCancelShutdownAnimation() {
198 return pre_shutdown_timer_.IsRunning() ||
199 lock_to_shutdown_timer_.IsRunning();
200 }
201
202 void SessionStateController::CancelShutdownAnimation() {
203 if (!CanCancelShutdownAnimation())
204 return;
205 if (lock_to_shutdown_timer_.IsRunning()) {
206 lock_to_shutdown_timer_.Stop();
207 return;
208 }
209
210 if (login_status_ == user::LOGGED_IN_LOCKED) {
211 // If we've already started shutdown transition at lock screen
212 // desktop background needs to be restored immediately.
213 animator_->StartAnimation(
214 internal::SessionStateAnimator::DESKTOP_BACKGROUND,
215 internal::SessionStateAnimator::ANIMATION_RESTORE);
216 animator_->StartAnimation(
217 internal::SessionStateAnimator::kAllLockScreenContainersMask,
218 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE);
219 animator_->ScheduleDropBlackLayer();
220 } else {
221 animator_->StartAnimation(
222 internal::SessionStateAnimator::kAllContainersMask,
223 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE);
224 animator_->ScheduleDropBlackLayer();
225 }
226 pre_shutdown_timer_.Stop();
227 }
228
229 void SessionStateController::RequestShutdown() {
230 if (!shutting_down_)
231 animator_->ShowBlackLayer();
232 RequestShutdownImpl();
233 }
234
235 void SessionStateController::RequestShutdownImpl() {
236 DCHECK(!shutting_down_);
237 shutting_down_ = true;
238
239 Shell* shell = ash::Shell::GetInstance();
240 shell->env_filter()->set_cursor_hidden_by_filter(false);
241 shell->cursor_manager()->ShowCursor(false);
242
243 animator_->ShowBlackLayer();
244 if (login_status_ != user::LOGGED_IN_NONE) {
245 // Hide the other containers before starting the animation.
246 // ANIMATION_FAST_CLOSE will make the screen locker windows partially
247 // transparent, and we don't want the other windows to show through.
248 animator_->StartAnimation(
249 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS |
250 internal::SessionStateAnimator::LAUNCHER,
251 internal::SessionStateAnimator::ANIMATION_HIDE);
252 animator_->StartAnimation(
253 internal::SessionStateAnimator::kAllLockScreenContainersMask,
254 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE);
255 } else {
256 animator_->StartAnimation(
257 internal::SessionStateAnimator::kAllContainersMask,
258 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE);
259 }
260 StartRealShutdownTimer();
261 }
262
263 void SessionStateController::OnRootWindowHostCloseRequested(
264 const aura::RootWindow*) {
265 if(Shell::GetInstance() && Shell::GetInstance()->delegate())
266 Shell::GetInstance()->delegate()->Exit();
267 }
268
269 bool SessionStateController::LoggedInAsNonGuest() const {
270 if (login_status_ == user::LOGGED_IN_NONE)
Nikita (slow) 2012/10/16 12:43:45 Could just use return (login_status_ != user::LOG
Denis Kuznetsov (DE-MUC) 2012/10/16 14:24:53 Done.
271 return false;
272 if (login_status_ == user::LOGGED_IN_GUEST)
273 return false;
274 // TODO(mukai): think about kiosk mode.
275 return true;
276 }
277
278 void SessionStateController::StartLockTimer() {
279 lock_timer_.Stop();
280 lock_timer_.Start(FROM_HERE,
281 base::TimeDelta::FromMilliseconds(kSlowCloseAnimMs),
282 this, &SessionStateController::OnLockTimeout);
283 }
284
285 void SessionStateController::OnLockTimeout() {
286 delegate_->RequestLockScreen();
287 lock_fail_timer_.Start(
288 FROM_HERE,
289 base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs),
290 this, &SessionStateController::OnLockFailTimeout);
291 }
292
293 void SessionStateController::OnLockFailTimeout() {
294 DCHECK_NE(login_status_, user::LOGGED_IN_LOCKED);
295 // Undo lock animation.
296 animator_->StartAnimation(
297 internal::SessionStateAnimator::LAUNCHER |
298 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
299 internal::SessionStateAnimator::ANIMATION_RESTORE);
300 animator_->DropBlackLayer();
301 }
302
303 void SessionStateController::StartLockToShutdownTimer() {
304 shutdown_after_lock_ = false;
305 lock_to_shutdown_timer_.Stop();
306 lock_to_shutdown_timer_.Start(
307 FROM_HERE,
308 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs),
309 this, &SessionStateController::OnLockToShutdownTimeout);
310 }
311
312
313 void SessionStateController::OnLockToShutdownTimeout() {
314 DCHECK_EQ(login_status_, user::LOGGED_IN_LOCKED);
315 StartShutdownAnimation();
316 }
317
318 void SessionStateController::StartPreShutdownAnimationTimer() {
319 pre_shutdown_timer_.Stop();
320 pre_shutdown_timer_.Start(
321 FROM_HERE,
322 base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs),
323 this, &SessionStateController::OnPreShutdownAnimationTimeout);
324 }
325
326 void SessionStateController::OnPreShutdownAnimationTimeout() {
327 if (!shutting_down_)
328 RequestShutdownImpl();
329 }
330
331 void SessionStateController::StartRealShutdownTimer() {
332 real_shutdown_timer_.Start(
333 FROM_HERE,
334 base::TimeDelta::FromMilliseconds(kFastCloseAnimMs +
335 kShutdownRequestDelayMs),
336 this, &SessionStateController::OnRealShutdownTimeout);
337 }
338
339 void SessionStateController::OnRealShutdownTimeout() {
340 DCHECK(shutting_down_);
341 #if defined(OS_CHROMEOS)
342 if (!base::chromeos::IsRunningOnChromeOS()) {
343 ShellDelegate* delegate = Shell::GetInstance()->delegate();
344 if (delegate)
345 delegate->Exit();
Daniel Erat 2012/10/15 13:24:47 should there be a return within this "if (delegate
Denis Kuznetsov (DE-MUC) 2012/10/16 14:24:53 Sounds reasonable.
346 }
347 #endif
348 delegate_->RequestShutdown();
349 }
350
351 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698