Index: ash/system/chromeos/power/tablet_power_button_controller.cc |
diff --git a/ash/system/chromeos/power/tablet_power_button_controller.cc b/ash/system/chromeos/power/tablet_power_button_controller.cc |
index d8b3fc6f54204c082c8fd1ce0bfc718cc44c84ec..4041637e6e9dadb63466d11111f717a1bc20a310 100644 |
--- a/ash/system/chromeos/power/tablet_power_button_controller.cc |
+++ b/ash/system/chromeos/power/tablet_power_button_controller.cc |
@@ -25,6 +25,10 @@ namespace { |
// animation when in tablet mode. |
constexpr int kShutdownTimeoutMs = 500; |
+// Amount of time that locking screen needs to be delayed after setting display |
+// forced off. |
Daniel Erat
2017/01/12 01:40:46
thanks, i understand now. maybe:
// Amount of tim
Qiang(Joe) Xu
2017/01/12 15:05:55
Done.
|
+constexpr int kLockScreenTimeoutMs = 1000; |
+ |
// Amount of time since last SuspendDone() that power button event needs to be |
// ignored. |
constexpr int kIgnorePowerButtonAfterResumeMs = 2000; |
@@ -64,6 +68,16 @@ void TabletPowerButtonController::TestApi::TriggerShutdownTimeout() { |
controller_->shutdown_timer_.Stop(); |
} |
+bool TabletPowerButtonController::TestApi::LockScreenTimerIsRunning() const { |
+ return controller_->lock_screen_timer_.IsRunning(); |
+} |
+ |
+void TabletPowerButtonController::TestApi::TriggerLockScreenTimeout() { |
+ DCHECK(LockScreenTimerIsRunning()); |
+ controller_->OnLockScreenTimeout(); |
+ controller_->lock_screen_timer_.Stop(); |
+} |
+ |
TabletPowerButtonController::TabletPowerButtonController( |
LockStateController* controller) |
: tick_clock_(new base::DefaultTickClock()), |
@@ -108,6 +122,7 @@ void TabletPowerButtonController::OnPowerButtonEvent( |
} |
screen_off_when_power_button_down_ = brightness_level_is_zero_; |
SetDisplayForcedOff(false); |
+ lock_screen_timer_.Stop(); |
StartShutdownTimer(); |
} else { |
if (shutdown_timer_.IsRunning()) { |
@@ -159,8 +174,10 @@ void TabletPowerButtonController::OnKeyEvent(ui::KeyEvent* event) { |
if (event->key_code() == ui::VKEY_POWER) |
return; |
- if (!IsTabletModeActive() && backlights_forced_off_) |
+ if (!IsTabletModeActive() && backlights_forced_off_) { |
SetDisplayForcedOff(false); |
+ lock_screen_timer_.Stop(); |
+ } |
} |
void TabletPowerButtonController::OnMouseEvent(ui::MouseEvent* event) { |
@@ -171,14 +188,17 @@ void TabletPowerButtonController::OnMouseEvent(ui::MouseEvent* event) { |
return; |
} |
- if (!IsTabletModeActive() && backlights_forced_off_) |
+ if (!IsTabletModeActive() && backlights_forced_off_) { |
SetDisplayForcedOff(false); |
+ lock_screen_timer_.Stop(); |
+ } |
} |
void TabletPowerButtonController::OnStylusStateChanged(ui::StylusState state) { |
if (IsTabletModeSupported() && state == ui::StylusState::REMOVED && |
backlights_forced_off_) { |
SetDisplayForcedOff(false); |
+ lock_screen_timer_.Stop(); |
} |
} |
@@ -206,6 +226,11 @@ void TabletPowerButtonController::SetDisplayForcedOff(bool forced_off) { |
// Send an a11y alert. |
WmShell::Get()->accessibility_delegate()->TriggerAccessibilityAlert( |
forced_off ? A11Y_ALERT_SCREEN_OFF : A11Y_ALERT_SCREEN_ON); |
+ |
+ // Reset |lock_screen_timer_| when display is not set to forced off since |
+ // under this case, |lock_screen_timer_| should not timeout. |
+ if (!forced_off) |
+ lock_screen_timer_.Stop(); |
Daniel Erat
2017/01/12 01:40:46
did you mean to remove this now? aren't you alread
Qiang(Joe) Xu
2017/01/12 15:05:55
oops, yeh, sorry about this.
|
} |
void TabletPowerButtonController::GetInitialBacklightsForcedOff() { |
@@ -238,8 +263,14 @@ void TabletPowerButtonController::LockScreenIfRequired() { |
session_state_delegate->CanLockScreen() && |
!session_state_delegate->IsUserSessionBlocked() && |
!controller_->LockRequested()) { |
- session_state_delegate->LockScreen(); |
+ lock_screen_timer_.Start( |
+ FROM_HERE, base::TimeDelta::FromMilliseconds(kLockScreenTimeoutMs), |
+ this, &TabletPowerButtonController::OnLockScreenTimeout); |
} |
} |
+void TabletPowerButtonController::OnLockScreenTimeout() { |
+ WmShell::Get()->GetSessionStateDelegate()->LockScreen(); |
+} |
+ |
} // namespace ash |