diff options
21 files changed, 862 insertions, 2197 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index 6b1c93d..1d677f5 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -441,8 +441,6 @@ 'wm/image_cursors.h', 'wm/lock_state_controller.cc', 'wm/lock_state_controller.h', - 'wm/lock_state_controller_impl2.cc', - 'wm/lock_state_controller_impl2.h', 'wm/lock_state_observer.h', 'wm/mru_window_tracker.cc', 'wm/mru_window_tracker.h', @@ -485,8 +483,6 @@ 'wm/screen_dimmer.h', 'wm/session_state_animator.cc', 'wm/session_state_animator.h', - 'wm/session_state_controller_impl.cc', - 'wm/session_state_controller_impl.h', 'wm/stacking_controller.cc', 'wm/stacking_controller.h', 'wm/status_area_layout_manager.cc', @@ -771,13 +767,12 @@ 'wm/dock/docked_window_resizer_unittest.cc', 'wm/drag_window_resizer_unittest.cc', 'wm/frame_painter_unittest.cc', - 'wm/lock_state_controller_impl2_unittest.cc', + 'wm/lock_state_controller_unittest.cc', 'wm/mru_window_tracker_unittest.cc', 'wm/overview/window_selector_unittest.cc', 'wm/panels/panel_layout_manager_unittest.cc', 'wm/panels/panel_window_resizer_unittest.cc', 'wm/partial_screenshot_view_unittest.cc', - 'wm/power_button_controller_unittest.cc', 'wm/screen_dimmer_unittest.cc', 'wm/stacking_controller_unittest.cc', 'wm/sticky_keys_unittest.cc', diff --git a/ash/ash_switches.cc b/ash/ash_switches.cc index 4242373..004876d 100644 --- a/ash/ash_switches.cc +++ b/ash/ash_switches.cc @@ -61,9 +61,6 @@ const char kAshDisableAutoMaximizing[] = "ash-disable-auto-maximizing"; const char kAshDisableDisplayChangeLimiter[] = "ash-disable-display-change-limiter"; -// If present new lock animations are enabled. -const char kAshDisableNewLockAnimations[] = "ash-disable-new-lock-animations"; - // Disable immersive fullscreen mode, regardless of default setting. const char kAshDisableImmersiveFullscreen[] = "ash-disable-immersive-fullscreen"; diff --git a/ash/ash_switches.h b/ash/ash_switches.h index 006b8dc..339226d 100644 --- a/ash/ash_switches.h +++ b/ash/ash_switches.h @@ -33,7 +33,6 @@ ASH_EXPORT extern const char kAshDisableAutoMaximizing[]; ASH_EXPORT extern const char kAshDisableDisplayChangeLimiter[]; ASH_EXPORT extern const char kAshDisableDragOffShelf[]; ASH_EXPORT extern const char kAshDisableImmersiveFullscreen[]; -ASH_EXPORT extern const char kAshDisableNewLockAnimations[]; ASH_EXPORT extern const char kAshDisableOverviewMode[]; ASH_EXPORT extern const char kAshDisableDragAndDropAppListToLauncher[]; #if defined(OS_CHROMEOS) diff --git a/ash/shell.cc b/ash/shell.cc index 123b81e..bea797a 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -55,7 +55,6 @@ #include "ash/wm/event_client_impl.h" #include "ash/wm/event_rewriter_event_filter.h" #include "ash/wm/lock_state_controller.h" -#include "ash/wm/lock_state_controller_impl2.h" #include "ash/wm/mru_window_tracker.h" #include "ash/wm/overlay_event_filter.h" #include "ash/wm/overview/window_selector_controller.h" @@ -63,7 +62,6 @@ #include "ash/wm/resize_shadow_controller.h" #include "ash/wm/root_window_layout_manager.h" #include "ash/wm/screen_dimmer.h" -#include "ash/wm/session_state_controller_impl.h" #include "ash/wm/system_gesture_event_filter.h" #include "ash/wm/system_modal_container_event_filter.h" #include "ash/wm/system_modal_container_layout_manager.h" @@ -493,10 +491,7 @@ void Shell::Init() { if (keyboard::IsKeyboardEnabled()) keyboard::InitializeKeyboard(); - if (command_line->HasSwitch(ash::switches::kAshDisableNewLockAnimations)) - lock_state_controller_.reset(new SessionStateControllerImpl); - else - lock_state_controller_.reset(new LockStateControllerImpl2); + lock_state_controller_.reset(new LockStateController); power_button_controller_.reset(new PowerButtonController( lock_state_controller_.get())); AddShellObserver(lock_state_controller_.get()); diff --git a/ash/wm/lock_state_controller.cc b/ash/wm/lock_state_controller.cc index 3b3d1cf..6117224 100644 --- a/ash/wm/lock_state_controller.cc +++ b/ash/wm/lock_state_controller.cc @@ -5,27 +5,162 @@ #include "ash/wm/lock_state_controller.h" #include "ash/ash_switches.h" +#include "ash/cancel_mode.h" #include "ash/shell.h" #include "ash/shell_delegate.h" #include "ash/shell_window_ids.h" #include "ash/wm/session_state_animator.h" +#include "base/bind_helpers.h" #include "base/command_line.h" +#include "base/timer/timer.h" #include "ui/aura/root_window.h" +#include "ui/compositor/layer_animation_sequence.h" +#include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/views/corewm/compound_event_filter.h" +#if defined(OS_CHROMEOS) +#include "base/sys_info.h" +#endif + namespace ash { +namespace { + +aura::Window* GetBackground() { + aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); + return Shell::GetContainer(root_window, + internal::kShellWindowId_DesktopBackgroundContainer); +} + +bool IsBackgroundHidden() { + return !GetBackground()->IsVisible(); +} + +void ShowBackground() { + ui::ScopedLayerAnimationSettings settings( + GetBackground()->layer()->GetAnimator()); + settings.SetTransitionDuration(base::TimeDelta()); + GetBackground()->Show(); +} + +void HideBackground() { + ui::ScopedLayerAnimationSettings settings( + GetBackground()->layer()->GetAnimator()); + settings.SetTransitionDuration(base::TimeDelta()); + GetBackground()->Hide(); +} + +// This observer is intended to use in cases when some action has to be taken +// once some animation successfully completes (i.e. it was not aborted). +// Observer will count a number of sequences it is attached to, and a number of +// finished sequences (either Ended or Aborted). Once these two numbers are +// equal, observer will delete itself, calling callback passed to constructor if +// there were no aborted animations. +// This way it can be either used to wait for some animation to be finished in +// multiple layers, to wait once a sequence of animations is finished in one +// layer or the mixture of both. +class AnimationFinishedObserver : public ui::LayerAnimationObserver { + public: + explicit AnimationFinishedObserver(base::Closure &callback) + : callback_(callback), + sequences_attached_(0), + sequences_completed_(0), + paused_(false) { + } + + // Pauses observer: no checks will be made while paused. It can be used when + // a sequence has some immediate animations in the beginning, and for + // animations that can be tested with flag that makes all animations + // immediate. + void Pause() { + paused_ = true; + } + + // Unpauses observer. It does a check and calls callback if conditions are + // met. + void Unpause() { + if (!paused_) + return; + paused_ = false; + if (sequences_completed_ == sequences_attached_) { + callback_.Run(); + delete this; + } + } + + private: + virtual ~AnimationFinishedObserver() { + } + + // LayerAnimationObserver implementation + virtual void OnLayerAnimationEnded( + ui::LayerAnimationSequence* sequence) OVERRIDE { + sequences_completed_++; + if ((sequences_completed_ == sequences_attached_) && !paused_) { + callback_.Run(); + delete this; + } + } + + virtual void OnLayerAnimationAborted( + ui::LayerAnimationSequence* sequence) OVERRIDE { + sequences_completed_++; + if ((sequences_completed_ == sequences_attached_) && !paused_) + delete this; + } + + virtual void OnLayerAnimationScheduled( + ui::LayerAnimationSequence* sequence) OVERRIDE { + } + + virtual void OnAttachedToSequence( + ui::LayerAnimationSequence* sequence) OVERRIDE { + LayerAnimationObserver::OnAttachedToSequence(sequence); + sequences_attached_++; + } + + // Callback to be called. + base::Closure callback_; + + // Number of sequences this observer was attached to. + int sequences_attached_; + + // Number of sequences either ended or aborted. + int sequences_completed_; + + bool paused_; + + DISALLOW_COPY_AND_ASSIGN(AnimationFinishedObserver); +}; + +} // namespace + const int LockStateController::kLockTimeoutMs = 400; const int LockStateController::kShutdownTimeoutMs = 400; const int LockStateController::kLockFailTimeoutMs = 8000; const int LockStateController::kLockToShutdownTimeoutMs = 150; const int LockStateController::kShutdownRequestDelayMs = 50; +LockStateController::TestApi::TestApi(LockStateController* controller) + : controller_(controller) { +} + +LockStateController::TestApi::~TestApi() { +} + LockStateController::LockStateController() - : animator_(new internal::SessionStateAnimator()) { + : animator_(new internal::SessionStateAnimator()), + login_status_(user::LOGGED_IN_NONE), + system_is_locked_(false), + shutting_down_(false), + shutdown_after_lock_(false), + animating_lock_(false), + can_cancel_lock_animation_(false) { + Shell::GetPrimaryRootWindow()->AddRootWindowObserver(this); } LockStateController::~LockStateController() { + Shell::GetPrimaryRootWindow()->RemoveRootWindowObserver(this); } void LockStateController::SetDelegate(LockStateControllerDelegate* delegate) { @@ -44,5 +179,479 @@ bool LockStateController::HasObserver(LockStateObserver* observer) { return observers_.HasObserver(observer); } +void LockStateController::StartLockAnimation( + bool shutdown_after_lock) { + if (animating_lock_) + return; + shutdown_after_lock_ = shutdown_after_lock; + can_cancel_lock_animation_ = true; + + StartCancellablePreLockAnimation(); +} + +void LockStateController::StartShutdownAnimation() { + StartCancellableShutdownAnimation(); +} + +void LockStateController::StartLockAnimationAndLockImmediately() { + if (animating_lock_) + return; + StartImmediatePreLockAnimation(true /* request_lock_on_completion */); +} + +bool LockStateController::LockRequested() { + return lock_fail_timer_.IsRunning(); +} + +bool LockStateController::ShutdownRequested() { + return shutting_down_; +} + +bool LockStateController::CanCancelLockAnimation() { + return can_cancel_lock_animation_; +} + +void LockStateController::CancelLockAnimation() { + if (!CanCancelLockAnimation()) + return; + shutdown_after_lock_ = false; + animating_lock_ = false; + CancelPreLockAnimation(); +} + +bool LockStateController::CanCancelShutdownAnimation() { + return pre_shutdown_timer_.IsRunning() || + shutdown_after_lock_ || + lock_to_shutdown_timer_.IsRunning(); +} + +void LockStateController::CancelShutdownAnimation() { + if (!CanCancelShutdownAnimation()) + return; + if (lock_to_shutdown_timer_.IsRunning()) { + lock_to_shutdown_timer_.Stop(); + return; + } + if (shutdown_after_lock_) { + shutdown_after_lock_ = false; + return; + } + + animator_->StartGlobalAnimation( + internal::SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS, + internal::SessionStateAnimator::ANIMATION_SPEED_REVERT_SHUTDOWN); + pre_shutdown_timer_.Stop(); +} + +void LockStateController::OnStartingLock() { + if (shutting_down_ || system_is_locked_) + return; + if (animating_lock_) + return; + StartImmediatePreLockAnimation(false /* request_lock_on_completion */); +} + +void LockStateController::RequestShutdown() { + if (shutting_down_) + return; + + shutting_down_ = true; + + Shell* shell = ash::Shell::GetInstance(); + shell->env_filter()->set_cursor_hidden_by_filter(false); + shell->cursor_manager()->HideCursor(); + + animator_->StartGlobalAnimation( + internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS, + internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); + StartRealShutdownTimer(true); +} + +void LockStateController::OnLockScreenHide( + base::Callback<void(void)>& callback) { + StartUnlockAnimationBeforeUIDestroyed(callback); +} + +void LockStateController::SetLockScreenDisplayedCallback( + base::Closure& callback) { + lock_screen_displayed_callback_ = callback; +} + +void LockStateController::OnRootWindowHostCloseRequested( + const aura::RootWindow*) { + Shell::GetInstance()->delegate()->Exit(); +} + +void LockStateController::OnLoginStateChanged( + user::LoginStatus status) { + if (status != user::LOGGED_IN_LOCKED) + login_status_ = status; + system_is_locked_ = (status == user::LOGGED_IN_LOCKED); +} + +void LockStateController::OnAppTerminating() { + // If we hear that Chrome is exiting but didn't request it ourselves, all we + // can really hope for is that we'll have time to clear the screen. + // This is also the case when the user signs off. + if (!shutting_down_) { + shutting_down_ = true; + Shell* shell = ash::Shell::GetInstance(); + shell->env_filter()->set_cursor_hidden_by_filter(false); + shell->cursor_manager()->HideCursor(); + animator_->StartAnimation( + internal::SessionStateAnimator::kAllContainersMask, + internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, + internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); + } +} + +void LockStateController::OnLockStateChanged(bool locked) { + if (shutting_down_ || (system_is_locked_ == locked)) + return; + + system_is_locked_ = locked; + + if (locked) { + StartPostLockAnimation(); + lock_fail_timer_.Stop(); + } else { + StartUnlockAnimationAfterUIDestroyed(); + } +} + +void LockStateController::OnLockFailTimeout() { + DCHECK(!system_is_locked_); + // Undo lock animation. + StartUnlockAnimationAfterUIDestroyed(); +} + +void LockStateController::StartLockToShutdownTimer() { + shutdown_after_lock_ = false; + lock_to_shutdown_timer_.Stop(); + lock_to_shutdown_timer_.Start( + FROM_HERE, + base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), + this, &LockStateController::OnLockToShutdownTimeout); +} + +void LockStateController::OnLockToShutdownTimeout() { + DCHECK(system_is_locked_); + StartCancellableShutdownAnimation(); +} + +void LockStateController::StartPreShutdownAnimationTimer() { + pre_shutdown_timer_.Stop(); + pre_shutdown_timer_.Start( + FROM_HERE, + animator_-> + GetDuration(internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN), + this, + &LockStateController::OnPreShutdownAnimationTimeout); +} + +void LockStateController::OnPreShutdownAnimationTimeout() { + shutting_down_ = true; + + Shell* shell = ash::Shell::GetInstance(); + shell->env_filter()->set_cursor_hidden_by_filter(false); + shell->cursor_manager()->HideCursor(); + + StartRealShutdownTimer(false); +} + +void LockStateController::StartRealShutdownTimer( + bool with_animation_time) { + base::TimeDelta duration = + base::TimeDelta::FromMilliseconds(kShutdownRequestDelayMs); + if (with_animation_time) { + duration += animator_->GetDuration( + internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); + } + real_shutdown_timer_.Start( + FROM_HERE, + duration, + this, + &LockStateController::OnRealShutdownTimeout); +} + +void LockStateController::OnRealShutdownTimeout() { + DCHECK(shutting_down_); +#if defined(OS_CHROMEOS) + if (!base::SysInfo::IsRunningOnChromeOS()) { + ShellDelegate* delegate = Shell::GetInstance()->delegate(); + if (delegate) { + delegate->Exit(); + return; + } + } +#endif + Shell::GetInstance()->delegate()->RecordUserMetricsAction( + UMA_ACCEL_SHUT_DOWN_POWER_BUTTON); + delegate_->RequestShutdown(); +} + +void LockStateController::StartCancellableShutdownAnimation() { + Shell* shell = ash::Shell::GetInstance(); + // Hide cursor, but let it reappear if the mouse moves. + shell->env_filter()->set_cursor_hidden_by_filter(true); + shell->cursor_manager()->HideCursor(); + + animator_->StartGlobalAnimation( + internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS, + internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); + StartPreShutdownAnimationTimer(); +} + +void LockStateController::StartImmediatePreLockAnimation( + bool request_lock_on_completion) { + animating_lock_ = true; + + StoreUnlockedProperties(); + + base::Closure next_animation_starter = + base::Bind(&LockStateController::PreLockAnimationFinished, + base::Unretained(this), request_lock_on_completion); + AnimationFinishedObserver* observer = + new AnimationFinishedObserver(next_animation_starter); + + observer->Pause(); + + animator_->StartAnimationWithObserver( + internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, + internal::SessionStateAnimator::ANIMATION_LIFT, + internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, + observer); + animator_->StartAnimationWithObserver( + internal::SessionStateAnimator::LAUNCHER, + internal::SessionStateAnimator::ANIMATION_FADE_OUT, + internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, + observer); + // Hide the screen locker containers so we can raise them later. + animator_->StartAnimation( + internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, + internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, + internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); + AnimateBackgroundAppearanceIfNecessary( + internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, + observer); + + observer->Unpause(); + + DispatchCancelMode(); + FOR_EACH_OBSERVER(LockStateObserver, observers_, + OnLockStateEvent(LockStateObserver::EVENT_LOCK_ANIMATION_STARTED)); +} + +void LockStateController::StartCancellablePreLockAnimation() { + animating_lock_ = true; + StoreUnlockedProperties(); + + base::Closure next_animation_starter = + base::Bind(&LockStateController::PreLockAnimationFinished, + base::Unretained(this), true /* request_lock */); + AnimationFinishedObserver* observer = + new AnimationFinishedObserver(next_animation_starter); + + observer->Pause(); + + animator_->StartAnimationWithObserver( + internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, + internal::SessionStateAnimator::ANIMATION_LIFT, + internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, + observer); + animator_->StartAnimationWithObserver( + internal::SessionStateAnimator::LAUNCHER, + internal::SessionStateAnimator::ANIMATION_FADE_OUT, + internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, + observer); + // Hide the screen locker containers so we can raise them later. + animator_->StartAnimation( + internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, + internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, + internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); + AnimateBackgroundAppearanceIfNecessary( + internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, + observer); + + DispatchCancelMode(); + FOR_EACH_OBSERVER(LockStateObserver, observers_, + OnLockStateEvent(LockStateObserver::EVENT_PRELOCK_ANIMATION_STARTED)); + observer->Unpause(); +} + +void LockStateController::CancelPreLockAnimation() { + base::Closure next_animation_starter = + base::Bind(&LockStateController::LockAnimationCancelled, + base::Unretained(this)); + AnimationFinishedObserver* observer = + new AnimationFinishedObserver(next_animation_starter); + + observer->Pause(); + + animator_->StartAnimationWithObserver( + internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, + internal::SessionStateAnimator::ANIMATION_UNDO_LIFT, + internal::SessionStateAnimator::ANIMATION_SPEED_UNDO_MOVE_WINDOWS, + observer); + animator_->StartAnimationWithObserver( + internal::SessionStateAnimator::LAUNCHER, + internal::SessionStateAnimator::ANIMATION_FADE_IN, + internal::SessionStateAnimator::ANIMATION_SPEED_UNDO_MOVE_WINDOWS, + observer); + AnimateBackgroundHidingIfNecessary( + internal::SessionStateAnimator::ANIMATION_SPEED_UNDO_MOVE_WINDOWS, + observer); + + observer->Unpause(); +} + +void LockStateController::StartPostLockAnimation() { + base::Closure next_animation_starter = + base::Bind(&LockStateController::PostLockAnimationFinished, + base::Unretained(this)); + + AnimationFinishedObserver* observer = + new AnimationFinishedObserver(next_animation_starter); + + observer->Pause(); + animator_->StartAnimationWithObserver( + internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, + internal::SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN, + internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, + observer); + observer->Unpause(); +} + +void LockStateController::StartUnlockAnimationBeforeUIDestroyed( + base::Closure& callback) { + animator_->StartAnimationWithCallback( + internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, + internal::SessionStateAnimator::ANIMATION_LIFT, + internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, + callback); +} + +void LockStateController::StartUnlockAnimationAfterUIDestroyed() { + base::Closure next_animation_starter = + base::Bind(&LockStateController::UnlockAnimationAfterUIDestroyedFinished, + base::Unretained(this)); + + AnimationFinishedObserver* observer = + new AnimationFinishedObserver(next_animation_starter); + + observer->Pause(); + + animator_->StartAnimationWithObserver( + internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, + internal::SessionStateAnimator::ANIMATION_DROP, + internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, + observer); + animator_->StartAnimationWithObserver( + internal::SessionStateAnimator::LAUNCHER, + internal::SessionStateAnimator::ANIMATION_FADE_IN, + internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, + observer); + AnimateBackgroundHidingIfNecessary( + internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, + observer); + observer->Unpause(); +} + +void LockStateController::LockAnimationCancelled() { + can_cancel_lock_animation_ = false; + RestoreUnlockedProperties(); +} + +void LockStateController::PreLockAnimationFinished(bool request_lock) { + can_cancel_lock_animation_ = false; + + if (request_lock) { + Shell::GetInstance()->delegate()->RecordUserMetricsAction( + shutdown_after_lock_ ? + UMA_ACCEL_LOCK_SCREEN_POWER_BUTTON : + UMA_ACCEL_LOCK_SCREEN_LOCK_BUTTON); + delegate_->RequestLockScreen(); + } + + lock_fail_timer_.Start( + FROM_HERE, + base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs), + this, + &LockStateController::OnLockFailTimeout); +} + +void LockStateController::PostLockAnimationFinished() { + animating_lock_ = false; + + FOR_EACH_OBSERVER(LockStateObserver, observers_, + OnLockStateEvent(LockStateObserver::EVENT_LOCK_ANIMATION_FINISHED)); + if (!lock_screen_displayed_callback_.is_null()) { + lock_screen_displayed_callback_.Run(); + lock_screen_displayed_callback_.Reset(); + } + if (shutdown_after_lock_) { + shutdown_after_lock_ = false; + StartLockToShutdownTimer(); + } +} + +void LockStateController::UnlockAnimationAfterUIDestroyedFinished() { + RestoreUnlockedProperties(); +} + +void LockStateController::StoreUnlockedProperties() { + if (!unlocked_properties_) { + unlocked_properties_.reset(new UnlockedStateProperties()); + unlocked_properties_->background_is_hidden = IsBackgroundHidden(); + } + if (unlocked_properties_->background_is_hidden) { + // Hide background so that it can be animated later. + animator_->StartAnimation( + internal::SessionStateAnimator::DESKTOP_BACKGROUND, + internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, + internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); + ShowBackground(); + } +} + +void LockStateController::RestoreUnlockedProperties() { + if (!unlocked_properties_) + return; + if (unlocked_properties_->background_is_hidden) { + HideBackground(); + // Restore background visibility. + animator_->StartAnimation( + internal::SessionStateAnimator::DESKTOP_BACKGROUND, + internal::SessionStateAnimator::ANIMATION_FADE_IN, + internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); + } + unlocked_properties_.reset(); +} + +void LockStateController::AnimateBackgroundAppearanceIfNecessary( + internal::SessionStateAnimator::AnimationSpeed speed, + ui::LayerAnimationObserver* observer) { + if (unlocked_properties_.get() && + unlocked_properties_->background_is_hidden) { + animator_->StartAnimationWithObserver( + internal::SessionStateAnimator::DESKTOP_BACKGROUND, + internal::SessionStateAnimator::ANIMATION_FADE_IN, + speed, + observer); + } +} + +void LockStateController::AnimateBackgroundHidingIfNecessary( + internal::SessionStateAnimator::AnimationSpeed speed, + ui::LayerAnimationObserver* observer) { + if (unlocked_properties_.get() && + unlocked_properties_->background_is_hidden) { + animator_->StartAnimationWithObserver( + internal::SessionStateAnimator::DESKTOP_BACKGROUND, + internal::SessionStateAnimator::ANIMATION_FADE_OUT, + speed, + observer); + } +} } // namespace ash diff --git a/ash/wm/lock_state_controller.h b/ash/wm/lock_state_controller.h index 10fce26..66c8ceb 100644 --- a/ash/wm/lock_state_controller.h +++ b/ash/wm/lock_state_controller.h @@ -28,7 +28,7 @@ class Layer; namespace ash { namespace test { -class LockStateControllerImpl2Test; +class LockStateControllerTest; class PowerButtonControllerTest; } @@ -47,6 +47,27 @@ class ASH_EXPORT LockStateControllerDelegate { // Displays onscreen animations and locks or suspends the system in response to // the power button being pressed or released. +// Lock workflow: +// Entry points: +// * StartLockAnimation (bool shutdown after lock) - starts lock that can be +// cancelled. +// * StartLockAnimationAndLockImmediately - starts uninterruptible lock +// animation. +// This leads to call of either StartImmediatePreLockAnimation or +// StartCancellablePreLockAnimation. Once they complete +// PreLockAnimationFinished is called, and system lock is requested. +// Once system locks and lock UI is created, OnLockStateChanged is called, and +// StartPostLockAnimation is called. In PostLockAnimationFinished two +// things happen : EVENT_LOCK_ANIMATION_FINISHED notification is sent (it +// triggers third part of animation within lock UI), and check for continuing to +// shutdown is made. +// +// Unlock workflow: +// WebUI does first part of animation, and calls OnLockScreenHide(callback) that +// triggers StartUnlockAnimationBeforeUIDestroyed(callback). Once callback is +// called at the end of the animation, lock UI is deleted, system unlocks, and +// OnLockStateChanged is called. It leads to +// StartUnlockAnimationAfterUIDestroyed. class ASH_EXPORT LockStateController : public aura::RootWindowObserver, public ShellObserver { public: @@ -71,65 +92,186 @@ class ASH_EXPORT LockStateController : public aura::RootWindowObserver, // the animation time to finish. static const int kShutdownRequestDelayMs; + // Helper class used by tests to access internal state. + class ASH_EXPORT TestApi { + public: + explicit TestApi(LockStateController* controller); + + virtual ~TestApi(); + + bool lock_fail_timer_is_running() const { + return controller_->lock_fail_timer_.IsRunning(); + } + bool lock_to_shutdown_timer_is_running() const { + return controller_->lock_to_shutdown_timer_.IsRunning(); + } + bool shutdown_timer_is_running() const { + return controller_->pre_shutdown_timer_.IsRunning(); + } + bool real_shutdown_timer_is_running() const { + return controller_->real_shutdown_timer_.IsRunning(); + } + bool is_animating_lock() const { + return controller_->animating_lock_; + } + bool is_lock_cancellable() const { + return controller_->CanCancelLockAnimation(); + } + + void trigger_lock_fail_timeout() { + controller_->OnLockFailTimeout(); + controller_->lock_fail_timer_.Stop(); + } + void trigger_lock_to_shutdown_timeout() { + controller_->OnLockToShutdownTimeout(); + controller_->lock_to_shutdown_timer_.Stop(); + } + void trigger_shutdown_timeout() { + controller_->OnPreShutdownAnimationTimeout(); + controller_->pre_shutdown_timer_.Stop(); + } + void trigger_real_shutdown_timeout() { + controller_->OnRealShutdownTimeout(); + controller_->real_shutdown_timer_.Stop(); + } + private: + LockStateController* controller_; // not owned + + DISALLOW_COPY_AND_ASSIGN(TestApi); + }; + LockStateController(); virtual ~LockStateController(); + // Takes ownership of |delegate|. void SetDelegate(LockStateControllerDelegate* delegate); + void AddObserver(LockStateObserver* observer); + void RemoveObserver(LockStateObserver* observer); + bool HasObserver(LockStateObserver* observer); + // Starts locking (with slow animation) that can be cancelled. // After locking and |kLockToShutdownTimeoutMs| StartShutdownAnimation() // will be called unless CancelShutdownAnimation() is called, if // |shutdown_after_lock| is true. - virtual void StartLockAnimation(bool shutdown_after_lock) = 0; + void StartLockAnimation(bool shutdown_after_lock); // Starts shutting down (with slow animation) that can be cancelled. - virtual void StartShutdownAnimation() = 0; + void StartShutdownAnimation(); // Starts usual lock animation, but locks immediately. // Unlike StartLockAnimation it does no lead to StartShutdownAnimation. - virtual void StartLockAnimationAndLockImmediately() = 0; + void StartLockAnimationAndLockImmediately(); // Returns true if we have requested system to lock, but haven't received // confirmation yet. - virtual bool LockRequested() = 0; + bool LockRequested(); // Returns true if we are shutting down. - virtual bool ShutdownRequested() = 0; + bool ShutdownRequested(); // Returns true if we are within cancellable lock timeframe. - virtual bool CanCancelLockAnimation() = 0; + bool CanCancelLockAnimation(); // Cancels locking and reverts lock animation. - virtual void CancelLockAnimation() = 0; + void CancelLockAnimation(); // Returns true if we are within cancellable shutdown timeframe. - virtual bool CanCancelShutdownAnimation() = 0; + bool CanCancelShutdownAnimation(); // Cancels shutting down and reverts shutdown animation. - virtual void CancelShutdownAnimation() = 0; + void CancelShutdownAnimation(); // Called when Chrome gets a request to display the lock screen. - virtual void OnStartingLock() = 0; + void OnStartingLock(); // Displays the shutdown animation and requests shutdown when it's done. - virtual void RequestShutdown() = 0; + void RequestShutdown(); // Called when ScreenLocker is ready to close, but not yet destroyed. // Can be used to display "hiding" animations on unlock. // |callback| will be called when all animations are done. - virtual void OnLockScreenHide(base::Closure& callback) = 0; + void OnLockScreenHide(base::Closure& callback); // Sets up the callback that should be called once lock animation is finished. // Callback is guaranteed to be called once and then discarded. - virtual void SetLockScreenDisplayedCallback(base::Closure& callback) = 0; + void SetLockScreenDisplayedCallback(base::Closure& callback); - virtual void AddObserver(LockStateObserver* observer); - virtual void RemoveObserver(LockStateObserver* observer); - virtual bool HasObserver(LockStateObserver* observer); + // RootWindowObserver override: + virtual void OnRootWindowHostCloseRequested( + const aura::RootWindow* root) OVERRIDE; - protected: + // ShellObserver overrides: + virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE; + virtual void OnAppTerminating() OVERRIDE; + virtual void OnLockStateChanged(bool locked) OVERRIDE; + + private: friend class test::PowerButtonControllerTest; - friend class test::LockStateControllerImpl2Test; + friend class test::LockStateControllerTest; + + struct UnlockedStateProperties { + bool background_is_hidden; + }; + + // Reverts the pre-lock animation, reports the error. + void OnLockFailTimeout(); + + // Starts timer for gap between lock and shutdown. + void StartLockToShutdownTimer(); + + // Calls StartShutdownAnimation(). + void OnLockToShutdownTimeout(); + + // Starts timer for undoable shutdown animation. + void StartPreShutdownAnimationTimer(); + + // Calls StartRealShutdownTimer(). + void OnPreShutdownAnimationTimeout(); + + // Starts timer for final shutdown animation. + // If |with_animation_time| is true, it will also include time of "fade to + // white" shutdown animation. + void StartRealShutdownTimer(bool with_animation_time); + + // Requests that the machine be shut down. + void OnRealShutdownTimeout(); + + // Starts shutdown animation that can be cancelled and starts pre-shutdown + // timer. + void StartCancellableShutdownAnimation(); + + // If |request_lock_on_completion| is true, a lock request will be sent + // after the pre-lock animation completes. (The pre-lock animation is + // also displayed in response to already-in-progress lock requests; in + // these cases an additional lock request is undesirable.) + void StartImmediatePreLockAnimation(bool request_lock_on_completion); + void StartCancellablePreLockAnimation(); + void CancelPreLockAnimation(); + void StartPostLockAnimation(); + // This method calls |callback| when animation completes. + void StartUnlockAnimationBeforeUIDestroyed(base::Closure &callback); + void StartUnlockAnimationAfterUIDestroyed(); + + // These methods are called when corresponding animation completes. + void LockAnimationCancelled(); + void PreLockAnimationFinished(bool request_lock); + void PostLockAnimationFinished(); + void UnlockAnimationAfterUIDestroyedFinished(); + + // Stores properties of UI that have to be temporarily modified while locking. + void StoreUnlockedProperties(); + void RestoreUnlockedProperties(); + + // Fades in background layer with |speed| if it was hidden in unlocked state. + void AnimateBackgroundAppearanceIfNecessary( + ash::internal::SessionStateAnimator::AnimationSpeed speed, + ui::LayerAnimationObserver* observer); + + // Fades out background layer with |speed| if it was hidden in unlocked state. + void AnimateBackgroundHidingIfNecessary( + ash::internal::SessionStateAnimator::AnimationSpeed speed, + ui::LayerAnimationObserver* observer); scoped_ptr<internal::SessionStateAnimator> animator_; @@ -137,7 +279,47 @@ class ASH_EXPORT LockStateController : public aura::RootWindowObserver, ObserverList<LockStateObserver> observers_; - private: + // The current login status, or original login status from before we locked. + user::LoginStatus login_status_; + + // Current lock status. + bool system_is_locked_; + + // Are we in the process of shutting the machine down? + bool shutting_down_; + + // Indicates whether controller should proceed to (cancellable) shutdown after + // locking. + bool shutdown_after_lock_; + + // Indicates that controller displays lock animation. + bool animating_lock_; + + // Indicates that lock animation can be undone. + bool can_cancel_lock_animation_; + + scoped_ptr<UnlockedStateProperties> unlocked_properties_; + + // Started when we request that the screen be locked. When it fires, we + // assume that our request got dropped. + base::OneShotTimer<LockStateController> lock_fail_timer_; + + // Started when the screen is locked while the power button is held. Adds a + // delay between the appearance of the lock screen and the beginning of the + // pre-shutdown animation. + base::OneShotTimer<LockStateController> lock_to_shutdown_timer_; + + // Started when we begin displaying the pre-shutdown animation. When it + // fires, we start the shutdown animation and get ready to request shutdown. + base::OneShotTimer<LockStateController> pre_shutdown_timer_; + + // Started when we display the shutdown animation. When it fires, we actually + // request shutdown. Gives the animation time to complete before Chrome, X, + // etc. are shut down. + base::OneShotTimer<LockStateController> real_shutdown_timer_; + + base::Closure lock_screen_displayed_callback_; + DISALLOW_COPY_AND_ASSIGN(LockStateController); }; diff --git a/ash/wm/lock_state_controller_impl2.cc b/ash/wm/lock_state_controller_impl2.cc deleted file mode 100644 index dae62c4..0000000 --- a/ash/wm/lock_state_controller_impl2.cc +++ /dev/null @@ -1,643 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/wm/lock_state_controller_impl2.h" - -#include "ash/ash_switches.h" -#include "ash/cancel_mode.h" -#include "ash/shell.h" -#include "ash/shell_delegate.h" -#include "ash/shell_window_ids.h" -#include "ash/wm/session_state_animator.h" -#include "base/bind_helpers.h" -#include "base/command_line.h" -#include "base/sys_info.h" -#include "base/timer/timer.h" -#include "ui/aura/root_window.h" -#include "ui/compositor/layer_animation_sequence.h" -#include "ui/compositor/scoped_layer_animation_settings.h" -#include "ui/views/corewm/compound_event_filter.h" - -namespace ash { - -namespace { - -aura::Window* GetBackground() { - aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); - return Shell::GetContainer(root_window, - internal::kShellWindowId_DesktopBackgroundContainer); -} - -bool IsBackgroundHidden() { - return !GetBackground()->IsVisible(); -} - -void ShowBackground() { - ui::ScopedLayerAnimationSettings settings( - GetBackground()->layer()->GetAnimator()); - settings.SetTransitionDuration(base::TimeDelta()); - GetBackground()->Show(); -} - -void HideBackground() { - ui::ScopedLayerAnimationSettings settings( - GetBackground()->layer()->GetAnimator()); - settings.SetTransitionDuration(base::TimeDelta()); - GetBackground()->Hide(); -} - -// This observer is intended to use in cases when some action has to be taken -// once some animation successfully completes (i.e. it was not aborted). -// Observer will count a number of sequences it is attached to, and a number of -// finished sequences (either Ended or Aborted). Once these two numbers are -// equal, observer will delete itself, calling callback passed to constructor if -// there were no aborted animations. -// This way it can be either used to wait for some animation to be finished in -// multiple layers, to wait once a sequence of animations is finished in one -// layer or the mixture of both. -class AnimationFinishedObserver : public ui::LayerAnimationObserver { - public: - explicit AnimationFinishedObserver(base::Closure &callback) - : callback_(callback), - sequences_attached_(0), - sequences_completed_(0), - paused_(false) { - } - - // Pauses observer: no checks will be made while paused. It can be used when - // a sequence has some immediate animations in the beginning, and for - // animations that can be tested with flag that makes all animations - // immediate. - void Pause() { - paused_ = true; - } - - // Unpauses observer. It does a check and calls callback if conditions are - // met. - void Unpause() { - if (!paused_) - return; - paused_ = false; - if (sequences_completed_ == sequences_attached_) { - callback_.Run(); - delete this; - } - } - - private: - virtual ~AnimationFinishedObserver() { - } - - // LayerAnimationObserver implementation - virtual void OnLayerAnimationEnded( - ui::LayerAnimationSequence* sequence) OVERRIDE { - sequences_completed_++; - if ((sequences_completed_ == sequences_attached_) && !paused_) { - callback_.Run(); - delete this; - } - } - - virtual void OnLayerAnimationAborted( - ui::LayerAnimationSequence* sequence) OVERRIDE { - sequences_completed_++; - if ((sequences_completed_ == sequences_attached_) && !paused_) - delete this; - } - - virtual void OnLayerAnimationScheduled( - ui::LayerAnimationSequence* sequence) OVERRIDE { - } - - virtual void OnAttachedToSequence( - ui::LayerAnimationSequence* sequence) OVERRIDE { - LayerAnimationObserver::OnAttachedToSequence(sequence); - sequences_attached_++; - } - - // Callback to be called. - base::Closure callback_; - - // Number of sequences this observer was attached to. - int sequences_attached_; - - // Number of sequences either ended or aborted. - int sequences_completed_; - - bool paused_; - - DISALLOW_COPY_AND_ASSIGN(AnimationFinishedObserver); -}; - -} // namespace - -LockStateControllerImpl2::TestApi::TestApi( - LockStateControllerImpl2* controller) - : controller_(controller) { -} - -LockStateControllerImpl2::TestApi::~TestApi() { -} - -LockStateControllerImpl2::LockStateControllerImpl2() - : login_status_(user::LOGGED_IN_NONE), - system_is_locked_(false), - shutting_down_(false), - shutdown_after_lock_(false), - animating_lock_(false), - can_cancel_lock_animation_(false) { - Shell::GetPrimaryRootWindow()->AddRootWindowObserver(this); -} - -LockStateControllerImpl2::~LockStateControllerImpl2() { - Shell::GetPrimaryRootWindow()->RemoveRootWindowObserver(this); -} - -void LockStateControllerImpl2::OnLoginStateChanged( - user::LoginStatus status) { - if (status != user::LOGGED_IN_LOCKED) - login_status_ = status; - system_is_locked_ = (status == user::LOGGED_IN_LOCKED); -} - -void LockStateControllerImpl2::OnAppTerminating() { - // If we hear that Chrome is exiting but didn't request it ourselves, all we - // can really hope for is that we'll have time to clear the screen. - // This is also the case when the user signs off. - if (!shutting_down_) { - shutting_down_ = true; - Shell* shell = ash::Shell::GetInstance(); - shell->env_filter()->set_cursor_hidden_by_filter(false); - shell->cursor_manager()->HideCursor(); - animator_->StartAnimation( - internal::SessionStateAnimator::kAllContainersMask, - internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, - internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); - } -} - -void LockStateControllerImpl2::OnLockStateChanged(bool locked) { - if (shutting_down_ || (system_is_locked_ == locked)) - return; - - system_is_locked_ = locked; - - if (locked) { - StartPostLockAnimation(); - lock_fail_timer_.Stop(); - } else { - StartUnlockAnimationAfterUIDestroyed(); - } -} - -void LockStateControllerImpl2::SetLockScreenDisplayedCallback( - base::Closure& callback) { - lock_screen_displayed_callback_ = callback; -} - -void LockStateControllerImpl2::OnStartingLock() { - if (shutting_down_ || system_is_locked_) - return; - if (animating_lock_) - return; - StartImmediatePreLockAnimation(false /* request_lock_on_completion */); -} - -void LockStateControllerImpl2::StartLockAnimationAndLockImmediately() { - if (animating_lock_) - return; - StartImmediatePreLockAnimation(true /* request_lock_on_completion */); -} - -void LockStateControllerImpl2::StartLockAnimation( - bool shutdown_after_lock) { - if (animating_lock_) - return; - shutdown_after_lock_ = shutdown_after_lock; - can_cancel_lock_animation_ = true; - - StartCancellablePreLockAnimation(); -} - -bool LockStateControllerImpl2::LockRequested() { - return lock_fail_timer_.IsRunning(); -} - -bool LockStateControllerImpl2::ShutdownRequested() { - return shutting_down_; -} - -bool LockStateControllerImpl2::CanCancelLockAnimation() { - return can_cancel_lock_animation_; -} - -void LockStateControllerImpl2::CancelLockAnimation() { - if (!CanCancelLockAnimation()) - return; - shutdown_after_lock_ = false; - animating_lock_ = false; - CancelPreLockAnimation(); -} - -bool LockStateControllerImpl2::CanCancelShutdownAnimation() { - return pre_shutdown_timer_.IsRunning() || - shutdown_after_lock_ || - lock_to_shutdown_timer_.IsRunning(); -} - -void LockStateControllerImpl2::StartShutdownAnimation() { - StartCancellableShutdownAnimation(); -} - -void LockStateControllerImpl2::CancelShutdownAnimation() { - if (!CanCancelShutdownAnimation()) - return; - if (lock_to_shutdown_timer_.IsRunning()) { - lock_to_shutdown_timer_.Stop(); - return; - } - if (shutdown_after_lock_) { - shutdown_after_lock_ = false; - return; - } - - animator_->StartGlobalAnimation( - internal::SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS, - internal::SessionStateAnimator::ANIMATION_SPEED_REVERT_SHUTDOWN); - pre_shutdown_timer_.Stop(); -} - -void LockStateControllerImpl2::RequestShutdown() { - if (!shutting_down_) - RequestShutdownImpl(); -} - -void LockStateControllerImpl2::RequestShutdownImpl() { - DCHECK(!shutting_down_); - shutting_down_ = true; - - Shell* shell = ash::Shell::GetInstance(); - shell->env_filter()->set_cursor_hidden_by_filter(false); - shell->cursor_manager()->HideCursor(); - - StartShutdownAnimationImpl(); -} - -void LockStateControllerImpl2::OnRootWindowHostCloseRequested( - const aura::RootWindow*) { - Shell::GetInstance()->delegate()->Exit(); -} - -void LockStateControllerImpl2::OnLockFailTimeout() { - DCHECK(!system_is_locked_); - // Undo lock animation. - StartUnlockAnimationAfterUIDestroyed(); -} - -void LockStateControllerImpl2::StartLockToShutdownTimer() { - shutdown_after_lock_ = false; - lock_to_shutdown_timer_.Stop(); - lock_to_shutdown_timer_.Start( - FROM_HERE, - base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), - this, &LockStateControllerImpl2::OnLockToShutdownTimeout); -} - -void LockStateControllerImpl2::OnLockToShutdownTimeout() { - DCHECK(system_is_locked_); - StartCancellableShutdownAnimation(); -} - -void LockStateControllerImpl2::StartCancellableShutdownAnimation() { - Shell* shell = ash::Shell::GetInstance(); - // Hide cursor, but let it reappear if the mouse moves. - shell->env_filter()->set_cursor_hidden_by_filter(true); - shell->cursor_manager()->HideCursor(); - - animator_->StartGlobalAnimation( - internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS, - internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); - StartPreShutdownAnimationTimer(); -} - -void LockStateControllerImpl2::StartShutdownAnimationImpl() { - animator_->StartGlobalAnimation( - internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS, - internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); - StartRealShutdownTimer(true); -} - -void LockStateControllerImpl2::StartPreShutdownAnimationTimer() { - pre_shutdown_timer_.Stop(); - pre_shutdown_timer_.Start( - FROM_HERE, - animator_-> - GetDuration(internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN), - this, - &LockStateControllerImpl2::OnPreShutdownAnimationTimeout); -} - -void LockStateControllerImpl2::OnPreShutdownAnimationTimeout() { - shutting_down_ = true; - - Shell* shell = ash::Shell::GetInstance(); - shell->env_filter()->set_cursor_hidden_by_filter(false); - shell->cursor_manager()->HideCursor(); - - StartRealShutdownTimer(false); -} - -void LockStateControllerImpl2::StartRealShutdownTimer( - bool with_animation_time) { - base::TimeDelta duration = - base::TimeDelta::FromMilliseconds(kShutdownRequestDelayMs); - if (with_animation_time) { - duration += animator_->GetDuration( - internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); - } - real_shutdown_timer_.Start( - FROM_HERE, - duration, - this, - &LockStateControllerImpl2::OnRealShutdownTimeout); -} - -void LockStateControllerImpl2::OnRealShutdownTimeout() { - DCHECK(shutting_down_); -#if defined(OS_CHROMEOS) - if (!base::SysInfo::IsRunningOnChromeOS()) { - ShellDelegate* delegate = Shell::GetInstance()->delegate(); - if (delegate) { - delegate->Exit(); - return; - } - } -#endif - Shell::GetInstance()->delegate()->RecordUserMetricsAction( - UMA_ACCEL_SHUT_DOWN_POWER_BUTTON); - delegate_->RequestShutdown(); -} - -void LockStateControllerImpl2::OnLockScreenHide( - base::Callback<void(void)>& callback) { - StartUnlockAnimationBeforeUIDestroyed(callback); -} - -void LockStateControllerImpl2::LockAnimationCancelled() { - can_cancel_lock_animation_ = false; - RestoreUnlockedProperties(); -} - -void LockStateControllerImpl2::PreLockAnimationFinished( - bool request_lock) { - can_cancel_lock_animation_ = false; - - if (request_lock) { - Shell::GetInstance()->delegate()->RecordUserMetricsAction( - shutdown_after_lock_ ? - UMA_ACCEL_LOCK_SCREEN_POWER_BUTTON : - UMA_ACCEL_LOCK_SCREEN_LOCK_BUTTON); - delegate_->RequestLockScreen(); - } - - lock_fail_timer_.Start( - FROM_HERE, - base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs), - this, - &LockStateControllerImpl2::OnLockFailTimeout); -} - -void LockStateControllerImpl2::PostLockAnimationFinished() { - animating_lock_ = false; - - FOR_EACH_OBSERVER(LockStateObserver, observers_, - OnLockStateEvent(LockStateObserver::EVENT_LOCK_ANIMATION_FINISHED)); - if (!lock_screen_displayed_callback_.is_null()) { - lock_screen_displayed_callback_.Run(); - lock_screen_displayed_callback_.Reset(); - } - if (shutdown_after_lock_) { - shutdown_after_lock_ = false; - StartLockToShutdownTimer(); - } -} - -void LockStateControllerImpl2:: -UnlockAnimationAfterUIDestroyedFinished() { - RestoreUnlockedProperties(); -} - -void LockStateControllerImpl2::StartImmediatePreLockAnimation( - bool request_lock_on_completion) { - animating_lock_ = true; - - StoreUnlockedProperties(); - - base::Closure next_animation_starter = - base::Bind(&LockStateControllerImpl2::PreLockAnimationFinished, - base::Unretained(this), request_lock_on_completion); - AnimationFinishedObserver* observer = - new AnimationFinishedObserver(next_animation_starter); - - observer->Pause(); - - animator_->StartAnimationWithObserver( - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_LIFT, - internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, - observer); - animator_->StartAnimationWithObserver( - internal::SessionStateAnimator::LAUNCHER, - internal::SessionStateAnimator::ANIMATION_FADE_OUT, - internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, - observer); - // Hide the screen locker containers so we can raise them later. - animator_->StartAnimation( - internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, - internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); - AnimateBackgroundAppearanceIfNecessary( - internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, - observer); - - observer->Unpause(); - - DispatchCancelMode(); - FOR_EACH_OBSERVER(LockStateObserver, observers_, - OnLockStateEvent(LockStateObserver::EVENT_LOCK_ANIMATION_STARTED)); -} - -void LockStateControllerImpl2::StartCancellablePreLockAnimation() { - animating_lock_ = true; - StoreUnlockedProperties(); - - base::Closure next_animation_starter = - base::Bind(&LockStateControllerImpl2::PreLockAnimationFinished, - base::Unretained(this), true /* request_lock */); - AnimationFinishedObserver* observer = - new AnimationFinishedObserver(next_animation_starter); - - observer->Pause(); - - animator_->StartAnimationWithObserver( - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_LIFT, - internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, - observer); - animator_->StartAnimationWithObserver( - internal::SessionStateAnimator::LAUNCHER, - internal::SessionStateAnimator::ANIMATION_FADE_OUT, - internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, - observer); - // Hide the screen locker containers so we can raise them later. - animator_->StartAnimation( - internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, - internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); - AnimateBackgroundAppearanceIfNecessary( - internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, - observer); - - DispatchCancelMode(); - FOR_EACH_OBSERVER(LockStateObserver, observers_, - OnLockStateEvent(LockStateObserver::EVENT_PRELOCK_ANIMATION_STARTED)); - observer->Unpause(); -} - -void LockStateControllerImpl2::CancelPreLockAnimation() { - base::Closure next_animation_starter = - base::Bind(&LockStateControllerImpl2::LockAnimationCancelled, - base::Unretained(this)); - AnimationFinishedObserver* observer = - new AnimationFinishedObserver(next_animation_starter); - - observer->Pause(); - - animator_->StartAnimationWithObserver( - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_UNDO_LIFT, - internal::SessionStateAnimator::ANIMATION_SPEED_UNDO_MOVE_WINDOWS, - observer); - animator_->StartAnimationWithObserver( - internal::SessionStateAnimator::LAUNCHER, - internal::SessionStateAnimator::ANIMATION_FADE_IN, - internal::SessionStateAnimator::ANIMATION_SPEED_UNDO_MOVE_WINDOWS, - observer); - AnimateBackgroundHidingIfNecessary( - internal::SessionStateAnimator::ANIMATION_SPEED_UNDO_MOVE_WINDOWS, - observer); - - observer->Unpause(); -} - -void LockStateControllerImpl2::StartPostLockAnimation() { - base::Closure next_animation_starter = - base::Bind(&LockStateControllerImpl2::PostLockAnimationFinished, - base::Unretained(this)); - - AnimationFinishedObserver* observer = - new AnimationFinishedObserver(next_animation_starter); - - observer->Pause(); - animator_->StartAnimationWithObserver( - internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN, - internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, - observer); - observer->Unpause(); -} - -void LockStateControllerImpl2::StartUnlockAnimationBeforeUIDestroyed( - base::Closure& callback) { - animator_->StartAnimationWithCallback( - internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_LIFT, - internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, - callback); -} - -void LockStateControllerImpl2::StartUnlockAnimationAfterUIDestroyed() { - base::Closure next_animation_starter = - base::Bind( - &LockStateControllerImpl2:: - UnlockAnimationAfterUIDestroyedFinished, - base::Unretained(this)); - - AnimationFinishedObserver* observer = - new AnimationFinishedObserver(next_animation_starter); - - observer->Pause(); - - animator_->StartAnimationWithObserver( - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_DROP, - internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, - observer); - animator_->StartAnimationWithObserver( - internal::SessionStateAnimator::LAUNCHER, - internal::SessionStateAnimator::ANIMATION_FADE_IN, - internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, - observer); - AnimateBackgroundHidingIfNecessary( - internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, - observer); - observer->Unpause(); -} - -void LockStateControllerImpl2::StoreUnlockedProperties() { - if (!unlocked_properties_) { - unlocked_properties_.reset(new UnlockedStateProperties()); - unlocked_properties_->background_is_hidden = IsBackgroundHidden(); - } - if (unlocked_properties_->background_is_hidden) { - // Hide background so that it can be animated later. - animator_->StartAnimation( - internal::SessionStateAnimator::DESKTOP_BACKGROUND, - internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, - internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); - ShowBackground(); - } -} - -void LockStateControllerImpl2::RestoreUnlockedProperties() { - if (!unlocked_properties_) - return; - if (unlocked_properties_->background_is_hidden) { - HideBackground(); - // Restore background visibility. - animator_->StartAnimation( - internal::SessionStateAnimator::DESKTOP_BACKGROUND, - internal::SessionStateAnimator::ANIMATION_FADE_IN, - internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); - } - unlocked_properties_.reset(); -} - -void LockStateControllerImpl2::AnimateBackgroundAppearanceIfNecessary( - internal::SessionStateAnimator::AnimationSpeed speed, - ui::LayerAnimationObserver* observer) { - if (unlocked_properties_.get() && - unlocked_properties_->background_is_hidden) { - animator_->StartAnimationWithObserver( - internal::SessionStateAnimator::DESKTOP_BACKGROUND, - internal::SessionStateAnimator::ANIMATION_FADE_IN, - speed, - observer); - } -} - -void LockStateControllerImpl2::AnimateBackgroundHidingIfNecessary( - internal::SessionStateAnimator::AnimationSpeed speed, - ui::LayerAnimationObserver* observer) { - if (unlocked_properties_.get() && - unlocked_properties_->background_is_hidden) { - animator_->StartAnimationWithObserver( - internal::SessionStateAnimator::DESKTOP_BACKGROUND, - internal::SessionStateAnimator::ANIMATION_FADE_OUT, - speed, - observer); - } -} - -} // namespace ash diff --git a/ash/wm/lock_state_controller_impl2.h b/ash/wm/lock_state_controller_impl2.h deleted file mode 100644 index 8908a7e..0000000 --- a/ash/wm/lock_state_controller_impl2.h +++ /dev/null @@ -1,263 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_WM_LOCK_STATE_CONTROLLER_IMPL2_H_ -#define ASH_WM_LOCK_STATE_CONTROLLER_IMPL2_H_ - -#include "ash/ash_export.h" -#include "ash/shell_observer.h" -#include "ash/wm/lock_state_controller.h" -#include "ash/wm/session_state_animator.h" -#include "base/basictypes.h" -#include "base/memory/scoped_ptr.h" -#include "base/time/time.h" -#include "base/timer/timer.h" -#include "ui/aura/root_window_observer.h" - -namespace gfx { -class Rect; -class Size; -} - -namespace ui { -class Layer; -} - -namespace ash { - -namespace test { -class LockStateControllerImpl2Test; -} - -// Displays onscreen animations and locks or suspends the system in response to -// the power button being pressed or released. -// Lock workflow: -// Entry points: -// * StartLockAnimation (bool shutdown after lock) - starts lock that can be -// cancelled. -// * StartLockAnimationAndLockImmediately - starts uninterruptible lock -// animation. -// This leads to call of either StartImmediatePreLockAnimation or -// StartCancellablePreLockAnimation. Once they complete -// PreLockAnimationFinished is called, and system lock is requested. -// Once system locks and lock UI is created, OnLockStateChanged is called, and -// StartPostLockAnimation is called. In PostLockAnimationFinished two -// things happen : EVENT_LOCK_ANIMATION_FINISHED notification is sent (it -// triggers third part of animation within lock UI), and check for continuing to -// shutdown is made. -// -// Unlock workflow: -// WebUI does first part of animation, and calls OnLockScreenHide(callback) that -// triggers StartUnlockAnimationBeforeUIDestroyed(callback). Once callback is -// called at the end of the animation, lock UI is deleted, system unlocks, and -// OnLockStateChanged is called. It leads to -// StartUnlockAnimationAfterUIDestroyed. - -class ASH_EXPORT LockStateControllerImpl2 : public LockStateController { - public: - - // Helper class used by tests to access internal state. - class ASH_EXPORT TestApi { - public: - explicit TestApi(LockStateControllerImpl2* controller); - - virtual ~TestApi(); - - bool lock_fail_timer_is_running() const { - return controller_->lock_fail_timer_.IsRunning(); - } - bool lock_to_shutdown_timer_is_running() const { - return controller_->lock_to_shutdown_timer_.IsRunning(); - } - bool shutdown_timer_is_running() const { - return controller_->pre_shutdown_timer_.IsRunning(); - } - bool real_shutdown_timer_is_running() const { - return controller_->real_shutdown_timer_.IsRunning(); - } - bool is_animating_lock() const { - return controller_->animating_lock_; - } - bool is_lock_cancellable() const { - return controller_->CanCancelLockAnimation(); - } - - void trigger_lock_fail_timeout() { - controller_->OnLockFailTimeout(); - controller_->lock_fail_timer_.Stop(); - } - void trigger_lock_to_shutdown_timeout() { - controller_->OnLockToShutdownTimeout(); - controller_->lock_to_shutdown_timer_.Stop(); - } - void trigger_shutdown_timeout() { - controller_->OnPreShutdownAnimationTimeout(); - controller_->pre_shutdown_timer_.Stop(); - } - void trigger_real_shutdown_timeout() { - controller_->OnRealShutdownTimeout(); - controller_->real_shutdown_timer_.Stop(); - } - private: - LockStateControllerImpl2* controller_; // not owned - - DISALLOW_COPY_AND_ASSIGN(TestApi); - }; - - LockStateControllerImpl2(); - virtual ~LockStateControllerImpl2(); - - // RootWindowObserver override: - virtual void OnRootWindowHostCloseRequested( - const aura::RootWindow* root) OVERRIDE; - - // ShellObserver overrides: - virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE; - virtual void OnAppTerminating() OVERRIDE; - virtual void OnLockStateChanged(bool locked) OVERRIDE; - - // LockStateController overrides: - virtual void StartLockAnimation(bool shutdown_after_lock) OVERRIDE; - - virtual void StartShutdownAnimation() OVERRIDE; - virtual void StartLockAnimationAndLockImmediately() OVERRIDE; - - virtual bool LockRequested() OVERRIDE; - virtual bool ShutdownRequested() OVERRIDE; - - virtual bool CanCancelLockAnimation() OVERRIDE; - virtual void CancelLockAnimation() OVERRIDE; - - virtual bool CanCancelShutdownAnimation() OVERRIDE; - virtual void CancelShutdownAnimation() OVERRIDE; - - virtual void OnStartingLock() OVERRIDE; - virtual void RequestShutdown() OVERRIDE; - - virtual void OnLockScreenHide(base::Closure& callback) OVERRIDE; - virtual void SetLockScreenDisplayedCallback(base::Closure& callback) OVERRIDE; - - protected: - friend class test::LockStateControllerImpl2Test; - - private: - struct UnlockedStateProperties { - bool background_is_hidden; - }; - - void RequestShutdownImpl(); - - // Reverts the pre-lock animation, reports the error. - void OnLockFailTimeout(); - - // Starts timer for gap between lock and shutdown. - void StartLockToShutdownTimer(); - - // Calls StartShutdownAnimation(). - void OnLockToShutdownTimeout(); - - // Starts timer for undoable shutdown animation. - void StartPreShutdownAnimationTimer(); - - // Calls RequestShutdownImpl(); - void OnPreShutdownAnimationTimeout(); - - // Starts timer for final shutdown animation. - // If |with_animation_time| is true, it will also include time of "fade to - // white" shutdown animation. - void StartRealShutdownTimer(bool with_animation_time); - - // Requests that the machine be shut down. - void OnRealShutdownTimeout(); - - // Starts shutdown animation that can be cancelled and starts pre-shutdown - // timer. - void StartCancellableShutdownAnimation(); - - // Starts non-cancellable animation and starts real shutdown timer that - // includes animation time. - void StartShutdownAnimationImpl(); - - // Triggers late animations on the lock screen. - void OnLockScreenAnimationFinished(); - - // If |request_lock_on_completion| is true, a lock request will be sent - // after the pre-lock animation completes. (The pre-lock animation is - // also displayed in response to already-in-progress lock requests; in - // these cases an additional lock request is undesirable.) - void StartImmediatePreLockAnimation(bool request_lock_on_completion); - void StartCancellablePreLockAnimation(); - void CancelPreLockAnimation(); - void StartPostLockAnimation(); - // This method calls |callback| when animation completes. - void StartUnlockAnimationBeforeUIDestroyed(base::Closure &callback); - void StartUnlockAnimationAfterUIDestroyed(); - - // These methods are called when corresponding animation completes. - void LockAnimationCancelled(); - void PreLockAnimationFinished(bool request_lock); - void PostLockAnimationFinished(); - void UnlockAnimationAfterUIDestroyedFinished(); - - // Stores properties of UI that have to be temporarily modified while locking. - void StoreUnlockedProperties(); - void RestoreUnlockedProperties(); - - // Fades in background layer with |speed| if it was hidden in unlocked state. - void AnimateBackgroundAppearanceIfNecessary( - ash::internal::SessionStateAnimator::AnimationSpeed speed, - ui::LayerAnimationObserver* observer); - - // Fades out background layer with |speed| if it was hidden in unlocked state. - void AnimateBackgroundHidingIfNecessary( - ash::internal::SessionStateAnimator::AnimationSpeed speed, - ui::LayerAnimationObserver* observer); - - // The current login status, or original login status from before we locked. - user::LoginStatus login_status_; - - // Current lock status. - bool system_is_locked_; - - // Are we in the process of shutting the machine down? - bool shutting_down_; - - // Indicates whether controller should proceed to (cancellable) shutdown after - // locking. - bool shutdown_after_lock_; - - // Indicates that controller displays lock animation. - bool animating_lock_; - - // Indicates that lock animation can be undone. - bool can_cancel_lock_animation_; - - scoped_ptr<UnlockedStateProperties> unlocked_properties_; - - // Started when we request that the screen be locked. When it fires, we - // assume that our request got dropped. - base::OneShotTimer<LockStateControllerImpl2> lock_fail_timer_; - - // Started when the screen is locked while the power button is held. Adds a - // delay between the appearance of the lock screen and the beginning of the - // pre-shutdown animation. - base::OneShotTimer<LockStateControllerImpl2> lock_to_shutdown_timer_; - - // Started when we begin displaying the pre-shutdown animation. When it - // fires, we start the shutdown animation and get ready to request shutdown. - base::OneShotTimer<LockStateControllerImpl2> pre_shutdown_timer_; - - // Started when we display the shutdown animation. When it fires, we actually - // request shutdown. Gives the animation time to complete before Chrome, X, - // etc. are shut down. - base::OneShotTimer<LockStateControllerImpl2> real_shutdown_timer_; - - base::Closure lock_screen_displayed_callback_; - - DISALLOW_COPY_AND_ASSIGN(LockStateControllerImpl2); -}; - -} // namespace ash - -#endif // ASH_WM_LOCK_STATE_CONTROLLER_IMPL2_H_ diff --git a/ash/wm/lock_state_controller_impl2_unittest.cc b/ash/wm/lock_state_controller_unittest.cc index 62bed7c..001a5f72 100644 --- a/ash/wm/lock_state_controller_impl2_unittest.cc +++ b/ash/wm/lock_state_controller_unittest.cc @@ -2,14 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "ash/wm/lock_state_controller.h" + #include "ash/ash_switches.h" #include "ash/session_state_delegate.h" #include "ash/shell.h" #include "ash/shell_window_ids.h" #include "ash/test/ash_test_base.h" #include "ash/test/test_shell_delegate.h" -#include "ash/wm/lock_state_controller.h" -#include "ash/wm/lock_state_controller_impl2.h" #include "ash/wm/power_button_controller.h" #include "ash/wm/session_state_animator.h" #include "base/command_line.h" @@ -99,15 +99,12 @@ class TestLockStateControllerDelegate : public LockStateControllerDelegate { DISALLOW_COPY_AND_ASSIGN(TestLockStateControllerDelegate); }; -class LockStateControllerImpl2Test : public AshTestBase { +class LockStateControllerTest : public AshTestBase { public: - LockStateControllerImpl2Test() : controller_(NULL), delegate_(NULL) {} - virtual ~LockStateControllerImpl2Test() {} + LockStateControllerTest() : controller_(NULL), delegate_(NULL) {} + virtual ~LockStateControllerTest() {} virtual void SetUp() OVERRIDE { - CHECK(!CommandLine::ForCurrentProcess()->HasSwitch( - ash::switches::kAshDisableNewLockAnimations)); - AshTestBase::SetUp(); // We would control animations in a fine way: @@ -125,11 +122,10 @@ class LockStateControllerImpl2Test : public AshTestBase { delegate_ = new TestLockStateControllerDelegate; controller_ = Shell::GetInstance()->power_button_controller(); - lock_state_controller_ = static_cast<LockStateControllerImpl2*>( + lock_state_controller_ = static_cast<LockStateController*>( Shell::GetInstance()->lock_state_controller()); lock_state_controller_->SetDelegate(delegate_); // transfers ownership - test_api_.reset( - new LockStateControllerImpl2::TestApi(lock_state_controller_)); + test_api_.reset(new LockStateController::TestApi(lock_state_controller_)); animator_api_.reset( new SessionStateAnimator::TestApi(lock_state_controller_-> animator_.get())); @@ -395,19 +391,19 @@ class LockStateControllerImpl2Test : public AshTestBase { } PowerButtonController* controller_; // not owned - LockStateControllerImpl2* lock_state_controller_; // not owned + LockStateController* lock_state_controller_; // not owned TestLockStateControllerDelegate* delegate_; // not owned TestShellDelegate* shell_delegate_; // not owned SessionStateDelegate* session_state_delegate_; // not owned scoped_ptr<ui::ScopedAnimationDurationScaleMode> animation_duration_mode_; - scoped_ptr<LockStateControllerImpl2::TestApi> test_api_; + scoped_ptr<LockStateController::TestApi> test_api_; scoped_ptr<SessionStateAnimator::TestApi> animator_api_; // TODO(antrim) : restore // scoped_ptr<ui::test::AnimationContainerTestHelper> animator_helper_; private: - DISALLOW_COPY_AND_ASSIGN(LockStateControllerImpl2Test); + DISALLOW_COPY_AND_ASSIGN(LockStateControllerTest); }; // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't @@ -415,7 +411,7 @@ class LockStateControllerImpl2Test : public AshTestBase { // time the button is pressed and shut down when it's pressed from the locked // state. // TODO(antrim): Reenable this: http://crbug.com/167048 -TEST_F(LockStateControllerImpl2Test, DISABLED_LegacyLockAndShutDown) { +TEST_F(LockStateControllerTest, DISABLED_LegacyLockAndShutDown) { Initialize(true, user::LOGGED_IN_USER); ExpectUnlockedState(); @@ -468,7 +464,7 @@ TEST_F(LockStateControllerImpl2Test, DISABLED_LegacyLockAndShutDown) { // Test that we start shutting down immediately if the power button is pressed // while we're not logged in on an unofficial system. -TEST_F(LockStateControllerImpl2Test, LegacyNotLoggedIn) { +TEST_F(LockStateControllerTest, LegacyNotLoggedIn) { Initialize(true, user::LOGGED_IN_NONE); PressPowerButton(); @@ -479,7 +475,7 @@ TEST_F(LockStateControllerImpl2Test, LegacyNotLoggedIn) { // Test that we start shutting down immediately if the power button is pressed // while we're logged in as a guest on an unofficial system. -TEST_F(LockStateControllerImpl2Test, LegacyGuest) { +TEST_F(LockStateControllerTest, LegacyGuest) { Initialize(true, user::LOGGED_IN_GUEST); PressPowerButton(); @@ -490,7 +486,7 @@ TEST_F(LockStateControllerImpl2Test, LegacyGuest) { // When we hold the power button while the user isn't logged in, we should shut // down the machine directly. -TEST_F(LockStateControllerImpl2Test, ShutdownWhenNotLoggedIn) { +TEST_F(LockStateControllerTest, ShutdownWhenNotLoggedIn) { Initialize(false, user::LOGGED_IN_NONE); // Press the power button and check that we start the shutdown timer. @@ -530,7 +526,7 @@ TEST_F(LockStateControllerImpl2Test, ShutdownWhenNotLoggedIn) { // Test that we lock the screen and deal with unlocking correctly. // TODO(antrim): Reenable this: http://crbug.com/167048 -TEST_F(LockStateControllerImpl2Test, DISABLED_LockAndUnlock) { +TEST_F(LockStateControllerTest, DISABLED_LockAndUnlock) { Initialize(false, user::LOGGED_IN_USER); ExpectUnlockedState(); @@ -590,7 +586,7 @@ TEST_F(LockStateControllerImpl2Test, DISABLED_LockAndUnlock) { // Test that we deal with cancelling lock correctly. // TODO(antrim): Reenable this: http://crbug.com/167048 -TEST_F(LockStateControllerImpl2Test, DISABLED_LockAndCancel) { +TEST_F(LockStateControllerTest, DISABLED_LockAndCancel) { Initialize(false, user::LOGGED_IN_USER); ExpectUnlockedState(); @@ -627,7 +623,7 @@ TEST_F(LockStateControllerImpl2Test, DISABLED_LockAndCancel) { // Test that we deal with cancelling lock correctly. // TODO(antrim): Reenable this: http://crbug.com/167048 -TEST_F(LockStateControllerImpl2Test, +TEST_F(LockStateControllerTest, DISABLED_LockAndCancelAndLockAgain) { Initialize(false, user::LOGGED_IN_USER); @@ -665,7 +661,7 @@ TEST_F(LockStateControllerImpl2Test, // Hold the power button down from the unlocked state to eventual shutdown. // TODO(antrim): Reenable this: http://crbug.com/167048 -TEST_F(LockStateControllerImpl2Test, DISABLED_LockToShutdown) { +TEST_F(LockStateControllerTest, DISABLED_LockToShutdown) { Initialize(false, user::LOGGED_IN_USER); // Hold the power button and lock the screen. @@ -698,7 +694,7 @@ TEST_F(LockStateControllerImpl2Test, DISABLED_LockToShutdown) { // Hold the power button down from the unlocked state to eventual shutdown, // then release the button while system does locking. -TEST_F(LockStateControllerImpl2Test, CancelLockToShutdown) { +TEST_F(LockStateControllerTest, CancelLockToShutdown) { Initialize(false, user::LOGGED_IN_USER); PressPowerButton(); @@ -722,7 +718,7 @@ TEST_F(LockStateControllerImpl2Test, CancelLockToShutdown) { // Test that we handle the case where lock requests are ignored. // TODO(antrim): Reenable this: http://crbug.com/167048 -TEST_F(LockStateControllerImpl2Test, DISABLED_Lock) { +TEST_F(LockStateControllerTest, DISABLED_Lock) { // We require animations to have a duration for this test. ui::ScopedAnimationDurationScaleMode normal_duration_mode( ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); @@ -751,7 +747,7 @@ TEST_F(LockStateControllerImpl2Test, DISABLED_Lock) { } // Test the basic operation of the lock button (not logged in). -TEST_F(LockStateControllerImpl2Test, LockButtonBasicNotLoggedIn) { +TEST_F(LockStateControllerTest, LockButtonBasicNotLoggedIn) { // The lock button shouldn't do anything if we aren't logged in. Initialize(false, user::LOGGED_IN_NONE); @@ -762,7 +758,7 @@ TEST_F(LockStateControllerImpl2Test, LockButtonBasicNotLoggedIn) { } // Test the basic operation of the lock button (guest). -TEST_F(LockStateControllerImpl2Test, LockButtonBasicGuest) { +TEST_F(LockStateControllerTest, LockButtonBasicGuest) { // The lock button shouldn't do anything when we're logged in as a guest. Initialize(false, user::LOGGED_IN_GUEST); @@ -774,7 +770,7 @@ TEST_F(LockStateControllerImpl2Test, LockButtonBasicGuest) { // Test the basic operation of the lock button. // TODO(antrim): Reenable this: http://crbug.com/167048 -TEST_F(LockStateControllerImpl2Test, DISABLED_LockButtonBasic) { +TEST_F(LockStateControllerTest, DISABLED_LockButtonBasic) { // If we're logged in as a regular user, we should start the lock timer and // the pre-lock animation. Initialize(false, user::LOGGED_IN_USER); @@ -823,7 +819,7 @@ TEST_F(LockStateControllerImpl2Test, DISABLED_LockButtonBasic) { // Test that the power button takes priority over the lock button. // TODO(antrim): Reenable this: http://crbug.com/167048 -TEST_F(LockStateControllerImpl2Test, +TEST_F(LockStateControllerTest, DISABLED_PowerButtonPreemptsLockButton) { Initialize(false, user::LOGGED_IN_USER); @@ -862,7 +858,7 @@ TEST_F(LockStateControllerImpl2Test, // When the screen is locked without going through the usual power-button // slow-close path (e.g. via the wrench menu), test that we still show the // fast-close animation. -TEST_F(LockStateControllerImpl2Test, LockWithoutButton) { +TEST_F(LockStateControllerTest, LockWithoutButton) { Initialize(false, user::LOGGED_IN_USER); lock_state_controller_->OnStartingLock(); @@ -876,7 +872,7 @@ TEST_F(LockStateControllerImpl2Test, LockWithoutButton) { // When we hear that the process is exiting but we haven't had a chance to // display an animation, we should just blank the screen. -TEST_F(LockStateControllerImpl2Test, ShutdownWithoutButton) { +TEST_F(LockStateControllerTest, ShutdownWithoutButton) { Initialize(false, user::LOGGED_IN_USER); lock_state_controller_->OnAppTerminating(); @@ -890,7 +886,7 @@ TEST_F(LockStateControllerImpl2Test, ShutdownWithoutButton) { // Test that we display the fast-close animation and shut down when we get an // outside request to shut down (e.g. from the login or lock screen). -TEST_F(LockStateControllerImpl2Test, RequestShutdownFromLoginScreen) { +TEST_F(LockStateControllerTest, RequestShutdownFromLoginScreen) { Initialize(false, user::LOGGED_IN_NONE); lock_state_controller_->RequestShutdown(); @@ -907,7 +903,7 @@ TEST_F(LockStateControllerImpl2Test, RequestShutdownFromLoginScreen) { EXPECT_EQ(1, NumShutdownRequests()); } -TEST_F(LockStateControllerImpl2Test, RequestShutdownFromLockScreen) { +TEST_F(LockStateControllerTest, RequestShutdownFromLockScreen) { Initialize(false, user::LOGGED_IN_USER); SystemLocks(); @@ -929,7 +925,7 @@ TEST_F(LockStateControllerImpl2Test, RequestShutdownFromLockScreen) { } // TODO(antrim): Reenable this: http://crbug.com/167048 -TEST_F(LockStateControllerImpl2Test, +TEST_F(LockStateControllerTest, DISABLED_RequestAndCancelShutdownFromLockScreen) { Initialize(false, user::LOGGED_IN_USER); @@ -966,7 +962,7 @@ TEST_F(LockStateControllerImpl2Test, } // Test that we ignore power button presses when the screen is turned off. -TEST_F(LockStateControllerImpl2Test, IgnorePowerButtonIfScreenIsOff) { +TEST_F(LockStateControllerTest, IgnorePowerButtonIfScreenIsOff) { Initialize(false, user::LOGGED_IN_USER); // When the screen brightness is at 0%, we shouldn't do anything in response @@ -987,8 +983,7 @@ TEST_F(LockStateControllerImpl2Test, IgnorePowerButtonIfScreenIsOff) { // Test that hidden background appears and revers correctly on lock/cancel. // TODO(antrim): Reenable this: http://crbug.com/167048 -TEST_F(LockStateControllerImpl2Test, - DISABLED_TestHiddenBackgroundLockCancel) { +TEST_F(LockStateControllerTest, DISABLED_TestHiddenBackgroundLockCancel) { Initialize(false, user::LOGGED_IN_USER); HideBackground(); @@ -1017,8 +1012,7 @@ TEST_F(LockStateControllerImpl2Test, // Test that hidden background appears and revers correctly on lock/unlock. // TODO(antrim): Reenable this: http://crbug.com/167048 -TEST_F(LockStateControllerImpl2Test, - DISABLED_TestHiddenBackgroundLockUnlock) { +TEST_F(LockStateControllerTest, DISABLED_TestHiddenBackgroundLockUnlock) { Initialize(false, user::LOGGED_IN_USER); HideBackground(); diff --git a/ash/wm/power_button_controller_unittest.cc b/ash/wm/power_button_controller_unittest.cc deleted file mode 100644 index e1ce71b..0000000 --- a/ash/wm/power_button_controller_unittest.cc +++ /dev/null @@ -1,637 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/ash_switches.h" -#include "ash/session_state_delegate.h" -#include "ash/shell.h" -#include "ash/test/ash_test_base.h" -#include "ash/test/test_shell_delegate.h" -#include "ash/wm/lock_state_controller.h" -#include "ash/wm/power_button_controller.h" -#include "ash/wm/session_state_animator.h" -#include "ash/wm/session_state_controller_impl.h" -#include "base/command_line.h" -#include "base/memory/scoped_ptr.h" -#include "base/time/time.h" -#include "ui/aura/env.h" -#include "ui/aura/root_window.h" -#include "ui/aura/test/event_generator.h" -#include "ui/compositor/scoped_animation_duration_scale_mode.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/size.h" - -namespace ash { -namespace test { -namespace { -bool cursor_visible() { - return ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible(); -} -} - -// Fake implementation of PowerButtonControllerDelegate that just logs requests -// to lock the screen and shut down the device. -class TestPowerButtonControllerDelegate : - public LockStateControllerDelegate { - public: - TestPowerButtonControllerDelegate() - : num_lock_requests_(0), - num_shutdown_requests_(0) {} - - int num_lock_requests() const { return num_lock_requests_; } - int num_shutdown_requests() const { return num_shutdown_requests_; } - - // PowerButtonControllerDelegate implementation. - virtual void RequestLockScreen() OVERRIDE { - num_lock_requests_++; - } - virtual void RequestShutdown() OVERRIDE { - num_shutdown_requests_++; - } - - private: - int num_lock_requests_; - int num_shutdown_requests_; - - DISALLOW_COPY_AND_ASSIGN(TestPowerButtonControllerDelegate); -}; - -class PowerButtonControllerTest : public AshTestBase { - public: - PowerButtonControllerTest() : controller_(NULL), delegate_(NULL) {} - virtual ~PowerButtonControllerTest() {} - - virtual void SetUp() OVERRIDE { - CommandLine::ForCurrentProcess()->AppendSwitch( - ash::switches::kAshDisableNewLockAnimations); - - AshTestBase::SetUp(); - delegate_ = new TestPowerButtonControllerDelegate; - controller_ = Shell::GetInstance()->power_button_controller(); - lock_state_controller_ = static_cast<SessionStateControllerImpl*>( - Shell::GetInstance()->lock_state_controller()); - lock_state_controller_->SetDelegate(delegate_); // transfers ownership - test_api_.reset(new SessionStateControllerImpl::TestApi( - lock_state_controller_)); - animator_api_.reset(new internal::SessionStateAnimator::TestApi( - lock_state_controller_->animator_.get())); - shell_delegate_ = reinterpret_cast<TestShellDelegate*>( - ash::Shell::GetInstance()->delegate()); - state_delegate_ = Shell::GetInstance()->session_state_delegate(); - } - - protected: - void GenerateMouseMoveEvent() { - aura::test::EventGenerator generator( - Shell::GetPrimaryRootWindow()); - generator.MoveMouseTo(10, 10); - } - - int NumShutdownRequests() { - return delegate_->num_shutdown_requests() + - shell_delegate_->num_exit_requests(); - } - - PowerButtonController* controller_; // not owned - SessionStateControllerImpl* lock_state_controller_; // not owned - TestPowerButtonControllerDelegate* delegate_; // not owned - TestShellDelegate* shell_delegate_; // not owned - SessionStateDelegate* state_delegate_; // not owned - - scoped_ptr<SessionStateControllerImpl::TestApi> test_api_; - scoped_ptr<internal::SessionStateAnimator::TestApi> animator_api_; - - private: - DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerTest); -}; - -// Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't -// correctly report power button releases. We should lock immediately the first -// time the button is pressed and shut down when it's pressed from the locked -// state. -TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) { - controller_->set_has_legacy_power_button_for_test(true); - lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); - lock_state_controller_->OnLockStateChanged(false); - - // We should request that the screen be locked immediately after seeing the - // power button get pressed. - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); - EXPECT_FALSE(test_api_->lock_timer_is_running()); - EXPECT_EQ(1, delegate_->num_lock_requests()); - - // Notify that we locked successfully. - lock_state_controller_->OnStartingLock(); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::LAUNCHER, - internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); - - // Notify that the lock window is visible. We should make it fade in. - lock_state_controller_->OnLockStateChanged(true); - state_delegate_->LockScreen(); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::kAllLockScreenContainersMask, - internal::SessionStateAnimator::ANIMATION_FADE_IN)); - - // We shouldn't progress towards the shutdown state, however. - EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); - EXPECT_FALSE(test_api_->shutdown_timer_is_running()); - controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); - - // Hold the button again and check that we start shutting down. - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); - EXPECT_EQ(0, NumShutdownRequests()); - - // Previously we're checking that the all containers group was animated which - // was in fact checking that - // 1. All user session containers have transform (including wallpaper). - // They're in this state after lock. - // 2. Screen locker and related containers are in fact animating - // (as shutdown is in progress). - // With http://crbug.com/144737 we no longer animate user session wallpaper - // during lock so it makes sense only to check that screen lock and related - // containers are animated during shutdown. - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::kAllLockScreenContainersMask, - internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); - // Make sure a mouse move event won't show the cursor. - GenerateMouseMoveEvent(); - EXPECT_FALSE(cursor_visible()); - EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); - test_api_->trigger_real_shutdown_timeout(); - EXPECT_EQ(1, NumShutdownRequests()); -} - -// Test that we start shutting down immediately if the power button is pressed -// while we're not logged in on an unofficial system. -TEST_F(PowerButtonControllerTest, LegacyNotLoggedIn) { - controller_->set_has_legacy_power_button_for_test(true); - lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); - lock_state_controller_->OnLockStateChanged(false); - SetUserLoggedIn(false); - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); - EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); -} - -// Test that we start shutting down immediately if the power button is pressed -// while we're logged in as a guest on an unofficial system. -TEST_F(PowerButtonControllerTest, LegacyGuest) { - controller_->set_has_legacy_power_button_for_test(true); - lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); - lock_state_controller_->OnLockStateChanged(false); - SetCanLockScreen(false); - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); - EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); -} - -// When we hold the power button while the user isn't logged in, we should shut -// down the machine directly. -TEST_F(PowerButtonControllerTest, ShutdownWhenNotLoggedIn) { - controller_->set_has_legacy_power_button_for_test(false); - lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); - lock_state_controller_->OnLockStateChanged(false); - SetUserLoggedIn(false); - - // Press the power button and check that we start the shutdown timer. - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); - EXPECT_FALSE(test_api_->lock_timer_is_running()); - EXPECT_TRUE(test_api_->shutdown_timer_is_running()); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::kAllContainersMask, - internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); - - // Release the power button before the shutdown timer fires. - controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); - EXPECT_FALSE(test_api_->shutdown_timer_is_running()); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::kAllContainersMask, - internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE)); - - // Press the button again and make the shutdown timeout fire this time. - // Check that we start the timer for actually requesting the shutdown. - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); - EXPECT_TRUE(test_api_->shutdown_timer_is_running()); - test_api_->trigger_shutdown_timeout(); - EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); - EXPECT_EQ(0, NumShutdownRequests()); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::LAUNCHER | - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::kAllLockScreenContainersMask, - internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); - - // When the timout fires, we should request a shutdown. - test_api_->trigger_real_shutdown_timeout(); - EXPECT_EQ(1, NumShutdownRequests()); -} - -// Test that we lock the screen and deal with unlocking correctly. -TEST_F(PowerButtonControllerTest, LockAndUnlock) { - controller_->set_has_legacy_power_button_for_test(false); - lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); - lock_state_controller_->OnLockStateChanged(false); - - // We should initially be showing the screen locker containers, since they - // also contain login-related windows that we want to show during the - // logging-in animation. - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_RESTORE)); - - // Press the power button and check that the lock timer is started and that we - // start scaling the non-screen-locker containers. - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); - EXPECT_TRUE(test_api_->lock_timer_is_running()); - EXPECT_FALSE(test_api_->shutdown_timer_is_running()); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); - - // Release the button before the lock timer fires. - controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); - EXPECT_FALSE(test_api_->lock_timer_is_running()); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE)); - - // Press the button and fire the lock timer. We should request that the - // screen be locked, but we should still be in the slow-close animation. - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); - EXPECT_TRUE(test_api_->lock_timer_is_running()); - EXPECT_EQ(0, delegate_->num_lock_requests()); - test_api_->trigger_lock_timeout(); - EXPECT_EQ(1, delegate_->num_lock_requests()); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); - - // Notify that we locked successfully. - lock_state_controller_->OnStartingLock(); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::LAUNCHER, - internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); - - // Notify that the lock window is visible. We should make it fade in. - lock_state_controller_->OnLockStateChanged(true); - state_delegate_->LockScreen(); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::kAllLockScreenContainersMask, - internal::SessionStateAnimator::ANIMATION_FADE_IN)); - - // When we release the power button, the lock-to-shutdown timer should be - // stopped. - EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); - controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); - EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); - - // Notify that the screen has been unlocked. We should show the - // non-screen-locker windows. - lock_state_controller_->OnLockStateChanged(false); - state_delegate_->UnlockScreen(); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::DESKTOP_BACKGROUND | - internal::SessionStateAnimator::LAUNCHER | - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_RESTORE)); -} - -// Hold the power button down from the unlocked state to eventual shutdown. -TEST_F(PowerButtonControllerTest, LockToShutdown) { - controller_->set_has_legacy_power_button_for_test(false); - lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); - lock_state_controller_->OnLockStateChanged(false); - - // Hold the power button and lock the screen. - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); - EXPECT_TRUE(test_api_->lock_timer_is_running()); - test_api_->trigger_lock_timeout(); - lock_state_controller_->OnStartingLock(); - lock_state_controller_->OnLockStateChanged(true); - state_delegate_->LockScreen(); - - // When the lock-to-shutdown timeout fires, we should start the shutdown - // timer. - EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); - test_api_->trigger_lock_to_shutdown_timeout(); - EXPECT_TRUE(test_api_->shutdown_timer_is_running()); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::kAllContainersMask, - internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); - - // Fire the shutdown timeout and check that we request shutdown. - test_api_->trigger_shutdown_timeout(); - EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); - EXPECT_EQ(0, NumShutdownRequests()); - test_api_->trigger_real_shutdown_timeout(); - EXPECT_EQ(1, NumShutdownRequests()); -} - - -// Hold the power button down from the unlocked state to eventual shutdown, -// then release the button while system does locking. -TEST_F(PowerButtonControllerTest, CancelLockToShutdown) { - controller_->set_has_legacy_power_button_for_test(false); - - lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); - lock_state_controller_->OnLockStateChanged(false); - - // Hold the power button and lock the screen. - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); - EXPECT_TRUE(test_api_->lock_timer_is_running()); - test_api_->trigger_lock_timeout(); - lock_state_controller_->OnStartingLock(); - - // Power button is released while system attempts to lock. - controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); - lock_state_controller_->OnLockStateChanged(true); - state_delegate_->LockScreen(); - - EXPECT_FALSE(lock_state_controller_->ShutdownRequested()); - EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); - EXPECT_FALSE(test_api_->shutdown_timer_is_running()); -} - -// Test that we handle the case where lock requests are ignored. -TEST_F(PowerButtonControllerTest, LockFail) { - // We require animations to have a duration for this test. - ui::ScopedAnimationDurationScaleMode normal_duration_mode( - ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); - - controller_->set_has_legacy_power_button_for_test(false); - lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); - lock_state_controller_->OnLockStateChanged(false); - - // Hold the power button and lock the screen. - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); - EXPECT_TRUE(test_api_->lock_timer_is_running()); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::DESKTOP_BACKGROUND | - internal::SessionStateAnimator::LAUNCHER | - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_RESTORE)); - test_api_->trigger_lock_timeout(); - EXPECT_EQ(1, delegate_->num_lock_requests()); - EXPECT_TRUE(test_api_->lock_fail_timer_is_running()); - - // We shouldn't start the lock-to-shutdown timer until the screen has actually - // been locked. - EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); - - // Act as if the request timed out. We should restore the windows. - test_api_->trigger_lock_fail_timeout(); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_RESTORE)); -} - -// Test the basic operation of the lock button. -TEST_F(PowerButtonControllerTest, LockButtonBasic) { - controller_->set_has_legacy_power_button_for_test(false); - // The lock button shouldn't do anything if we aren't logged in. - lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); - lock_state_controller_->OnLockStateChanged(false); - SetUserLoggedIn(false); - controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); - EXPECT_FALSE(test_api_->lock_timer_is_running()); - controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); - EXPECT_EQ(0, delegate_->num_lock_requests()); - - // Ditto for when we're logged in as a guest. - lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); - SetUserLoggedIn(true); - SetCanLockScreen(false); - controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); - EXPECT_FALSE(test_api_->lock_timer_is_running()); - controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); - EXPECT_EQ(0, delegate_->num_lock_requests()); - - // If we're logged in as a regular user, we should start the lock timer and - // the pre-lock animation. - lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); - SetCanLockScreen(true); - controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); - EXPECT_TRUE(test_api_->lock_timer_is_running()); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); - - // If the button is released immediately, we shouldn't lock the screen. - controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); - EXPECT_FALSE(test_api_->lock_timer_is_running()); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE)); - EXPECT_EQ(0, delegate_->num_lock_requests()); - - // Press the button again and let the lock timeout fire. We should request - // that the screen be locked. - controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); - EXPECT_TRUE(test_api_->lock_timer_is_running()); - test_api_->trigger_lock_timeout(); - EXPECT_EQ(1, delegate_->num_lock_requests()); - - // Pressing the lock button while we have a pending lock request shouldn't do - // anything. - controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); - controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); - EXPECT_FALSE(test_api_->lock_timer_is_running()); - controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); - - // Pressing the button also shouldn't do anything after the screen is locked. - lock_state_controller_->OnStartingLock(); - lock_state_controller_->OnLockStateChanged(true); - state_delegate_->LockScreen(); - controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); - EXPECT_FALSE(test_api_->lock_timer_is_running()); - controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); -} - -// Test that the power button takes priority over the lock button. -TEST_F(PowerButtonControllerTest, PowerButtonPreemptsLockButton) { - controller_->set_has_legacy_power_button_for_test(false); - lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); - lock_state_controller_->OnLockStateChanged(false); - - // While the lock button is down, hold the power button. - controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); - EXPECT_TRUE(test_api_->lock_timer_is_running()); - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); - EXPECT_TRUE(test_api_->lock_timer_is_running()); - - // The lock timer shouldn't be stopped when the lock button is released. - controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); - EXPECT_TRUE(test_api_->lock_timer_is_running()); - controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); - EXPECT_FALSE(test_api_->lock_timer_is_running()); - - // Now press the power button first and then the lock button. - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); - EXPECT_TRUE(test_api_->lock_timer_is_running()); - controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); - EXPECT_TRUE(test_api_->lock_timer_is_running()); - - // Releasing the power button should stop the lock timer. - controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); - EXPECT_FALSE(test_api_->lock_timer_is_running()); - controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); - EXPECT_FALSE(test_api_->lock_timer_is_running()); -} - -// When the screen is locked without going through the usual power-button -// slow-close path (e.g. via the wrench menu), test that we still show the -// fast-close animation. -TEST_F(PowerButtonControllerTest, LockWithoutButton) { - lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); - lock_state_controller_->OnStartingLock(); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); -} - -// When we hear that the process is exiting but we haven't had a chance to -// display an animation, we should just blank the screen. -TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) { - lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); - lock_state_controller_->OnAppTerminating(); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::kAllContainersMask, - internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); - GenerateMouseMoveEvent(); - EXPECT_FALSE(cursor_visible()); -} - -// Test that we display the fast-close animation and shut down when we get an -// outside request to shut down (e.g. from the login or lock screen). -TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) { - lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); - lock_state_controller_->OnLockStateChanged(false); - SetUserLoggedIn(false); - lock_state_controller_->RequestShutdown(); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::kAllLockScreenContainersMask, - internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); - GenerateMouseMoveEvent(); - EXPECT_FALSE(cursor_visible()); - - EXPECT_EQ(0, NumShutdownRequests()); - EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); - test_api_->trigger_real_shutdown_timeout(); - EXPECT_EQ(1, NumShutdownRequests()); -} - -TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) { - lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); - lock_state_controller_->OnLockStateChanged(true); - state_delegate_->LockScreen(); - lock_state_controller_->RequestShutdown(); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::kAllLockScreenContainersMask, - internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); - GenerateMouseMoveEvent(); - EXPECT_FALSE(cursor_visible()); - - EXPECT_EQ(0, NumShutdownRequests()); - EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); - test_api_->trigger_real_shutdown_timeout(); - EXPECT_EQ(1, NumShutdownRequests()); -} - -TEST_F(PowerButtonControllerTest, RequestAndCancelShutdownFromLockScreen) { - lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); - lock_state_controller_->OnLockStateChanged(true); - state_delegate_->LockScreen(); - - // Press the power button and check that we start the shutdown timer. - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); - EXPECT_FALSE(test_api_->lock_timer_is_running()); - EXPECT_TRUE(test_api_->shutdown_timer_is_running()); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::kAllContainersMask, - internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); - - // Release the power button before the shutdown timer fires. - controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); - EXPECT_FALSE(test_api_->shutdown_timer_is_running()); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::kAllLockScreenContainersMask, - internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE)); - EXPECT_TRUE( - animator_api_->ContainersAreAnimated( - internal::SessionStateAnimator::DESKTOP_BACKGROUND, - internal::SessionStateAnimator::ANIMATION_RESTORE)); -} - -// Test that we ignore power button presses when the screen is turned off. -TEST_F(PowerButtonControllerTest, IgnorePowerButtonIfScreenIsOff) { - lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); - - // When the screen brightness is at 0%, we shouldn't do anything in response - // to power button presses. - controller_->OnScreenBrightnessChanged(0.0); - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); - EXPECT_FALSE(test_api_->lock_timer_is_running()); - - // After increasing the brightness to 10%, we should start the timer like - // usual. - controller_->OnScreenBrightnessChanged(10.0); - controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); - EXPECT_TRUE(test_api_->lock_timer_is_running()); -} - -} // namespace test -} // namespace ash diff --git a/ash/wm/session_state_controller_impl.cc b/ash/wm/session_state_controller_impl.cc deleted file mode 100644 index 63b0d1f..0000000 --- a/ash/wm/session_state_controller_impl.cc +++ /dev/null @@ -1,341 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/wm/session_state_controller_impl.h" - -#include "ash/ash_switches.h" -#include "ash/cancel_mode.h" -#include "ash/shell.h" -#include "ash/shell_delegate.h" -#include "ash/shell_window_ids.h" -#include "ash/wm/session_state_animator.h" -#include "base/command_line.h" -#include "base/sys_info.h" -#include "ui/aura/root_window.h" -#include "ui/views/corewm/compound_event_filter.h" - -namespace ash { - -SessionStateControllerImpl::TestApi::TestApi( - SessionStateControllerImpl* controller) - : controller_(controller) { -} - -SessionStateControllerImpl::TestApi::~TestApi() { -} - -SessionStateControllerImpl::SessionStateControllerImpl() - : login_status_(user::LOGGED_IN_NONE), - system_is_locked_(false), - shutting_down_(false), - shutdown_after_lock_(false) { - Shell::GetPrimaryRootWindow()->AddRootWindowObserver(this); -} - -SessionStateControllerImpl::~SessionStateControllerImpl() { - Shell::GetPrimaryRootWindow()->RemoveRootWindowObserver(this); -} - -void SessionStateControllerImpl::OnLoginStateChanged(user::LoginStatus status) { - if (status != user::LOGGED_IN_LOCKED) - login_status_ = status; - system_is_locked_ = (status == user::LOGGED_IN_LOCKED); -} - -void SessionStateControllerImpl::OnAppTerminating() { - // If we hear that Chrome is exiting but didn't request it ourselves, all we - // can really hope for is that we'll have time to clear the screen. - if (!shutting_down_) { - shutting_down_ = true; - Shell* shell = ash::Shell::GetInstance(); - shell->env_filter()->set_cursor_hidden_by_filter(false); - shell->cursor_manager()->HideCursor(); - animator_->StartAnimation( - internal::SessionStateAnimator::kAllContainersMask, - internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, - internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); - } -} - -void SessionStateControllerImpl::OnLockStateChanged(bool locked) { - if (shutting_down_ || (system_is_locked_ == locked)) - return; - - system_is_locked_ = locked; - - if (locked) { - animator_->StartAnimation( - internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_FADE_IN, - internal::SessionStateAnimator::ANIMATION_SPEED_SHOW_LOCK_SCREEN); - DispatchCancelMode(); - FOR_EACH_OBSERVER(LockStateObserver, observers_, - OnLockStateEvent(LockStateObserver::EVENT_LOCK_ANIMATION_STARTED)); - lock_timer_.Stop(); - lock_fail_timer_.Stop(); - - if (shutdown_after_lock_) { - shutdown_after_lock_ = false; - StartLockToShutdownTimer(); - } - } else { - animator_->StartAnimation( - internal::SessionStateAnimator::DESKTOP_BACKGROUND | - internal::SessionStateAnimator::LAUNCHER | - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_RESTORE, - internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); - } -} - -void SessionStateControllerImpl::OnStartingLock() { - if (shutting_down_ || system_is_locked_) - return; - - animator_->StartAnimation( - internal::SessionStateAnimator::LAUNCHER, - internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, - internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); - - animator_->StartAnimation( - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_FULL_CLOSE, - internal::SessionStateAnimator::ANIMATION_SPEED_FAST); - - DispatchCancelMode(); - FOR_EACH_OBSERVER(LockStateObserver, observers_, - OnLockStateEvent(LockStateObserver::EVENT_LOCK_ANIMATION_STARTED)); - - // Hide the screen locker containers so we can make them fade in later. - animator_->StartAnimation( - internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, - internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); -} - -void SessionStateControllerImpl::StartLockAnimationAndLockImmediately() { - animator_->StartAnimation( - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE, - internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); - DispatchCancelMode(); - FOR_EACH_OBSERVER(LockStateObserver, observers_, - OnLockStateEvent(LockStateObserver::EVENT_LOCK_ANIMATION_STARTED)); - OnLockTimeout(); -} - -void SessionStateControllerImpl::StartLockAnimation(bool shutdown_after_lock) { - shutdown_after_lock_ = shutdown_after_lock; - - animator_->StartAnimation( - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE, - internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); - DispatchCancelMode(); - FOR_EACH_OBSERVER(LockStateObserver, observers_, - OnLockStateEvent(LockStateObserver::EVENT_PRELOCK_ANIMATION_STARTED)); - StartLockTimer(); -} - -void SessionStateControllerImpl::StartShutdownAnimation() { - animator_->StartAnimation( - internal::SessionStateAnimator::kAllContainersMask, - internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE, - internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); - - StartPreShutdownAnimationTimer(); -} - -bool SessionStateControllerImpl::LockRequested() { - return lock_fail_timer_.IsRunning(); -} - -bool SessionStateControllerImpl::ShutdownRequested() { - return shutting_down_; -} - -bool SessionStateControllerImpl::CanCancelLockAnimation() { - return lock_timer_.IsRunning(); -} - -void SessionStateControllerImpl::CancelLockAnimation() { - if (!CanCancelLockAnimation()) - return; - shutdown_after_lock_ = false; - animator_->StartAnimation( - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE, - internal::SessionStateAnimator::ANIMATION_SPEED_REVERT); - lock_timer_.Stop(); -} - -bool SessionStateControllerImpl::CanCancelShutdownAnimation() { - return pre_shutdown_timer_.IsRunning() || - shutdown_after_lock_ || - lock_to_shutdown_timer_.IsRunning(); -} - -void SessionStateControllerImpl::CancelShutdownAnimation() { - if (!CanCancelShutdownAnimation()) - return; - if (lock_to_shutdown_timer_.IsRunning()) { - lock_to_shutdown_timer_.Stop(); - return; - } - if (shutdown_after_lock_) { - shutdown_after_lock_ = false; - return; - } - - if (system_is_locked_) { - // If we've already started shutdown transition at lock screen - // desktop background needs to be restored immediately. - animator_->StartAnimation( - internal::SessionStateAnimator::DESKTOP_BACKGROUND, - internal::SessionStateAnimator::ANIMATION_RESTORE, - internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); - animator_->StartAnimation( - internal::SessionStateAnimator::kAllLockScreenContainersMask, - internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE, - internal::SessionStateAnimator::ANIMATION_SPEED_REVERT); - } else { - animator_->StartAnimation( - internal::SessionStateAnimator::kAllContainersMask, - internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE, - internal::SessionStateAnimator::ANIMATION_SPEED_REVERT); - } - pre_shutdown_timer_.Stop(); -} - -void SessionStateControllerImpl::RequestShutdown() { - if (!shutting_down_) - RequestShutdownImpl(); -} - -void SessionStateControllerImpl::RequestShutdownImpl() { - DCHECK(!shutting_down_); - shutting_down_ = true; - - Shell* shell = ash::Shell::GetInstance(); - shell->env_filter()->set_cursor_hidden_by_filter(false); - shell->cursor_manager()->HideCursor(); - - if (login_status_ != user::LOGGED_IN_NONE) { - // Hide the other containers before starting the animation. - // ANIMATION_FULL_CLOSE will make the screen locker windows partially - // transparent, and we don't want the other windows to show through. - animator_->StartAnimation( - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | - internal::SessionStateAnimator::LAUNCHER, - internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, - internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); - animator_->StartAnimation( - internal::SessionStateAnimator::kAllLockScreenContainersMask, - internal::SessionStateAnimator::ANIMATION_FULL_CLOSE, - internal::SessionStateAnimator::ANIMATION_SPEED_FAST); - } else { - animator_->StartAnimation( - internal::SessionStateAnimator::kAllContainersMask, - internal::SessionStateAnimator::ANIMATION_FULL_CLOSE, - internal::SessionStateAnimator::ANIMATION_SPEED_FAST); - } - StartRealShutdownTimer(); -} - -void SessionStateControllerImpl::OnRootWindowHostCloseRequested( - const aura::RootWindow*) { - Shell::GetInstance()->delegate()->Exit(); -} - -void SessionStateControllerImpl::StartLockTimer() { - lock_timer_.Stop(); - lock_timer_.Start( - FROM_HERE, - animator_->GetDuration( - internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE), - this, &SessionStateControllerImpl::OnLockTimeout); -} - -void SessionStateControllerImpl::OnLockTimeout() { - delegate_->RequestLockScreen(); - lock_fail_timer_.Start( - FROM_HERE, - base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs), - this, &SessionStateControllerImpl::OnLockFailTimeout); -} - -void SessionStateControllerImpl::OnLockFailTimeout() { - DCHECK(!system_is_locked_); - // Undo lock animation. - animator_->StartAnimation( - internal::SessionStateAnimator::LAUNCHER | - internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, - internal::SessionStateAnimator::ANIMATION_RESTORE, - internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); -} - -void SessionStateControllerImpl::StartLockToShutdownTimer() { - shutdown_after_lock_ = false; - lock_to_shutdown_timer_.Stop(); - lock_to_shutdown_timer_.Start( - FROM_HERE, - base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), - this, &SessionStateControllerImpl::OnLockToShutdownTimeout); -} - - -void SessionStateControllerImpl::OnLockToShutdownTimeout() { - DCHECK(system_is_locked_); - StartShutdownAnimation(); -} - -void SessionStateControllerImpl::StartPreShutdownAnimationTimer() { - pre_shutdown_timer_.Stop(); - pre_shutdown_timer_.Start( - FROM_HERE, - base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs), - this, &SessionStateControllerImpl::OnPreShutdownAnimationTimeout); -} - -void SessionStateControllerImpl::OnPreShutdownAnimationTimeout() { - if (!shutting_down_) - RequestShutdownImpl(); -} - -void SessionStateControllerImpl::StartRealShutdownTimer() { - base::TimeDelta duration = - base::TimeDelta::FromMilliseconds(kShutdownRequestDelayMs); - duration += animator_->GetDuration( - internal::SessionStateAnimator::ANIMATION_SPEED_FAST); - - real_shutdown_timer_.Start( - FROM_HERE, - duration, - this, &SessionStateControllerImpl::OnRealShutdownTimeout); -} - -void SessionStateControllerImpl::OnRealShutdownTimeout() { - DCHECK(shutting_down_); -#if defined(OS_CHROMEOS) - if (!base::SysInfo::IsRunningOnChromeOS()) { - ShellDelegate* delegate = Shell::GetInstance()->delegate(); - if (delegate) { - delegate->Exit(); - return; - } - } -#endif - delegate_->RequestShutdown(); -} - -void SessionStateControllerImpl::OnLockScreenHide(base::Closure& callback) { - callback.Run(); -} - -void SessionStateControllerImpl::SetLockScreenDisplayedCallback( - base::Closure& callback) { - NOTIMPLEMENTED(); -} - -} // namespace ash diff --git a/ash/wm/session_state_controller_impl.h b/ash/wm/session_state_controller_impl.h deleted file mode 100644 index 3ffc221..0000000 --- a/ash/wm/session_state_controller_impl.h +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_WM_SESSION_STATE_CONTROLLER_IMPL_H_ -#define ASH_WM_SESSION_STATE_CONTROLLER_IMPL_H_ - -#include "ash/ash_export.h" -#include "ash/shell_observer.h" -#include "ash/wm/lock_state_controller.h" -#include "ash/wm/session_state_animator.h" -#include "base/basictypes.h" -#include "base/memory/scoped_ptr.h" -#include "base/time/time.h" -#include "base/timer/timer.h" -#include "ui/aura/root_window_observer.h" - -namespace gfx { -class Rect; -class Size; -} - -namespace ui { -class Layer; -} - -namespace ash { - -namespace test { -class PowerButtonControllerTest; -} - -// Displays onscreen animations and locks or suspends the system in response to -// the power button being pressed or released. -class ASH_EXPORT SessionStateControllerImpl : - public LockStateController { - public: - - // Helper class used by tests to access internal state. - class ASH_EXPORT TestApi { - public: - explicit TestApi(SessionStateControllerImpl* controller); - - virtual ~TestApi(); - - bool lock_timer_is_running() const { - return controller_->lock_timer_.IsRunning(); - } - bool lock_fail_timer_is_running() const { - return controller_->lock_fail_timer_.IsRunning(); - } - bool lock_to_shutdown_timer_is_running() const { - return controller_->lock_to_shutdown_timer_.IsRunning(); - } - bool shutdown_timer_is_running() const { - return controller_->pre_shutdown_timer_.IsRunning(); - } - bool real_shutdown_timer_is_running() const { - return controller_->real_shutdown_timer_.IsRunning(); - } - - void trigger_lock_timeout() { - controller_->OnLockTimeout(); - controller_->lock_timer_.Stop(); - } - void trigger_lock_fail_timeout() { - controller_->OnLockFailTimeout(); - controller_->lock_fail_timer_.Stop(); - } - void trigger_lock_to_shutdown_timeout() { - controller_->OnLockToShutdownTimeout(); - controller_->lock_to_shutdown_timer_.Stop(); - } - void trigger_shutdown_timeout() { - controller_->OnPreShutdownAnimationTimeout(); - controller_->pre_shutdown_timer_.Stop(); - } - void trigger_real_shutdown_timeout() { - controller_->OnRealShutdownTimeout(); - controller_->real_shutdown_timer_.Stop(); - } - private: - SessionStateControllerImpl* controller_; // not owned - - DISALLOW_COPY_AND_ASSIGN(TestApi); - }; - - SessionStateControllerImpl(); - virtual ~SessionStateControllerImpl(); - - // RootWindowObserver override: - virtual void OnRootWindowHostCloseRequested( - const aura::RootWindow* root) OVERRIDE; - - // ShellObserver overrides: - virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE; - virtual void OnAppTerminating() OVERRIDE; - virtual void OnLockStateChanged(bool locked) OVERRIDE; - - // SessionLockStateController overrides: - virtual void StartLockAnimation(bool shutdown_after_lock) OVERRIDE; - - virtual void StartShutdownAnimation() OVERRIDE; - virtual void StartLockAnimationAndLockImmediately() OVERRIDE; - - virtual bool LockRequested() OVERRIDE; - virtual bool ShutdownRequested() OVERRIDE; - - virtual bool CanCancelLockAnimation() OVERRIDE; - virtual void CancelLockAnimation() OVERRIDE; - - virtual bool CanCancelShutdownAnimation() OVERRIDE; - virtual void CancelShutdownAnimation() OVERRIDE; - - virtual void OnStartingLock() OVERRIDE; - virtual void RequestShutdown() OVERRIDE; - - virtual void OnLockScreenHide(base::Closure& callback) OVERRIDE; - virtual void SetLockScreenDisplayedCallback(base::Closure& callback) OVERRIDE; - - protected: - friend class test::PowerButtonControllerTest; - - private: - void RequestShutdownImpl(); - - // Starts lock timer. - void StartLockTimer(); - - // Requests that the screen be locked and starts |lock_fail_timer_|. - void OnLockTimeout(); - - // Reverts the pre-lock animation, reports the error. - void OnLockFailTimeout(); - - // Starts timer for gap between lock and shutdown. - void StartLockToShutdownTimer(); - - // Calls StartShutdownAnimation(). - void OnLockToShutdownTimeout(); - - // Starts timer for undoable shutdown animation. - void StartPreShutdownAnimationTimer(); - - // Calls RequestShutdownImpl(); - void OnPreShutdownAnimationTimeout(); - - // Starts timer for final shutdown animation. - void StartRealShutdownTimer(); - - // Requests that the machine be shut down. - void OnRealShutdownTimeout(); - - // The current login status, or original login status from before we locked.. - user::LoginStatus login_status_; - - // Current lock status. - bool system_is_locked_; - - // Are we in the process of shutting the machine down? - bool shutting_down_; - - // Indicates whether controller should proceed to (cancellable) shutdown after - // locking. - bool shutdown_after_lock_; - - // Started when the user first presses the power button while in a - // logged-in-as-a-non-guest-user, unlocked state. When it fires, we lock the - // screen. - base::OneShotTimer<SessionStateControllerImpl> lock_timer_; - - // Started when we request that the screen be locked. When it fires, we - // assume that our request got dropped. - base::OneShotTimer<SessionStateControllerImpl> lock_fail_timer_; - - // Started when the screen is locked while the power button is held. Adds a - // delay between the appearance of the lock screen and the beginning of the - // pre-shutdown animation. - base::OneShotTimer<SessionStateControllerImpl> lock_to_shutdown_timer_; - - // Started when we begin displaying the pre-shutdown animation. When it - // fires, we start the shutdown animation and get ready to request shutdown. - base::OneShotTimer<SessionStateControllerImpl> pre_shutdown_timer_; - - // Started when we display the shutdown animation. When it fires, we actually - // request shutdown. Gives the animation time to complete before Chrome, X, - // etc. are shut down. - base::OneShotTimer<SessionStateControllerImpl> real_shutdown_timer_; - - DISALLOW_COPY_AND_ASSIGN(SessionStateControllerImpl); -}; - -} // namespace ash - -#endif // ASH_WM_SESSION_STATE_CONTROLLER_IMPL_H_ diff --git a/ash/wm/toplevel_window_event_handler_unittest.cc b/ash/wm/toplevel_window_event_handler_unittest.cc index 5f37213..45958e8 100644 --- a/ash/wm/toplevel_window_event_handler_unittest.cc +++ b/ash/wm/toplevel_window_event_handler_unittest.cc @@ -9,7 +9,7 @@ #include "ash/shell.h" #include "ash/shell_window_ids.h" #include "ash/test/ash_test_base.h" -#include "ash/wm/lock_state_controller_impl2.h" +#include "ash/wm/lock_state_controller.h" #include "ash/wm/resize_shadow.h" #include "ash/wm/resize_shadow_controller.h" #include "ash/wm/window_state.h" @@ -464,9 +464,8 @@ TEST_F(ToplevelWindowEventHandlerTest, GestureDrag) { // Tests that a gesture cannot minimize a window in login/lock screen. TEST_F(ToplevelWindowEventHandlerTest, GestureDragMinimizeLoginScreen) { - LockStateControllerImpl2* state_controller = - static_cast<LockStateControllerImpl2*> - (Shell::GetInstance()->lock_state_controller()); + LockStateController* state_controller = + Shell::GetInstance()->lock_state_controller(); state_controller->OnLoginStateChanged(user::LOGGED_IN_NONE); state_controller->OnLockStateChanged(false); SetUserLoggedIn(false); diff --git a/build/ios/grit_whitelist.txt b/build/ios/grit_whitelist.txt index bcdb3f3..359e3a0 100644 --- a/build/ios/grit_whitelist.txt +++ b/build/ios/grit_whitelist.txt @@ -420,8 +420,6 @@ IDS_FLAGS_ASH_DISABLE_PER_APP_LAUNCHER_DESCRIPTION IDS_FLAGS_ASH_DISABLE_PER_APP_LAUNCHER_NAME IDS_FLAGS_ASH_IMMERSIVE_FULLSCREEN_DESCRIPTION IDS_FLAGS_ASH_IMMERSIVE_FULLSCREEN_NAME -IDS_FLAGS_ASH_NEW_LOCK_ANIMATIONS -IDS_FLAGS_ASH_NEW_LOCK_ANIMATIONS_DESCRIPTION IDS_FLAGS_CAPTIVE_PORTAL_DETECTOR_DESCRIPTION IDS_FLAGS_CAPTIVE_PORTAL_DETECTOR_NAME IDS_FLAGS_CHROME_CAPTIVE_PORTAL_DETECTOR diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index a2e9475..5a8ddf98 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -6481,12 +6481,6 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_FLAGS_SHILL_CAPTIVE_PORTAL_DETECTOR" desc="Description for the option of Captive Portal detector."> Shill Captive Portal detector </message> - <message name="IDS_FLAGS_ASH_NEW_LOCK_ANIMATIONS" desc="Name for the flag to switch lock animations."> - Disable new lock animations. - </message> - <message name="IDS_FLAGS_ASH_NEW_LOCK_ANIMATIONS_DESCRIPTION" desc="Description for the flag to switch lock animations."> - Disables new lock animations. - </message> <message name="IDS_FLAGS_ENABLE_STICKY_KEYS_NAME" desc="Name for the flag to enable sticky keys."> Enable sticky keys. </message> diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc index af03e05..234c4ef 100644 --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -1139,13 +1139,6 @@ const Experiment kExperiments[] = { MULTI_VALUE_TYPE(kChromeCaptivePortalDetectionChoices), }, { - "disable-new-lock-animations", - IDS_FLAGS_ASH_NEW_LOCK_ANIMATIONS, - IDS_FLAGS_ASH_NEW_LOCK_ANIMATIONS_DESCRIPTION, - kOsCrOS, - SINGLE_VALUE_TYPE(ash::switches::kAshDisableNewLockAnimations), - }, - { "file-manager-show-checkboxes", IDS_FLAGS_FILE_MANAGER_SHOW_CHECKBOXES_NAME, IDS_FLAGS_FILE_MANAGER_SHOW_CHECKBOXES_DESCRIPTION, diff --git a/chrome/browser/chromeos/login/screen_locker.cc b/chrome/browser/chromeos/login/screen_locker.cc index 2517066..5410f80 100644 --- a/chrome/browser/chromeos/login/screen_locker.cc +++ b/chrome/browser/chromeos/login/screen_locker.cc @@ -231,19 +231,14 @@ void ScreenLocker::OnLoginSuccess( authentication_capture_->pending_requests = pending_requests; authentication_capture_->using_oauth = using_oauth; - CommandLine* command_line = CommandLine::ForCurrentProcess(); - if (command_line->HasSwitch(ash::switches::kAshDisableNewLockAnimations)) { - UnlockOnLoginSuccess(); - } else { - // Add guard for case when something get broken in call chain to unlock - // for sure. - base::MessageLoop::current()->PostDelayedTask( - FROM_HERE, - base::Bind(&ScreenLocker::UnlockOnLoginSuccess, - weak_factory_.GetWeakPtr()), - base::TimeDelta::FromMilliseconds(kUnlockGuardTimeoutMs)); - delegate_->AnimateAuthenticationSuccess(); - } + // Add guard for case when something get broken in call chain to unlock + // for sure. + base::MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&ScreenLocker::UnlockOnLoginSuccess, + weak_factory_.GetWeakPtr()), + base::TimeDelta::FromMilliseconds(kUnlockGuardTimeoutMs)); + delegate_->AnimateAuthenticationSuccess(); } void ScreenLocker::UnlockOnLoginSuccess() { diff --git a/chrome/browser/resources/chromeos/login/header_bar.css b/chrome/browser/resources/chromeos/login/header_bar.css index 55f4ac5..aba26ea 100644 --- a/chrome/browser/resources/chromeos/login/header_bar.css +++ b/chrome/browser/resources/chromeos/login/header_bar.css @@ -20,14 +20,14 @@ background-image: url('chrome://theme/IDR_LAUNCHER_BACKGROUND'); } -html[screen=lock][lockanimations=new] .login-header-bar-hidden { +html[screen=lock] .login-header-bar-hidden { opacity: 0; } -html[screen=lock][lockanimations=new] .login-header-bar-animate-fast { +html[screen=lock] .login-header-bar-animate-fast { -webkit-transition: opacity 200ms ease-out; } -html[screen=lock][lockanimations=new] .login-header-bar-animate-slow { +html[screen=lock] .login-header-bar-animate-slow { -webkit-transition: opacity 2s ease-out; } diff --git a/chrome/browser/resources/chromeos/login/login.html b/chrome/browser/resources/chromeos/login/login.html index 6d30288..f7038b1 100644 --- a/chrome/browser/resources/chromeos/login/login.html +++ b/chrome/browser/resources/chromeos/login/login.html @@ -1,5 +1,5 @@ <!DOCTYPE HTML> -<html i18n-values="dir:textdirection;lockanimations:lockAnimationsType;build:buildType"> +<html i18n-values="dir:textdirection;build:buildType"> <head> <title i18n-content="title"></title> <include src="login_resources.html"> diff --git a/chrome/browser/resources/chromeos/login/oobe.html b/chrome/browser/resources/chromeos/login/oobe.html index a459837..df3113f 100644 --- a/chrome/browser/resources/chromeos/login/oobe.html +++ b/chrome/browser/resources/chromeos/login/oobe.html @@ -1,5 +1,5 @@ <!DOCTYPE HTML> -<html i18n-values="dir:textdirection;lockanimations:lockAnimationsType;build:buildType;highlight:highlightStrength"> +<html i18n-values="dir:textdirection;build:buildType;highlight:highlightStrength"> <head> <title i18n-content="title"></title> <include src="login_resources.html"> diff --git a/chrome/browser/ui/webui/chromeos/login/oobe_ui.cc b/chrome/browser/ui/webui/chromeos/login/oobe_ui.cc index 5bf872b..6f7ac6d 100644 --- a/chrome/browser/ui/webui/chromeos/login/oobe_ui.cc +++ b/chrome/browser/ui/webui/chromeos/login/oobe_ui.cc @@ -375,12 +375,6 @@ void OobeUI::GetLocalizedStrings(base::DictionaryValue* localized_strings) { localized_strings->SetString("buildType", "chromium"); #endif - if (CommandLine::ForCurrentProcess()-> - HasSwitch(ash::switches::kAshDisableNewLockAnimations)) - localized_strings->SetString("lockAnimationsType", "old"); - else - localized_strings->SetString("lockAnimationsType", "new"); - // If we're not doing boot animation then WebUI should trigger // wallpaper load on boot. if (CommandLine::ForCurrentProcess()->HasSwitch( |