OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ASH_WM_SESSION_STATE_CONTROLLER_H_ | 5 #ifndef ASH_WM_SESSION_STATE_CONTROLLER_H_ |
6 #define ASH_WM_SESSION_STATE_CONTROLLER_H_ | 6 #define ASH_WM_SESSION_STATE_CONTROLLER_H_ |
7 | 7 |
8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
9 #include "ash/shell_observer.h" | 9 #include "ash/shell_observer.h" |
10 #include "ash/wm/session_state_animator.h" | 10 #include "ash/wm/session_state_animator.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 // Amount of time taken to scale the snapshot down to a point in the center of | 75 // Amount of time taken to scale the snapshot down to a point in the center of |
76 // the screen once the screen has been locked or we've been notified that the | 76 // the screen once the screen has been locked or we've been notified that the |
77 // system is shutting down. | 77 // system is shutting down. |
78 static const int kFastCloseAnimMs; | 78 static const int kFastCloseAnimMs; |
79 | 79 |
80 // Additional time (beyond kFastCloseAnimMs) to wait after starting the | 80 // Additional time (beyond kFastCloseAnimMs) to wait after starting the |
81 // fast-close shutdown animation before actually requesting shutdown, to give | 81 // fast-close shutdown animation before actually requesting shutdown, to give |
82 // the animation time to finish. | 82 // the animation time to finish. |
83 static const int kShutdownRequestDelayMs; | 83 static const int kShutdownRequestDelayMs; |
84 | 84 |
85 // Helper class used by tests to access internal state. | |
86 class ASH_EXPORT TestApi { | |
87 public: | |
88 explicit TestApi(SessionStateController* controller); | |
89 | |
90 virtual ~TestApi(); | |
91 | |
92 bool lock_timer_is_running() const { | |
93 return controller_->lock_timer_.IsRunning(); | |
94 } | |
95 bool lock_fail_timer_is_running() const { | |
96 return controller_->lock_fail_timer_.IsRunning(); | |
97 } | |
98 bool lock_to_shutdown_timer_is_running() const { | |
99 return controller_->lock_to_shutdown_timer_.IsRunning(); | |
100 } | |
101 bool shutdown_timer_is_running() const { | |
102 return controller_->pre_shutdown_timer_.IsRunning(); | |
103 } | |
104 bool real_shutdown_timer_is_running() const { | |
105 return controller_->real_shutdown_timer_.IsRunning(); | |
106 } | |
107 | |
108 void trigger_lock_timeout() { | |
109 controller_->OnLockTimeout(); | |
110 controller_->lock_timer_.Stop(); | |
111 } | |
112 void trigger_lock_fail_timeout() { | |
113 controller_->OnLockFailTimeout(); | |
114 controller_->lock_fail_timer_.Stop(); | |
115 } | |
116 void trigger_lock_to_shutdown_timeout() { | |
117 controller_->OnLockToShutdownTimeout(); | |
118 controller_->lock_to_shutdown_timer_.Stop(); | |
119 } | |
120 void trigger_shutdown_timeout() { | |
121 controller_->OnPreShutdownAnimationTimeout(); | |
122 controller_->pre_shutdown_timer_.Stop(); | |
123 } | |
124 void trigger_real_shutdown_timeout() { | |
125 controller_->OnRealShutdownTimeout(); | |
126 controller_->real_shutdown_timer_.Stop(); | |
127 } | |
128 private: | |
129 SessionStateController* controller_; // not owned | |
130 | |
131 DISALLOW_COPY_AND_ASSIGN(TestApi); | |
132 }; | |
133 | |
134 SessionStateController(); | 85 SessionStateController(); |
135 virtual ~SessionStateController(); | 86 virtual ~SessionStateController(); |
136 | 87 |
137 // RootWindowObserver override: | |
138 virtual void OnRootWindowHostCloseRequested( | |
139 const aura::RootWindow* root) OVERRIDE; | |
140 | |
141 // ShellObserver overrides: | |
142 virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE; | |
143 virtual void OnAppTerminating() OVERRIDE; | |
144 virtual void OnLockStateChanged(bool locked) OVERRIDE; | |
145 | |
146 void SetDelegate(SessionStateControllerDelegate* delegate); | 88 void SetDelegate(SessionStateControllerDelegate* delegate); |
147 | 89 |
148 // Returns true iff when we're in state when user session can be locked. | 90 // Returns true iff when we're in state when user session can be locked. |
149 virtual bool IsEligibleForLock(); | 91 virtual bool IsEligibleForLock() = 0; |
150 | 92 |
151 // Returns true if system is locked. | 93 // Returns true if system is locked. |
152 virtual bool IsLocked(); | 94 virtual bool IsLocked() = 0; |
153 | 95 |
154 // Starts locking (with slow animation) that can be cancelled. | 96 // Starts locking (with slow animation) that can be cancelled. |
155 // After locking and |kLockToShutdownTimeoutMs| StartShutdownAnimation() | 97 // After locking and |kLockToShutdownTimeoutMs| StartShutdownAnimation() |
156 // will be called unless CancelShutdown() is called, if |shutdown_after_lock| | 98 // will be called unless CancelShutdownAnimation() is called, if |
157 // is true. | 99 // |shutdown_after_lock| is true. |
158 virtual void StartLockAnimation(bool shutdown_after_lock); | 100 virtual void StartLockAnimation(bool shutdown_after_lock) = 0; |
159 | 101 |
160 // Starts shutting down (with slow animation) that can be cancelled. | 102 // Starts shutting down (with slow animation) that can be cancelled. |
161 virtual void StartShutdownAnimation(); | 103 virtual void StartShutdownAnimation() = 0; |
162 | 104 |
163 // Starts usual lock animation, but locks immediately. | 105 // Starts usual lock animation, but locks immediately. |
164 // Unlike StartLockAnimation it does no lead to StartShutdownAnimation. | 106 // Unlike StartLockAnimation it does no lead to StartShutdownAnimation. |
165 virtual void StartLockAnimationAndLockImmediately(); | 107 virtual void StartLockAnimationAndLockImmediately() = 0; |
166 | 108 |
167 // Returns true if we have requested system to lock, but haven't received | 109 // Returns true if we have requested system to lock, but haven't received |
168 // confirmation yet. | 110 // confirmation yet. |
169 virtual bool LockRequested(); | 111 virtual bool LockRequested() = 0; |
170 | 112 |
171 // Returns true if we are shutting down. | 113 // Returns true if we are shutting down. |
172 virtual bool ShutdownRequested(); | 114 virtual bool ShutdownRequested() = 0; |
173 | 115 |
174 // Returns true if we are within cancellable lock timeframe. | 116 // Returns true if we are within cancellable lock timeframe. |
175 virtual bool CanCancelLockAnimation(); | 117 virtual bool CanCancelLockAnimation() = 0; |
176 | 118 |
177 // Cancels locking and reverts lock animation. | 119 // Cancels locking and reverts lock animation. |
178 virtual void CancelLockAnimation(); | 120 virtual void CancelLockAnimation() = 0; |
179 | |
180 // Cancels locking and reverts lock animation with slightly different | |
181 // parameters. Seems to be some bug, but refactoring should keep all bugs. | |
182 // TODO(antrim): remove this, animations should actually be the same. | |
183 virtual void CancelLockWithOtherAnimation(); | |
184 | 121 |
185 // Returns true if we are within cancellable shutdown timeframe. | 122 // Returns true if we are within cancellable shutdown timeframe. |
186 virtual bool CanCancelShutdownAnimation(); | 123 virtual bool CanCancelShutdownAnimation() = 0; |
187 | 124 |
188 // Cancels shutting down and reverts shutdown animation. | 125 // Cancels shutting down and reverts shutdown animation. |
189 virtual void CancelShutdownAnimation(); | 126 virtual void CancelShutdownAnimation() = 0; |
190 | 127 |
191 // Called when Chrome gets a request to display the lock screen. | 128 // Called when Chrome gets a request to display the lock screen. |
192 virtual void OnStartingLock(); | 129 virtual void OnStartingLock() = 0; |
193 | 130 |
194 // Displays the shutdown animation and requests shutdown when it's done. | 131 // Displays the shutdown animation and requests shutdown when it's done. |
195 virtual void RequestShutdown(); | 132 virtual void RequestShutdown() = 0; |
196 | 133 |
197 protected: | 134 protected: |
198 friend class test::PowerButtonControllerTest; | 135 friend class test::PowerButtonControllerTest; |
199 | 136 |
200 bool IsLoggedInAsNonGuest() const; | 137 bool IsLoggedInAsNonGuest() const; |
201 | 138 |
202 private: | |
203 void RequestShutdownImpl(); | |
204 | |
205 // Starts lock timer. | |
206 void StartLockTimer(); | |
207 | |
208 // Requests that the screen be locked and starts |lock_fail_timer_|. | |
209 void OnLockTimeout(); | |
210 | |
211 // Reverts the pre-lock animation, reports the error. | |
212 void OnLockFailTimeout(); | |
213 | |
214 // Starts timer for gap between lock and shutdown. | |
215 void StartLockToShutdownTimer(); | |
216 | |
217 // Calls StartShutdownAnimation(). | |
218 void OnLockToShutdownTimeout(); | |
219 | |
220 // Starts timer for undoable shutdown animation. | |
221 void StartPreShutdownAnimationTimer(); | |
222 | |
223 // Calls RequestShutdownImpl(); | |
224 void OnPreShutdownAnimationTimeout(); | |
225 | |
226 // Starts timer for final shutdown animation. | |
227 void StartRealShutdownTimer(); | |
228 | |
229 // Requests that the machine be shut down. | |
230 void OnRealShutdownTimeout(); | |
231 | |
232 // The current login status. | |
233 user::LoginStatus login_status_; | |
234 | |
235 // Original login status from before we locked. LOGGED_IN_NONE if it's not | |
236 // locked. | |
237 user::LoginStatus unlocked_login_status_; | |
238 | |
239 // Are we in the process of shutting the machine down? | |
240 bool shutting_down_; | |
241 | |
242 // Indicates whether controller should proceed to (cancellable) shutdown after | |
243 // locking. | |
244 bool shutdown_after_lock_; | |
245 | |
246 // Started when the user first presses the power button while in a | |
247 // logged-in-as-a-non-guest-user, unlocked state. When it fires, we lock the | |
248 // screen. | |
249 base::OneShotTimer<SessionStateController> lock_timer_; | |
250 | |
251 // Started when we request that the screen be locked. When it fires, we | |
252 // assume that our request got dropped. | |
253 base::OneShotTimer<SessionStateController> lock_fail_timer_; | |
254 | |
255 // Started when the screen is locked while the power button is held. Adds a | |
256 // delay between the appearance of the lock screen and the beginning of the | |
257 // pre-shutdown animation. | |
258 base::OneShotTimer<SessionStateController> lock_to_shutdown_timer_; | |
259 | |
260 // Started when we begin displaying the pre-shutdown animation. When it | |
261 // fires, we start the shutdown animation and get ready to request shutdown. | |
262 base::OneShotTimer<SessionStateController> pre_shutdown_timer_; | |
263 | |
264 // Started when we display the shutdown animation. When it fires, we actually | |
265 // request shutdown. Gives the animation time to complete before Chrome, X, | |
266 // etc. are shut down. | |
267 base::OneShotTimer<SessionStateController> real_shutdown_timer_; | |
268 | |
269 scoped_ptr<internal::SessionStateAnimator> animator_; | 139 scoped_ptr<internal::SessionStateAnimator> animator_; |
270 | 140 |
271 scoped_ptr<SessionStateControllerDelegate> delegate_; | 141 scoped_ptr<SessionStateControllerDelegate> delegate_; |
272 | 142 |
| 143 private: |
273 DISALLOW_COPY_AND_ASSIGN(SessionStateController); | 144 DISALLOW_COPY_AND_ASSIGN(SessionStateController); |
274 }; | 145 }; |
275 | 146 |
276 } // namespace ash | 147 } // namespace ash |
277 | 148 |
278 #endif // ASH_WM_SESSION_STATE_CONTROLLER_H_ | 149 #endif // ASH_WM_SESSION_STATE_CONTROLLER_H_ |
OLD | NEW |