blob: d8f2f0809493f77f7d1c46efc24a48628ee6ad56 [file] [log] [blame]
[email protected]64e199252012-04-06 01:54:361// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]7bf59022011-09-08 21:24:212// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/idle.h"
6
7#include "base/bind.h"
8#include "base/callback.h"
[email protected]64e199252012-04-06 01:54:369#include "chromeos/dbus/dbus_thread_manager.h"
10#include "chromeos/dbus/power_manager_client.h"
[email protected]7bf59022011-09-08 21:24:2111
12void CalculateIdleStateNotifier(unsigned int idle_treshold,
13 IdleCallback notify,
14 int64_t idle_time_s) {
15 if (idle_time_s >= (int64_t)idle_treshold) {
16 notify.Run(IDLE_STATE_IDLE);
17 } else if (idle_time_s < 0) {
18 notify.Run(IDLE_STATE_UNKNOWN);
19 } else {
20 notify.Run(IDLE_STATE_ACTIVE);
21 }
22}
23
24void CalculateIdleState(unsigned int idle_threshold, IdleCallback notify) {
[email protected]360e7a02011-11-15 22:24:5125 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
26 CalculateIdleTime(base::Bind(&CalculateIdleStateNotifier, idle_threshold,
27 notify));
[email protected]7bf59022011-09-08 21:24:2128}
[email protected]80722b22011-09-10 07:54:5029
30bool CheckIdleStateIsLocked() {
[email protected]0b5758b2011-09-16 22:16:4431 // Usually the screensaver is used to lock the screen, so we do not need to
32 // check if the workstation is locked.
[email protected]64e199252012-04-06 01:54:3633 // TODO(oshima): Verify if this behavior is correct.
[email protected]042d6992011-09-20 18:09:4734 return false;
[email protected]80722b22011-09-10 07:54:5035}