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 #include "ui/base/idle/idle.h"
6 
7 #include "base/time/time.h"
8 #include "chromeos/dbus/session_manager/session_manager_client.h"
9 #include "ui/base/idle/idle_internal.h"
10 #include "ui/base/user_activity/user_activity_detector.h"
11 
12 namespace ui {
13 
CalculateIdleTime()14 int CalculateIdleTime() {
15   base::TimeDelta idle_time = base::TimeTicks::Now() -
16       ui::UserActivityDetector::Get()->last_activity_time();
17   return static_cast<int>(idle_time.InSeconds());
18 }
19 
CheckIdleStateIsLocked()20 bool CheckIdleStateIsLocked() {
21   if (IdleStateForTesting().has_value())
22     return IdleStateForTesting().value() == IDLE_STATE_LOCKED;
23 
24   return chromeos::SessionManagerClient::Get()->IsScreenLocked();
25 }
26 
27 }  // namespace ui
28