1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef ASH_WM_SESSION_STATE_CONTROLLER_H_
6 #define ASH_WM_SESSION_STATE_CONTROLLER_H_
8 #include "ash/ash_export.h"
9 #include "ash/shell_observer.h"
10 #include "ash/wm/session_state_animator.h"
11 #include "ash/wm/session_state_observer.h"
12 #include "base/basictypes.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/observer_list.h"
15 #include "base/time.h"
16 #include "base/timer.h"
17 #include "ui/aura/root_window_observer.h"
31 class PowerButtonControllerTest
;
32 class SessionStateControllerImpl2Test
;
35 // Performs system-related functions on behalf of SessionStateController.
36 class ASH_EXPORT SessionStateControllerDelegate
{
38 SessionStateControllerDelegate() {}
39 virtual ~SessionStateControllerDelegate() {}
41 virtual void RequestLockScreen() = 0;
42 virtual void RequestShutdown() = 0;
45 DISALLOW_COPY_AND_ASSIGN(SessionStateControllerDelegate
);
48 // Displays onscreen animations and locks or suspends the system in response to
49 // the power button being pressed or released.
50 class ASH_EXPORT SessionStateController
: public aura::RootWindowObserver
,
51 public ShellObserver
{
53 // Amount of time that the power button needs to be held before we lock the
55 static const int kLockTimeoutMs
;
57 // Amount of time that the power button needs to be held before we shut down.
58 static const int kShutdownTimeoutMs
;
60 // Amount of time to wait for our lock requests to be honored before giving
62 static const int kLockFailTimeoutMs
;
64 // When the button has been held continuously from the unlocked state, amount
65 // of time that we wait after the screen locker window is shown before
66 // starting the pre-shutdown animation.
67 static const int kLockToShutdownTimeoutMs
;
69 // Additional time (beyond kFastCloseAnimMs) to wait after starting the
70 // fast-close shutdown animation before actually requesting shutdown, to give
71 // the animation time to finish.
72 static const int kShutdownRequestDelayMs
;
74 SessionStateController();
75 virtual ~SessionStateController();
77 void SetDelegate(SessionStateControllerDelegate
* delegate
);
79 // Starts locking (with slow animation) that can be cancelled.
80 // After locking and |kLockToShutdownTimeoutMs| StartShutdownAnimation()
81 // will be called unless CancelShutdownAnimation() is called, if
82 // |shutdown_after_lock| is true.
83 virtual void StartLockAnimation(bool shutdown_after_lock
) = 0;
85 // Starts shutting down (with slow animation) that can be cancelled.
86 virtual void StartShutdownAnimation() = 0;
88 // Starts usual lock animation, but locks immediately.
89 // Unlike StartLockAnimation it does no lead to StartShutdownAnimation.
90 virtual void StartLockAnimationAndLockImmediately() = 0;
92 // Returns true if we have requested system to lock, but haven't received
94 virtual bool LockRequested() = 0;
96 // Returns true if we are shutting down.
97 virtual bool ShutdownRequested() = 0;
99 // Returns true if we are within cancellable lock timeframe.
100 virtual bool CanCancelLockAnimation() = 0;
102 // Cancels locking and reverts lock animation.
103 virtual void CancelLockAnimation() = 0;
105 // Returns true if we are within cancellable shutdown timeframe.
106 virtual bool CanCancelShutdownAnimation() = 0;
108 // Cancels shutting down and reverts shutdown animation.
109 virtual void CancelShutdownAnimation() = 0;
111 // Called when Chrome gets a request to display the lock screen.
112 virtual void OnStartingLock() = 0;
114 // Displays the shutdown animation and requests shutdown when it's done.
115 virtual void RequestShutdown() = 0;
117 // Called when ScreenLocker is ready to close, but not yet destroyed.
118 // Can be used to display "hiding" animations on unlock.
119 // |callback| will be called when all animations are done.
120 virtual void OnLockScreenHide(base::Closure
& callback
) = 0;
122 // Sets up the callback that should be called once lock animation is finished.
123 // Callback is guaranteed to be called once and then discarded.
124 virtual void SetLockScreenDisplayedCallback(base::Closure
& callback
) = 0;
126 virtual void AddObserver(SessionStateObserver
* observer
);
127 virtual void RemoveObserver(SessionStateObserver
* observer
);
128 virtual bool HasObserver(SessionStateObserver
* observer
);
131 friend class test::PowerButtonControllerTest
;
132 friend class test::SessionStateControllerImpl2Test
;
134 scoped_ptr
<internal::SessionStateAnimator
> animator_
;
136 scoped_ptr
<SessionStateControllerDelegate
> delegate_
;
138 ObserverList
<SessionStateObserver
> observers_
;
141 DISALLOW_COPY_AND_ASSIGN(SessionStateController
);
146 #endif // ASH_WM_SESSION_STATE_CONTROLLER_H_