Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: ash/system/chromeos/power/tablet_power_button_controller.cc

Issue 2640333002: Revert "ash: Add one second grace period For LockScreenIfRequired" (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "ash/system/chromeos/power/tablet_power_button_controller.h" 5 #include "ash/system/chromeos/power/tablet_power_button_controller.h"
6 6
7 #include "ash/common/accessibility_delegate.h" 7 #include "ash/common/accessibility_delegate.h"
8 #include "ash/common/session/session_state_delegate.h" 8 #include "ash/common/session/session_state_delegate.h"
9 #include "ash/common/shell_delegate.h" 9 #include "ash/common/shell_delegate.h"
10 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" 10 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
11 #include "ash/common/wm_shell.h" 11 #include "ash/common/wm_shell.h"
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "ash/wm/lock_state_controller.h" 13 #include "ash/wm/lock_state_controller.h"
14 #include "base/time/default_tick_clock.h" 14 #include "base/time/default_tick_clock.h"
15 #include "chromeos/dbus/dbus_thread_manager.h" 15 #include "chromeos/dbus/dbus_thread_manager.h"
16 #include "ui/events/devices/input_device_manager.h" 16 #include "ui/events/devices/input_device_manager.h"
17 #include "ui/events/devices/stylus_state.h" 17 #include "ui/events/devices/stylus_state.h"
18 #include "ui/events/event.h" 18 #include "ui/events/event.h"
19 19
20 namespace ash { 20 namespace ash {
21 21
22 namespace { 22 namespace {
23 23
24 // Amount of time the power button must be held to start the pre-shutdown 24 // Amount of time the power button must be held to start the pre-shutdown
25 // animation when in tablet mode. 25 // animation when in tablet mode.
26 constexpr int kShutdownTimeoutMs = 500; 26 constexpr int kShutdownTimeoutMs = 500;
27 27
28 // Amount of time to delay locking screen after display is forced off.
29 constexpr int kLockScreenTimeoutMs = 1000;
30
31 // Amount of time since last SuspendDone() that power button event needs to be 28 // Amount of time since last SuspendDone() that power button event needs to be
32 // ignored. 29 // ignored.
33 constexpr int kIgnorePowerButtonAfterResumeMs = 2000; 30 constexpr int kIgnorePowerButtonAfterResumeMs = 2000;
34 31
35 // Returns true if device is a convertible/tablet device or has 32 // Returns true if device is a convertible/tablet device or has
36 // kAshEnableTouchViewTesting in test, otherwise false. 33 // kAshEnableTouchViewTesting in test, otherwise false.
37 bool IsTabletModeSupported() { 34 bool IsTabletModeSupported() {
38 MaximizeModeController* maximize_mode_controller = 35 MaximizeModeController* maximize_mode_controller =
39 WmShell::Get()->maximize_mode_controller(); 36 WmShell::Get()->maximize_mode_controller();
40 return maximize_mode_controller && 37 return maximize_mode_controller &&
(...skipping 19 matching lines...) Expand all
60 bool TabletPowerButtonController::TestApi::ShutdownTimerIsRunning() const { 57 bool TabletPowerButtonController::TestApi::ShutdownTimerIsRunning() const {
61 return controller_->shutdown_timer_.IsRunning(); 58 return controller_->shutdown_timer_.IsRunning();
62 } 59 }
63 60
64 void TabletPowerButtonController::TestApi::TriggerShutdownTimeout() { 61 void TabletPowerButtonController::TestApi::TriggerShutdownTimeout() {
65 DCHECK(ShutdownTimerIsRunning()); 62 DCHECK(ShutdownTimerIsRunning());
66 controller_->OnShutdownTimeout(); 63 controller_->OnShutdownTimeout();
67 controller_->shutdown_timer_.Stop(); 64 controller_->shutdown_timer_.Stop();
68 } 65 }
69 66
70 bool TabletPowerButtonController::TestApi::LockScreenTimerIsRunning() const {
71 return controller_->lock_screen_timer_.IsRunning();
72 }
73
74 void TabletPowerButtonController::TestApi::TriggerLockScreenTimeout() {
75 DCHECK(LockScreenTimerIsRunning());
76 controller_->OnLockScreenTimeout();
77 controller_->lock_screen_timer_.Stop();
78 }
79
80 TabletPowerButtonController::TabletPowerButtonController( 67 TabletPowerButtonController::TabletPowerButtonController(
81 LockStateController* controller) 68 LockStateController* controller)
82 : tick_clock_(new base::DefaultTickClock()), 69 : tick_clock_(new base::DefaultTickClock()),
83 last_resume_time_(base::TimeTicks()), 70 last_resume_time_(base::TimeTicks()),
84 force_off_on_button_up_(true), 71 force_off_on_button_up_(true),
85 controller_(controller), 72 controller_(controller),
86 weak_ptr_factory_(this) { 73 weak_ptr_factory_(this) {
87 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( 74 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(
88 this); 75 this);
89 WmShell::Get()->AddShellObserver(this); 76 WmShell::Get()->AddShellObserver(this);
(...skipping 24 matching lines...) Expand all
114 // Chrome receives powerd's SuspendDone signal and notification that the 101 // Chrome receives powerd's SuspendDone signal and notification that the
115 // backlight has been turned back on before seeing the power button events 102 // backlight has been turned back on before seeing the power button events
116 // that woke the system. Avoid forcing off display just after resuming to 103 // that woke the system. Avoid forcing off display just after resuming to
117 // ensure that we don't turn the display off in response to the events. 104 // ensure that we don't turn the display off in response to the events.
118 if (timestamp - last_resume_time_ <= 105 if (timestamp - last_resume_time_ <=
119 base::TimeDelta::FromMilliseconds(kIgnorePowerButtonAfterResumeMs)) { 106 base::TimeDelta::FromMilliseconds(kIgnorePowerButtonAfterResumeMs)) {
120 force_off_on_button_up_ = false; 107 force_off_on_button_up_ = false;
121 } 108 }
122 screen_off_when_power_button_down_ = brightness_level_is_zero_; 109 screen_off_when_power_button_down_ = brightness_level_is_zero_;
123 SetDisplayForcedOff(false); 110 SetDisplayForcedOff(false);
124 lock_screen_timer_.Stop();
125 StartShutdownTimer(); 111 StartShutdownTimer();
126 } else { 112 } else {
127 if (shutdown_timer_.IsRunning()) { 113 if (shutdown_timer_.IsRunning()) {
128 shutdown_timer_.Stop(); 114 shutdown_timer_.Stop();
129 if (!screen_off_when_power_button_down_ && force_off_on_button_up_) { 115 if (!screen_off_when_power_button_down_ && force_off_on_button_up_) {
130 SetDisplayForcedOff(true); 116 SetDisplayForcedOff(true);
131 LockScreenIfRequired(); 117 LockScreenIfRequired();
132 } 118 }
133 } 119 }
134 120
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 if (controller_->CanCancelShutdownAnimation()) 152 if (controller_->CanCancelShutdownAnimation())
167 controller_->CancelShutdownAnimation(); 153 controller_->CancelShutdownAnimation();
168 } 154 }
169 155
170 void TabletPowerButtonController::OnKeyEvent(ui::KeyEvent* event) { 156 void TabletPowerButtonController::OnKeyEvent(ui::KeyEvent* event) {
171 // Ignore key events generated by the power button since power button activity 157 // Ignore key events generated by the power button since power button activity
172 // is already handled by OnPowerButtonEvent(). 158 // is already handled by OnPowerButtonEvent().
173 if (event->key_code() == ui::VKEY_POWER) 159 if (event->key_code() == ui::VKEY_POWER)
174 return; 160 return;
175 161
176 if (!IsTabletModeActive() && backlights_forced_off_) { 162 if (!IsTabletModeActive() && backlights_forced_off_)
177 SetDisplayForcedOff(false); 163 SetDisplayForcedOff(false);
178 lock_screen_timer_.Stop();
179 }
180 } 164 }
181 165
182 void TabletPowerButtonController::OnMouseEvent(ui::MouseEvent* event) { 166 void TabletPowerButtonController::OnMouseEvent(ui::MouseEvent* event) {
183 if (event->flags() & ui::EF_IS_SYNTHESIZED) 167 if (event->flags() & ui::EF_IS_SYNTHESIZED)
184 return; 168 return;
185 169
186 if (!IsTabletModeActive() && backlights_forced_off_) { 170 if (!IsTabletModeActive() && backlights_forced_off_)
187 SetDisplayForcedOff(false); 171 SetDisplayForcedOff(false);
188 lock_screen_timer_.Stop();
189 }
190 } 172 }
191 173
192 void TabletPowerButtonController::OnStylusStateChanged(ui::StylusState state) { 174 void TabletPowerButtonController::OnStylusStateChanged(ui::StylusState state) {
193 if (IsTabletModeSupported() && state == ui::StylusState::REMOVED && 175 if (IsTabletModeSupported() && state == ui::StylusState::REMOVED &&
194 backlights_forced_off_) { 176 backlights_forced_off_) {
195 SetDisplayForcedOff(false); 177 SetDisplayForcedOff(false);
196 lock_screen_timer_.Stop();
197 } 178 }
198 } 179 }
199 180
200 void TabletPowerButtonController::SetTickClockForTesting( 181 void TabletPowerButtonController::SetTickClockForTesting(
201 std::unique_ptr<base::TickClock> tick_clock) { 182 std::unique_ptr<base::TickClock> tick_clock) {
202 DCHECK(tick_clock); 183 DCHECK(tick_clock);
203 tick_clock_ = std::move(tick_clock); 184 tick_clock_ = std::move(tick_clock);
204 } 185 }
205 186
206 void TabletPowerButtonController::SetDisplayForcedOff(bool forced_off) { 187 void TabletPowerButtonController::SetDisplayForcedOff(bool forced_off) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 controller_->StartShutdownAnimation(); 227 controller_->StartShutdownAnimation();
247 } 228 }
248 229
249 void TabletPowerButtonController::LockScreenIfRequired() { 230 void TabletPowerButtonController::LockScreenIfRequired() {
250 SessionStateDelegate* session_state_delegate = 231 SessionStateDelegate* session_state_delegate =
251 WmShell::Get()->GetSessionStateDelegate(); 232 WmShell::Get()->GetSessionStateDelegate();
252 if (session_state_delegate->ShouldLockScreenAutomatically() && 233 if (session_state_delegate->ShouldLockScreenAutomatically() &&
253 session_state_delegate->CanLockScreen() && 234 session_state_delegate->CanLockScreen() &&
254 !session_state_delegate->IsUserSessionBlocked() && 235 !session_state_delegate->IsUserSessionBlocked() &&
255 !controller_->LockRequested()) { 236 !controller_->LockRequested()) {
256 lock_screen_timer_.Start( 237 session_state_delegate->LockScreen();
257 FROM_HERE, base::TimeDelta::FromMilliseconds(kLockScreenTimeoutMs),
258 this, &TabletPowerButtonController::OnLockScreenTimeout);
259 } 238 }
260 } 239 }
261 240
262 void TabletPowerButtonController::OnLockScreenTimeout() {
263 WmShell::Get()->GetSessionStateDelegate()->LockScreen();
264 }
265
266 } // namespace ash 241 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698