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

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: 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
20
21 namespace ash {
22
23 SessionStateController::TestApi::TestApi(SessionStateController* controller)
24 : controller_(controller) {
25 }
26
27 SessionStateController::TestApi::~TestApi() {
28 }
29
30 SessionStateController::SessionStateController()
31 : login_status_(user::LOGGED_IN_NONE),
32 unlocked_login_status_(user::LOGGED_IN_NONE),
33 shutting_down_(false),
34 animator_(new internal::SessionStateAnimator()) {
35 Shell::GetPrimaryRootWindow()->AddRootWindowObserver(this);
36 }
37
38 SessionStateController::~SessionStateController() {
39 Shell::GetPrimaryRootWindow()->RemoveRootWindowObserver(this);
40 }
41
42 void SessionStateController::OnLoginStateChanged(user::LoginStatus status) {
43 login_status_ = status;
44 unlocked_login_status_ = user::LOGGED_IN_NONE;
45 }
46
47 void SessionStateController::OnAppTerminating() {
48 // If we hear that Chrome is exiting but didn't request it ourselves, all we
49 // can really hope for is that we'll have time to clear the screen.
50 if (!shutting_down_) {
51 shutting_down_ = true;
52 Shell* shell = ash::Shell::GetInstance();
53 shell->env_filter()->set_cursor_hidden_by_filter(false);
54 shell->cursor_manager()->ShowCursor(false);
55 animator_->ShowBlackLayer();
56 animator_->StartAnimation(
57 internal::SessionStateAnimator::kAllContainersMask,
58 internal::SessionStateAnimator::ANIMATION_HIDE);
59 }
60 }
61
62 void SessionStateController::OnLockStateChanged(bool locked) {
63 if (shutting_down_ || (login_status_ == user::LOGGED_IN_LOCKED) == locked)
64 return;
65
66 if (!locked && login_status_ == user::LOGGED_IN_LOCKED) {
67 login_status_ = unlocked_login_status_;
68 unlocked_login_status_ = user::LOGGED_IN_NONE;
69 } else {
70 unlocked_login_status_ = login_status_;
71 login_status_ = user::LOGGED_IN_LOCKED;
72 }
73
74 if (locked) {
75 animator_->StartAnimation(
76 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
77 internal::SessionStateAnimator::ANIMATION_FADE_IN);
78 lock_timer_.Stop();
79 lock_fail_timer_.Stop();
80
81 if (shutdown_after_lock_) {
82 shutdown_after_lock_ = false;
83 StartLockToShutdownTimer();
84 }
85 } else {
86 animator_->StartAnimation(
87 internal::SessionStateAnimator::DESKTOP_BACKGROUND |
88 internal::SessionStateAnimator::LAUNCHER |
89 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
90 internal::SessionStateAnimator::ANIMATION_RESTORE);
91 animator_->DropBlackLayer();
92 }
93 }
94
95 void SessionStateController::OnStartingLock() {
96 if (shutting_down_ || login_status_ == user::LOGGED_IN_LOCKED)
97 return;
98
99 // Ensure that the black layer is visible -- if the screen was locked via
100 // the wrench menu, we won't have already shown the black background
101 // as part of the slow-close animation.
102 animator_->ShowBlackLayer();
103
104 animator_->StartAnimation(
105 internal::SessionStateAnimator::LAUNCHER,
106 internal::SessionStateAnimator::ANIMATION_HIDE);
107
108 animator_->StartAnimation(
109 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
110 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE);
111
112 // Hide the screen locker containers so we can make them fade in later.
113 animator_->StartAnimation(
114 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
115 internal::SessionStateAnimator::ANIMATION_HIDE);
116 }
117
118 void SessionStateController::StartLockAnimationButLockImmediately() {
119 animator_->ShowBlackLayer();
120 animator_->StartAnimation(
121 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
122 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE);
123 OnLockTimeout();
124 }
125
126 void SessionStateController::ShutdownImmediately() {
127 animator_->ShowBlackLayer();
128 if (!shutting_down_)
129 RequestShutdownImpl();
130 }
131
132 void SessionStateController::StartCancellableLock() {
133 shutdown_after_lock_ = true;
134
135 animator_->ShowBlackLayer();
136 animator_->StartAnimation(
137 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
138 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE);
139 StartLockTimer();
140 }
141
142 void SessionStateController::StartCancellableShutdown() {
143 animator_->ShowBlackLayer();
144 animator_->StartAnimation(
145 internal::SessionStateAnimator::kAllContainersMask,
146 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE);
147
148 StartPreShutdownAnimationTimer();
149 }
150
151 bool SessionStateController::IsEligibleForLock() {
152 return LoggedInAsNonGuest() && !IsLocked();
153 }
154
155 bool SessionStateController::IsLocked() {
156 return login_status_ == user::LOGGED_IN_LOCKED;
157 }
158
159 bool SessionStateController::IsTryingToLock() {
160 return lock_fail_timer_.IsRunning();
161 }
162
163 bool SessionStateController::IsLocking() {
164 return lock_timer_.IsRunning() || IsTryingToLock();
165 }
166
167 bool SessionStateController::IsShuttingDown() {
168 return shutting_down_;
169 }
170
171 bool SessionStateController::CanCancelLock() {
172 return lock_timer_.IsRunning();
173 }
174
175 void SessionStateController::CancelLock() {
176 if (!CanCancelLock())
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 (!CanCancelLock())
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::CanCancelShutdown() {
198 return pre_shutdown_timer_.IsRunning() ||
199 lock_to_shutdown_timer_.IsRunning();
200 }
201
202 void SessionStateController::CancelShutdown() {
203 if (!CanCancelShutdown())
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 RequestShutdownImpl();
232 }
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)
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 // ----------- Timer stuff.
279
280 void SessionStateController::StartLockTimer() {
281 lock_timer_.Stop();
282 lock_timer_.Start(FROM_HERE,
283 base::TimeDelta::FromMilliseconds(
284 internal::kSlowCloseAnimMs),
285 this, &SessionStateController::OnLockTimeout);
286 }
287
288 void SessionStateController::OnLockTimeout() {
289 delegate_->RequestLockScreen();
290 lock_fail_timer_.Start(
291 FROM_HERE,
292 base::TimeDelta::FromMilliseconds(internal::kLockFailTimeoutMs),
293 this, &SessionStateController::OnLockFailTimeout);
294 }
295
296 void SessionStateController::OnLockFailTimeout() {
297 DCHECK_NE(login_status_, user::LOGGED_IN_LOCKED);
298 // Undo lock animation.
299 animator_->StartAnimation(
300 internal::SessionStateAnimator::LAUNCHER |
301 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
302 internal::SessionStateAnimator::ANIMATION_RESTORE);
303 animator_->DropBlackLayer();
304 }
305
306 void SessionStateController::StartLockToShutdownTimer() {
307 shutdown_after_lock_ = false;
308 lock_to_shutdown_timer_.Stop();
309 lock_to_shutdown_timer_.Start(
310 FROM_HERE,
311 base::TimeDelta::FromMilliseconds(internal::kLockToShutdownTimeoutMs),
312 this, &SessionStateController::OnLockToShutdownTimeout);
313 }
314
315
316 void SessionStateController::OnLockToShutdownTimeout() {
317 DCHECK_EQ(login_status_, user::LOGGED_IN_LOCKED);
318 StartCancellableShutdown();
319 }
320
321 void SessionStateController::StartPreShutdownAnimationTimer() {
322 pre_shutdown_timer_.Stop();
323 pre_shutdown_timer_.Start(
324 FROM_HERE,
325 base::TimeDelta::FromMilliseconds(internal::kShutdownTimeoutMs),
326 this, &SessionStateController::OnPreShutdownAnimationTimeout);
327 }
328
329 void SessionStateController::OnPreShutdownAnimationTimeout() {
330 if (!shutting_down_)
331 RequestShutdownImpl();
332 }
333
334 void SessionStateController::StartRealShutdownTimer() {
335 real_shutdown_timer_.Start(
336 FROM_HERE,
337 base::TimeDelta::FromMilliseconds(
338 internal::kFastCloseAnimMs + internal::kShutdownRequestDelayMs),
339 this, &SessionStateController::OnRealShutdownTimeout);
340 }
341
342 void SessionStateController::OnRealShutdownTimeout() {
343 DCHECK(shutting_down_);
344 #if defined(OS_CHROMEOS)
345 if (!base::chromeos::IsRunningOnChromeOS()) {
346 ShellDelegate* delegate = Shell::GetInstance()->delegate();
347 if (delegate)
348 delegate->Exit();
349 }
350 #endif
351 delegate_->RequestShutdown();
352 }
353
354 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698