OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef ASH_WM_SESSION_STATE_CONTROLLER_H_ | |
6 #define ASH_WM_SESSION_STATE_CONTROLLER_H_ | |
7 | |
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" | |
18 | |
19 namespace gfx { | |
20 class Rect; | |
21 class Size; | |
22 } | |
23 | |
24 namespace ui { | |
25 class Layer; | |
26 } | |
27 | |
28 namespace ash { | |
29 | |
30 namespace test { | |
31 class PowerButtonControllerTest; | |
32 class SessionStateControllerImpl2Test; | |
33 } | |
34 | |
35 // Performs system-related functions on behalf of SessionStateController. | |
36 class ASH_EXPORT SessionStateControllerDelegate { | |
37 public: | |
38 SessionStateControllerDelegate() {} | |
39 virtual ~SessionStateControllerDelegate() {} | |
40 | |
41 virtual void RequestLockScreen() = 0; | |
42 virtual void RequestShutdown() = 0; | |
43 | |
44 private: | |
45 DISALLOW_COPY_AND_ASSIGN(SessionStateControllerDelegate); | |
46 }; | |
47 | |
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 { | |
52 public: | |
53 // Amount of time that the power button needs to be held before we lock the | |
54 // screen. | |
55 static const int kLockTimeoutMs; | |
56 | |
57 // Amount of time that the power button needs to be held before we shut down. | |
58 static const int kShutdownTimeoutMs; | |
59 | |
60 // Amount of time to wait for our lock requests to be honored before giving | |
61 // up. | |
62 static const int kLockFailTimeoutMs; | |
63 | |
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; | |
68 | |
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; | |
73 | |
74 SessionStateController(); | |
75 virtual ~SessionStateController(); | |
76 | |
77 void SetDelegate(SessionStateControllerDelegate* delegate); | |
78 | |
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; | |
84 | |
85 // Starts shutting down (with slow animation) that can be cancelled. | |
86 virtual void StartShutdownAnimation() = 0; | |
87 | |
88 // Starts usual lock animation, but locks immediately. | |
89 // Unlike StartLockAnimation it does no lead to StartShutdownAnimation. | |
90 virtual void StartLockAnimationAndLockImmediately() = 0; | |
91 | |
92 // Returns true if we have requested system to lock, but haven't received | |
93 // confirmation yet. | |
94 virtual bool LockRequested() = 0; | |
95 | |
96 // Returns true if we are shutting down. | |
97 virtual bool ShutdownRequested() = 0; | |
98 | |
99 // Returns true if we are within cancellable lock timeframe. | |
100 virtual bool CanCancelLockAnimation() = 0; | |
101 | |
102 // Cancels locking and reverts lock animation. | |
103 virtual void CancelLockAnimation() = 0; | |
104 | |
105 // Returns true if we are within cancellable shutdown timeframe. | |
106 virtual bool CanCancelShutdownAnimation() = 0; | |
107 | |
108 // Cancels shutting down and reverts shutdown animation. | |
109 virtual void CancelShutdownAnimation() = 0; | |
110 | |
111 // Called when Chrome gets a request to display the lock screen. | |
112 virtual void OnStartingLock() = 0; | |
113 | |
114 // Displays the shutdown animation and requests shutdown when it's done. | |
115 virtual void RequestShutdown() = 0; | |
116 | |
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; | |
121 | |
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; | |
125 | |
126 virtual void AddObserver(SessionStateObserver* observer); | |
127 virtual void RemoveObserver(SessionStateObserver* observer); | |
128 virtual bool HasObserver(SessionStateObserver* observer); | |
129 | |
130 protected: | |
131 friend class test::PowerButtonControllerTest; | |
132 friend class test::SessionStateControllerImpl2Test; | |
133 | |
134 scoped_ptr<internal::SessionStateAnimator> animator_; | |
135 | |
136 scoped_ptr<SessionStateControllerDelegate> delegate_; | |
137 | |
138 ObserverList<SessionStateObserver> observers_; | |
139 | |
140 private: | |
141 DISALLOW_COPY_AND_ASSIGN(SessionStateController); | |
142 }; | |
143 | |
144 } // namespace ash | |
145 | |
146 #endif // ASH_WM_SESSION_STATE_CONTROLLER_H_ | |
OLD | NEW |