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 #include "ash/wm/session_state_controller_impl.h" | |
6 | |
7 #include "ash/ash_switches.h" | |
8 #include "ash/cancel_mode.h" | |
9 #include "ash/shell.h" | |
10 #include "ash/shell_delegate.h" | |
11 #include "ash/shell_window_ids.h" | |
12 #include "ash/wm/session_state_animator.h" | |
13 #include "base/command_line.h" | |
14 #include "base/sys_info.h" | |
15 #include "ui/aura/root_window.h" | |
16 #include "ui/views/corewm/compound_event_filter.h" | |
17 | |
18 namespace ash { | |
19 | |
20 SessionStateControllerImpl::TestApi::TestApi( | |
21 SessionStateControllerImpl* controller) | |
22 : controller_(controller) { | |
23 } | |
24 | |
25 SessionStateControllerImpl::TestApi::~TestApi() { | |
26 } | |
27 | |
28 SessionStateControllerImpl::SessionStateControllerImpl() | |
29 : login_status_(user::LOGGED_IN_NONE), | |
30 system_is_locked_(false), | |
31 shutting_down_(false), | |
32 shutdown_after_lock_(false) { | |
33 Shell::GetPrimaryRootWindow()->AddRootWindowObserver(this); | |
34 } | |
35 | |
36 SessionStateControllerImpl::~SessionStateControllerImpl() { | |
37 Shell::GetPrimaryRootWindow()->RemoveRootWindowObserver(this); | |
38 } | |
39 | |
40 void SessionStateControllerImpl::OnLoginStateChanged(user::LoginStatus status) { | |
41 if (status != user::LOGGED_IN_LOCKED) | |
42 login_status_ = status; | |
43 system_is_locked_ = (status == user::LOGGED_IN_LOCKED); | |
44 } | |
45 | |
46 void SessionStateControllerImpl::OnAppTerminating() { | |
47 // If we hear that Chrome is exiting but didn't request it ourselves, all we | |
48 // can really hope for is that we'll have time to clear the screen. | |
49 if (!shutting_down_) { | |
50 shutting_down_ = true; | |
51 Shell* shell = ash::Shell::GetInstance(); | |
52 shell->env_filter()->set_cursor_hidden_by_filter(false); | |
53 shell->cursor_manager()->HideCursor(); | |
54 animator_->StartAnimation( | |
55 internal::SessionStateAnimator::kAllContainersMask, | |
56 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, | |
57 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); | |
58 } | |
59 } | |
60 | |
61 void SessionStateControllerImpl::OnLockStateChanged(bool locked) { | |
62 if (shutting_down_ || (system_is_locked_ == locked)) | |
63 return; | |
64 | |
65 system_is_locked_ = locked; | |
66 | |
67 if (locked) { | |
68 animator_->StartAnimation( | |
69 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | |
70 internal::SessionStateAnimator::ANIMATION_FADE_IN, | |
71 internal::SessionStateAnimator::ANIMATION_SPEED_SHOW_LOCK_SCREEN); | |
72 DispatchCancelMode(); | |
73 FOR_EACH_OBSERVER(LockStateObserver, observers_, | |
74 OnLockStateEvent(LockStateObserver::EVENT_LOCK_ANIMATION_STARTED)); | |
75 lock_timer_.Stop(); | |
76 lock_fail_timer_.Stop(); | |
77 | |
78 if (shutdown_after_lock_) { | |
79 shutdown_after_lock_ = false; | |
80 StartLockToShutdownTimer(); | |
81 } | |
82 } else { | |
83 animator_->StartAnimation( | |
84 internal::SessionStateAnimator::DESKTOP_BACKGROUND | | |
85 internal::SessionStateAnimator::LAUNCHER | | |
86 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | |
87 internal::SessionStateAnimator::ANIMATION_RESTORE, | |
88 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); | |
89 } | |
90 } | |
91 | |
92 void SessionStateControllerImpl::OnStartingLock() { | |
93 if (shutting_down_ || system_is_locked_) | |
94 return; | |
95 | |
96 animator_->StartAnimation( | |
97 internal::SessionStateAnimator::LAUNCHER, | |
98 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, | |
99 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); | |
100 | |
101 animator_->StartAnimation( | |
102 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | |
103 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE, | |
104 internal::SessionStateAnimator::ANIMATION_SPEED_FAST); | |
105 | |
106 DispatchCancelMode(); | |
107 FOR_EACH_OBSERVER(LockStateObserver, observers_, | |
108 OnLockStateEvent(LockStateObserver::EVENT_LOCK_ANIMATION_STARTED)); | |
109 | |
110 // Hide the screen locker containers so we can make them fade in later. | |
111 animator_->StartAnimation( | |
112 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | |
113 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, | |
114 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); | |
115 } | |
116 | |
117 void SessionStateControllerImpl::StartLockAnimationAndLockImmediately() { | |
118 animator_->StartAnimation( | |
119 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | |
120 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE, | |
121 internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); | |
122 DispatchCancelMode(); | |
123 FOR_EACH_OBSERVER(LockStateObserver, observers_, | |
124 OnLockStateEvent(LockStateObserver::EVENT_LOCK_ANIMATION_STARTED)); | |
125 OnLockTimeout(); | |
126 } | |
127 | |
128 void SessionStateControllerImpl::StartLockAnimation(bool shutdown_after_lock) { | |
129 shutdown_after_lock_ = shutdown_after_lock; | |
130 | |
131 animator_->StartAnimation( | |
132 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | |
133 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE, | |
134 internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); | |
135 DispatchCancelMode(); | |
136 FOR_EACH_OBSERVER(LockStateObserver, observers_, | |
137 OnLockStateEvent(LockStateObserver::EVENT_PRELOCK_ANIMATION_STARTED)); | |
138 StartLockTimer(); | |
139 } | |
140 | |
141 void SessionStateControllerImpl::StartShutdownAnimation() { | |
142 animator_->StartAnimation( | |
143 internal::SessionStateAnimator::kAllContainersMask, | |
144 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE, | |
145 internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); | |
146 | |
147 StartPreShutdownAnimationTimer(); | |
148 } | |
149 | |
150 bool SessionStateControllerImpl::LockRequested() { | |
151 return lock_fail_timer_.IsRunning(); | |
152 } | |
153 | |
154 bool SessionStateControllerImpl::ShutdownRequested() { | |
155 return shutting_down_; | |
156 } | |
157 | |
158 bool SessionStateControllerImpl::CanCancelLockAnimation() { | |
159 return lock_timer_.IsRunning(); | |
160 } | |
161 | |
162 void SessionStateControllerImpl::CancelLockAnimation() { | |
163 if (!CanCancelLockAnimation()) | |
164 return; | |
165 shutdown_after_lock_ = false; | |
166 animator_->StartAnimation( | |
167 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | |
168 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE, | |
169 internal::SessionStateAnimator::ANIMATION_SPEED_REVERT); | |
170 lock_timer_.Stop(); | |
171 } | |
172 | |
173 bool SessionStateControllerImpl::CanCancelShutdownAnimation() { | |
174 return pre_shutdown_timer_.IsRunning() || | |
175 shutdown_after_lock_ || | |
176 lock_to_shutdown_timer_.IsRunning(); | |
177 } | |
178 | |
179 void SessionStateControllerImpl::CancelShutdownAnimation() { | |
180 if (!CanCancelShutdownAnimation()) | |
181 return; | |
182 if (lock_to_shutdown_timer_.IsRunning()) { | |
183 lock_to_shutdown_timer_.Stop(); | |
184 return; | |
185 } | |
186 if (shutdown_after_lock_) { | |
187 shutdown_after_lock_ = false; | |
188 return; | |
189 } | |
190 | |
191 if (system_is_locked_) { | |
192 // If we've already started shutdown transition at lock screen | |
193 // desktop background needs to be restored immediately. | |
194 animator_->StartAnimation( | |
195 internal::SessionStateAnimator::DESKTOP_BACKGROUND, | |
196 internal::SessionStateAnimator::ANIMATION_RESTORE, | |
197 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); | |
198 animator_->StartAnimation( | |
199 internal::SessionStateAnimator::kAllLockScreenContainersMask, | |
200 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE, | |
201 internal::SessionStateAnimator::ANIMATION_SPEED_REVERT); | |
202 } else { | |
203 animator_->StartAnimation( | |
204 internal::SessionStateAnimator::kAllContainersMask, | |
205 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE, | |
206 internal::SessionStateAnimator::ANIMATION_SPEED_REVERT); | |
207 } | |
208 pre_shutdown_timer_.Stop(); | |
209 } | |
210 | |
211 void SessionStateControllerImpl::RequestShutdown() { | |
212 if (!shutting_down_) | |
213 RequestShutdownImpl(); | |
214 } | |
215 | |
216 void SessionStateControllerImpl::RequestShutdownImpl() { | |
217 DCHECK(!shutting_down_); | |
218 shutting_down_ = true; | |
219 | |
220 Shell* shell = ash::Shell::GetInstance(); | |
221 shell->env_filter()->set_cursor_hidden_by_filter(false); | |
222 shell->cursor_manager()->HideCursor(); | |
223 | |
224 if (login_status_ != user::LOGGED_IN_NONE) { | |
225 // Hide the other containers before starting the animation. | |
226 // ANIMATION_FULL_CLOSE will make the screen locker windows partially | |
227 // transparent, and we don't want the other windows to show through. | |
228 animator_->StartAnimation( | |
229 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | |
230 internal::SessionStateAnimator::LAUNCHER, | |
231 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, | |
232 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); | |
233 animator_->StartAnimation( | |
234 internal::SessionStateAnimator::kAllLockScreenContainersMask, | |
235 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE, | |
236 internal::SessionStateAnimator::ANIMATION_SPEED_FAST); | |
237 } else { | |
238 animator_->StartAnimation( | |
239 internal::SessionStateAnimator::kAllContainersMask, | |
240 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE, | |
241 internal::SessionStateAnimator::ANIMATION_SPEED_FAST); | |
242 } | |
243 StartRealShutdownTimer(); | |
244 } | |
245 | |
246 void SessionStateControllerImpl::OnRootWindowHostCloseRequested( | |
247 const aura::RootWindow*) { | |
248 Shell::GetInstance()->delegate()->Exit(); | |
249 } | |
250 | |
251 void SessionStateControllerImpl::StartLockTimer() { | |
252 lock_timer_.Stop(); | |
253 lock_timer_.Start( | |
254 FROM_HERE, | |
255 animator_->GetDuration( | |
256 internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE), | |
257 this, &SessionStateControllerImpl::OnLockTimeout); | |
258 } | |
259 | |
260 void SessionStateControllerImpl::OnLockTimeout() { | |
261 delegate_->RequestLockScreen(); | |
262 lock_fail_timer_.Start( | |
263 FROM_HERE, | |
264 base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs), | |
265 this, &SessionStateControllerImpl::OnLockFailTimeout); | |
266 } | |
267 | |
268 void SessionStateControllerImpl::OnLockFailTimeout() { | |
269 DCHECK(!system_is_locked_); | |
270 // Undo lock animation. | |
271 animator_->StartAnimation( | |
272 internal::SessionStateAnimator::LAUNCHER | | |
273 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | |
274 internal::SessionStateAnimator::ANIMATION_RESTORE, | |
275 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); | |
276 } | |
277 | |
278 void SessionStateControllerImpl::StartLockToShutdownTimer() { | |
279 shutdown_after_lock_ = false; | |
280 lock_to_shutdown_timer_.Stop(); | |
281 lock_to_shutdown_timer_.Start( | |
282 FROM_HERE, | |
283 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), | |
284 this, &SessionStateControllerImpl::OnLockToShutdownTimeout); | |
285 } | |
286 | |
287 | |
288 void SessionStateControllerImpl::OnLockToShutdownTimeout() { | |
289 DCHECK(system_is_locked_); | |
290 StartShutdownAnimation(); | |
291 } | |
292 | |
293 void SessionStateControllerImpl::StartPreShutdownAnimationTimer() { | |
294 pre_shutdown_timer_.Stop(); | |
295 pre_shutdown_timer_.Start( | |
296 FROM_HERE, | |
297 base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs), | |
298 this, &SessionStateControllerImpl::OnPreShutdownAnimationTimeout); | |
299 } | |
300 | |
301 void SessionStateControllerImpl::OnPreShutdownAnimationTimeout() { | |
302 if (!shutting_down_) | |
303 RequestShutdownImpl(); | |
304 } | |
305 | |
306 void SessionStateControllerImpl::StartRealShutdownTimer() { | |
307 base::TimeDelta duration = | |
308 base::TimeDelta::FromMilliseconds(kShutdownRequestDelayMs); | |
309 duration += animator_->GetDuration( | |
310 internal::SessionStateAnimator::ANIMATION_SPEED_FAST); | |
311 | |
312 real_shutdown_timer_.Start( | |
313 FROM_HERE, | |
314 duration, | |
315 this, &SessionStateControllerImpl::OnRealShutdownTimeout); | |
316 } | |
317 | |
318 void SessionStateControllerImpl::OnRealShutdownTimeout() { | |
319 DCHECK(shutting_down_); | |
320 #if defined(OS_CHROMEOS) | |
321 if (!base::SysInfo::IsRunningOnChromeOS()) { | |
322 ShellDelegate* delegate = Shell::GetInstance()->delegate(); | |
323 if (delegate) { | |
324 delegate->Exit(); | |
325 return; | |
326 } | |
327 } | |
328 #endif | |
329 delegate_->RequestShutdown(); | |
330 } | |
331 | |
332 void SessionStateControllerImpl::OnLockScreenHide(base::Closure& callback) { | |
333 callback.Run(); | |
334 } | |
335 | |
336 void SessionStateControllerImpl::SetLockScreenDisplayedCallback( | |
337 base::Closure& callback) { | |
338 NOTIMPLEMENTED(); | |
339 } | |
340 | |
341 } // namespace ash | |
OLD | NEW |