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