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_POWER_BUTTON_CONTROLLER_H_ | 5 #ifndef ASH_WM_POWER_BUTTON_CONTROLLER_H_ |
6 #define ASH_WM_POWER_BUTTON_CONTROLLER_H_ | 6 #define ASH_WM_POWER_BUTTON_CONTROLLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "ash/ash_export.h" | 9 #include "ash/ash_export.h" |
| 10 #include "ash/shell_observer.h" |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/time.h" | 13 #include "base/time.h" |
13 #include "base/timer.h" | 14 #include "base/timer.h" |
14 #include "ui/aura/root_window_observer.h" | 15 #include "ui/aura/root_window_observer.h" |
15 | 16 |
16 namespace gfx { | 17 namespace gfx { |
17 class Size; | 18 class Size; |
18 } | 19 } |
19 | 20 |
(...skipping 11 matching lines...) Expand all Loading... |
31 | 32 |
32 virtual void RequestLockScreen() = 0; | 33 virtual void RequestLockScreen() = 0; |
33 virtual void RequestShutdown() = 0; | 34 virtual void RequestShutdown() = 0; |
34 | 35 |
35 private: | 36 private: |
36 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerDelegate); | 37 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerDelegate); |
37 }; | 38 }; |
38 | 39 |
39 // Displays onscreen animations and locks or suspends the system in response to | 40 // Displays onscreen animations and locks or suspends the system in response to |
40 // the power button being pressed or released. | 41 // the power button being pressed or released. |
41 class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver { | 42 class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver, |
| 43 public ShellObserver { |
42 public: | 44 public: |
43 // Animations that can be applied to groups of containers. | 45 // Animations that can be applied to groups of containers. |
44 // Exposed here for TestApi::ContainerGroupIsAnimated(). | 46 // Exposed here for TestApi::ContainerGroupIsAnimated(). |
45 enum AnimationType { | 47 enum AnimationType { |
46 ANIMATION_SLOW_CLOSE = 0, | 48 ANIMATION_SLOW_CLOSE = 0, |
47 ANIMATION_UNDO_SLOW_CLOSE, | 49 ANIMATION_UNDO_SLOW_CLOSE, |
48 ANIMATION_FAST_CLOSE, | 50 ANIMATION_FAST_CLOSE, |
49 ANIMATION_FADE_IN, | 51 ANIMATION_FADE_IN, |
50 ANIMATION_HIDE, | 52 ANIMATION_HIDE, |
51 ANIMATION_RESTORE, | 53 ANIMATION_RESTORE, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 virtual ~PowerButtonController(); | 130 virtual ~PowerButtonController(); |
129 | 131 |
130 void set_delegate(PowerButtonControllerDelegate* delegate) { | 132 void set_delegate(PowerButtonControllerDelegate* delegate) { |
131 delegate_.reset(delegate); | 133 delegate_.reset(delegate); |
132 } | 134 } |
133 | 135 |
134 void set_has_legacy_power_button_for_test(bool legacy) { | 136 void set_has_legacy_power_button_for_test(bool legacy) { |
135 has_legacy_power_button_ = legacy; | 137 has_legacy_power_button_ = legacy; |
136 } | 138 } |
137 | 139 |
138 // Called when the user logs in. | |
139 void OnLoginStateChange(bool logged_in, bool is_guest); | |
140 | |
141 // Called when the application is exiting. | |
142 void OnExit(); | |
143 | |
144 // Called when the screen is locked (after the lock window is visible) or | |
145 // unlocked. | |
146 void OnLockStateChange(bool locked); | |
147 | |
148 // Called when Chrome gets a request to display the lock screen. | 140 // Called when Chrome gets a request to display the lock screen. |
149 void OnStartingLock(); | 141 void OnStartingLock(); |
150 | 142 |
151 // Called when the power or lock buttons are pressed or released. | 143 // Called when the power or lock buttons are pressed or released. |
152 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp); | 144 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp); |
153 void OnLockButtonEvent(bool down, const base::TimeTicks& timestamp); | 145 void OnLockButtonEvent(bool down, const base::TimeTicks& timestamp); |
154 | 146 |
155 // Displays the shutdown animation and requests shutdown when it's done. | 147 // Displays the shutdown animation and requests shutdown when it's done. |
156 void RequestShutdown(); | 148 void RequestShutdown(); |
157 | 149 |
158 // aura::RootWindowObserver overrides: | 150 // aura::RootWindowObserver overrides: |
159 virtual void OnRootWindowResized(const aura::RootWindow* root, | 151 virtual void OnRootWindowResized(const aura::RootWindow* root, |
160 const gfx::Size& old_size) OVERRIDE; | 152 const gfx::Size& old_size) OVERRIDE; |
161 | 153 |
| 154 // ShellObserver overrides: |
| 155 virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE; |
| 156 virtual void OnAppTerminating() OVERRIDE; |
| 157 virtual void OnLockStateChanged(bool locked) OVERRIDE; |
| 158 |
162 private: | 159 private: |
163 bool logged_in_as_non_guest() const { return logged_in_ && !is_guest_; } | 160 bool LoggedInAsNonGuest() const; |
164 | 161 |
165 // Requests that the screen be locked and starts |lock_fail_timer_|. | 162 // Requests that the screen be locked and starts |lock_fail_timer_|. |
166 void OnLockTimeout(); | 163 void OnLockTimeout(); |
167 | 164 |
168 // Aborts the pre-lock animation. | 165 // Aborts the pre-lock animation. |
169 void OnLockFailTimeout(); | 166 void OnLockFailTimeout(); |
170 | 167 |
171 // Displays the pre-shutdown animation and starts |shutdown_timer_|. | 168 // Displays the pre-shutdown animation and starts |shutdown_timer_|. |
172 void OnLockToShutdownTimeout(); | 169 void OnLockToShutdownTimeout(); |
173 | 170 |
(...skipping 10 matching lines...) Expand all Loading... |
184 // Displays the shutdown animation and starts |real_shutdown_timer_|. | 181 // Displays the shutdown animation and starts |real_shutdown_timer_|. |
185 void StartShutdownAnimationAndRequestShutdown(); | 182 void StartShutdownAnimationAndRequestShutdown(); |
186 | 183 |
187 // Shows or hides |background_layer_|. The show method creates and | 184 // Shows or hides |background_layer_|. The show method creates and |
188 // initializes the layer if it doesn't already exist. | 185 // initializes the layer if it doesn't already exist. |
189 void ShowBackgroundLayer(); | 186 void ShowBackgroundLayer(); |
190 void HideBackgroundLayer(); | 187 void HideBackgroundLayer(); |
191 | 188 |
192 scoped_ptr<PowerButtonControllerDelegate> delegate_; | 189 scoped_ptr<PowerButtonControllerDelegate> delegate_; |
193 | 190 |
194 // True if the user is currently logged in. | 191 // The current login status. |
195 bool logged_in_; | 192 user::LoginStatus login_status_; |
196 | 193 |
197 // True if a guest user is currently logged in. Unused if |logged_in_| is | 194 // Original login status during locked. LOGGED_IN_NONE if it's not locked. |
198 // false. | 195 user::LoginStatus unlocked_login_status_; |
199 bool is_guest_; | |
200 | |
201 // True if the screen is currently locked. | |
202 bool locked_; | |
203 | 196 |
204 // Are the power or lock buttons currently held? | 197 // Are the power or lock buttons currently held? |
205 bool power_button_down_; | 198 bool power_button_down_; |
206 bool lock_button_down_; | 199 bool lock_button_down_; |
207 | 200 |
208 // Are we in the process of shutting the machine down? | 201 // Are we in the process of shutting the machine down? |
209 bool shutting_down_; | 202 bool shutting_down_; |
210 | 203 |
211 // Should we start |shutdown_timer_| when we receive notification that the | 204 // Should we start |shutdown_timer_| when we receive notification that the |
212 // screen has been locked? | 205 // screen has been locked? |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 // |background_layer_|, as the desktop background is now covering the whole | 243 // |background_layer_|, as the desktop background is now covering the whole |
251 // screen. | 244 // screen. |
252 base::OneShotTimer<PowerButtonController> hide_background_layer_timer_; | 245 base::OneShotTimer<PowerButtonController> hide_background_layer_timer_; |
253 | 246 |
254 DISALLOW_COPY_AND_ASSIGN(PowerButtonController); | 247 DISALLOW_COPY_AND_ASSIGN(PowerButtonController); |
255 }; | 248 }; |
256 | 249 |
257 } // namespace ash | 250 } // namespace ash |
258 | 251 |
259 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_ | 252 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_ |
OLD | NEW |