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

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: Initialize variable 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 shutdown_after_lock_(false),
35 animator_(new internal::SessionStateAnimator()) {
36 Shell::GetPrimaryRootWindow()->AddRootWindowObserver(this);
37 }
38
39 SessionStateController::~SessionStateController() {
40 Shell::GetPrimaryRootWindow()->RemoveRootWindowObserver(this);
41 }
42
43 void SessionStateController::OnLoginStateChanged(user::LoginStatus status) {
44 login_status_ = status;
45 unlocked_login_status_ = user::LOGGED_IN_NONE;
46 }
47
48 void SessionStateController::OnAppTerminating() {
49 // If we hear that Chrome is exiting but didn't request it ourselves, all we
50 // can really hope for is that we'll have time to clear the screen.
51 if (!shutting_down_) {
52 shutting_down_ = true;
53 Shell* shell = ash::Shell::GetInstance();
54 shell->env_filter()->set_cursor_hidden_by_filter(false);
55 shell->cursor_manager()->ShowCursor(false);
56 animator_->ShowBlackLayer();
57 animator_->StartAnimation(
58 internal::SessionStateAnimator::kAllContainersMask,
59 internal::SessionStateAnimator::ANIMATION_HIDE);
60 }
61 }
62
63 void SessionStateController::OnLockStateChanged(bool locked) {
64 if (shutting_down_ || (login_status_ == user::LOGGED_IN_LOCKED) == locked)
65 return;
66
67 if (!locked && login_status_ == user::LOGGED_IN_LOCKED) {
68 login_status_ = unlocked_login_status_;
69 unlocked_login_status_ = user::LOGGED_IN_NONE;
70 } else {
71 unlocked_login_status_ = login_status_;
72 login_status_ = user::LOGGED_IN_LOCKED;
73 }
74
75 if (locked) {
76 animator_->StartAnimation(
77 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
78 internal::SessionStateAnimator::ANIMATION_FADE_IN);
79 lock_timer_.Stop();
80 lock_fail_timer_.Stop();
81
82 if (shutdown_after_lock_) {
83 shutdown_after_lock_ = false;
84 StartLockToShutdownTimer();
85 }
86 } else {
87 animator_->StartAnimation(
88 internal::SessionStateAnimator::DESKTOP_BACKGROUND |
89 internal::SessionStateAnimator::LAUNCHER |
90 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
91 internal::SessionStateAnimator::ANIMATION_RESTORE);
92 animator_->DropBlackLayer();
93 }
94 }
95
96 void SessionStateController::OnStartingLock() {
97 if (shutting_down_ || login_status_ == user::LOGGED_IN_LOCKED)
98 return;
99
100 // Ensure that the black layer is visible -- if the screen was locked via
101 // the wrench menu, we won't have already shown the black background
102 // as part of the slow-close animation.
103 animator_->ShowBlackLayer();
104
105 animator_->StartAnimation(
106 internal::SessionStateAnimator::LAUNCHER,
107 internal::SessionStateAnimator::ANIMATION_HIDE);
108
109 animator_->StartAnimation(
110 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
111 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE);
112
113 // Hide the screen locker containers so we can make them fade in later.
114 animator_->StartAnimation(
115 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
116 internal::SessionStateAnimator::ANIMATION_HIDE);
117 }
118
119 void SessionStateController::StartLockAnimationButLockImmediately() {
120 animator_->ShowBlackLayer();
121 animator_->StartAnimation(
122 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
123 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE);
124 OnLockTimeout();
125 }
126
127 void SessionStateController::ShutdownImmediately() {
128 animator_->ShowBlackLayer();
129 if (!shutting_down_)
130 RequestShutdownImpl();
131 }
132
133 void SessionStateController::StartCancellableLock() {
134 shutdown_after_lock_ = true;
135
136 animator_->ShowBlackLayer();
137 animator_->StartAnimation(
138 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
139 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE);
140 StartLockTimer();
141 }
142
143 void SessionStateController::StartCancellableShutdown() {
144 animator_->ShowBlackLayer();
145 animator_->StartAnimation(
146 internal::SessionStateAnimator::kAllContainersMask,
147 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE);
148
149 StartPreShutdownAnimationTimer();
150 }
151
152 bool SessionStateController::IsEligibleForLock() {
153 return LoggedInAsNonGuest() && !IsLocked();
154 }
155
156 bool SessionStateController::IsLocked() {
157 return login_status_ == user::LOGGED_IN_LOCKED;
158 }
159
160 bool SessionStateController::IsTryingToLock() {
161 return lock_fail_timer_.IsRunning();
162 }
163
164 bool SessionStateController::IsLocking() {
165 return lock_timer_.IsRunning() || IsTryingToLock();
166 }
167
168 bool SessionStateController::IsShuttingDown() {
169 return shutting_down_;
170 }
171
172 bool SessionStateController::CanCancelLock() {
173 return lock_timer_.IsRunning();
174 }
175
176 void SessionStateController::CancelLock() {
177 if (!CanCancelLock())
178 return;
179 shutdown_after_lock_ = false;
180 animator_->StartAnimation(
181 internal::SessionStateAnimator::kAllContainersMask,
182 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE);
183 animator_->ScheduleDropBlackLayer();
184 lock_timer_.Stop();
185 }
186
187 void SessionStateController::CancelLockWithOtherAnimation() {
188 if (!CanCancelLock())
189 return;
190 shutdown_after_lock_ = false;
191 animator_->StartAnimation(
192 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
193 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE);
194 animator_->ScheduleDropBlackLayer();
195 lock_timer_.Stop();
196 }
197
198 bool SessionStateController::CanCancelShutdown() {
199 return pre_shutdown_timer_.IsRunning() ||
200 lock_to_shutdown_timer_.IsRunning();
201 }
202
203 void SessionStateController::CancelShutdown() {
204 if (!CanCancelShutdown())
205 return;
206 if (lock_to_shutdown_timer_.IsRunning()) {
207 lock_to_shutdown_timer_.Stop();
208 return;
209 }
210
211 if (login_status_ == user::LOGGED_IN_LOCKED) {
212 // If we've already started shutdown transition at lock screen
213 // desktop background needs to be restored immediately.
214 animator_->StartAnimation(
215 internal::SessionStateAnimator::DESKTOP_BACKGROUND,
216 internal::SessionStateAnimator::ANIMATION_RESTORE);
217 animator_->StartAnimation(
218 internal::SessionStateAnimator::kAllLockScreenContainersMask,
219 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE);
220 animator_->ScheduleDropBlackLayer();
221 } else {
222 animator_->StartAnimation(
223 internal::SessionStateAnimator::kAllContainersMask,
224 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE);
225 animator_->ScheduleDropBlackLayer();
226 }
227 pre_shutdown_timer_.Stop();
228 }
229
230 void SessionStateController::RequestShutdown() {
231 if (!shutting_down_)
232 RequestShutdownImpl();
233 }
234
235
236 void SessionStateController::RequestShutdownImpl() {
237 DCHECK(!shutting_down_);
238 shutting_down_ = true;
239
240 Shell* shell = ash::Shell::GetInstance();
241 shell->env_filter()->set_cursor_hidden_by_filter(false);
242 shell->cursor_manager()->ShowCursor(false);
243
244 animator_->ShowBlackLayer();
245 if (login_status_ != user::LOGGED_IN_NONE) {
246 // Hide the other containers before starting the animation.
247 // ANIMATION_FAST_CLOSE will make the screen locker windows partially
248 // transparent, and we don't want the other windows to show through.
249 animator_->StartAnimation(
250 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS |
251 internal::SessionStateAnimator::LAUNCHER,
252 internal::SessionStateAnimator::ANIMATION_HIDE);
253 animator_->StartAnimation(
254 internal::SessionStateAnimator::kAllLockScreenContainersMask,
255 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE);
256 } else {
257 animator_->StartAnimation(
258 internal::SessionStateAnimator::kAllContainersMask,
259 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE);
260 }
261 StartRealShutdownTimer();
262 }
263
264 void SessionStateController::OnRootWindowHostCloseRequested(
265 const aura::RootWindow*) {
266 if(Shell::GetInstance() && Shell::GetInstance()->delegate())
267 Shell::GetInstance()->delegate()->Exit();
268 }
269
270 bool SessionStateController::LoggedInAsNonGuest() const {
271 if (login_status_ == user::LOGGED_IN_NONE)
272 return false;
273 if (login_status_ == user::LOGGED_IN_GUEST)
274 return false;
275 // TODO(mukai): think about kiosk mode.
276 return true;
277 }
278
279 // ----------- Timer stuff.
280
281 void SessionStateController::StartLockTimer() {
282 lock_timer_.Stop();
283 lock_timer_.Start(FROM_HERE,
284 base::TimeDelta::FromMilliseconds(
285 internal::kSlowCloseAnimMs),
286 this, &SessionStateController::OnLockTimeout);
287 }
288
289 void SessionStateController::OnLockTimeout() {
290 delegate_->RequestLockScreen();
291 lock_fail_timer_.Start(
292 FROM_HERE,
293 base::TimeDelta::FromMilliseconds(internal::kLockFailTimeoutMs),
294 this, &SessionStateController::OnLockFailTimeout);
295 }
296
297 void SessionStateController::OnLockFailTimeout() {
298 DCHECK_NE(login_status_, user::LOGGED_IN_LOCKED);
299 // Undo lock animation.
300 animator_->StartAnimation(
301 internal::SessionStateAnimator::LAUNCHER |
302 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
303 internal::SessionStateAnimator::ANIMATION_RESTORE);
304 animator_->DropBlackLayer();
305 }
306
307 void SessionStateController::StartLockToShutdownTimer() {
308 shutdown_after_lock_ = false;
309 lock_to_shutdown_timer_.Stop();
310 lock_to_shutdown_timer_.Start(
311 FROM_HERE,
312 base::TimeDelta::FromMilliseconds(internal::kLockToShutdownTimeoutMs),
313 this, &SessionStateController::OnLockToShutdownTimeout);
314 }
315
316
317 void SessionStateController::OnLockToShutdownTimeout() {
318 DCHECK_EQ(login_status_, user::LOGGED_IN_LOCKED);
319 StartCancellableShutdown();
320 }
321
322 void SessionStateController::StartPreShutdownAnimationTimer() {
323 pre_shutdown_timer_.Stop();
324 pre_shutdown_timer_.Start(
325 FROM_HERE,
326 base::TimeDelta::FromMilliseconds(internal::kShutdownTimeoutMs),
327 this, &SessionStateController::OnPreShutdownAnimationTimeout);
328 }
329
330 void SessionStateController::OnPreShutdownAnimationTimeout() {
331 if (!shutting_down_)
332 RequestShutdownImpl();
333 }
334
335 void SessionStateController::StartRealShutdownTimer() {
336 real_shutdown_timer_.Start(
337 FROM_HERE,
338 base::TimeDelta::FromMilliseconds(
339 internal::kFastCloseAnimMs + internal::kShutdownRequestDelayMs),
340 this, &SessionStateController::OnRealShutdownTimeout);
341 }
342
343 void SessionStateController::OnRealShutdownTimeout() {
344 DCHECK(shutting_down_);
345 #if defined(OS_CHROMEOS)
346 if (!base::chromeos::IsRunningOnChromeOS()) {
347 ShellDelegate* delegate = Shell::GetInstance()->delegate();
348 if (delegate)
349 delegate->Exit();
350 }
351 #endif
352 delegate_->RequestShutdown();
353 }
354
355 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698