OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/idle.h" | 5 #include "chrome/browser/idle.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "chrome/browser/chromeos/cros/cros_library.h" | 9 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
10 #include "chrome/browser/chromeos/cros/power_library.h" | 10 #include "chrome/browser/chromeos/dbus/power_manager_client.h" |
11 #if !defined(USE_AURA) | 11 #if !defined(USE_AURA) |
12 #include "chrome/browser/screensaver_window_finder_gtk.h" | 12 #include "chrome/browser/screensaver_window_finder_gtk.h" |
13 #endif | 13 #endif |
14 | 14 |
15 void CalculateIdleStateNotifier(unsigned int idle_treshold, | 15 void CalculateIdleStateNotifier(unsigned int idle_treshold, |
16 IdleCallback notify, | 16 IdleCallback notify, |
17 int64_t idle_time_s) { | 17 int64_t idle_time_s) { |
18 if (idle_time_s >= (int64_t)idle_treshold) { | 18 if (idle_time_s >= (int64_t)idle_treshold) { |
19 notify.Run(IDLE_STATE_IDLE); | 19 notify.Run(IDLE_STATE_IDLE); |
20 } else if (idle_time_s < 0) { | 20 } else if (idle_time_s < 0) { |
21 notify.Run(IDLE_STATE_UNKNOWN); | 21 notify.Run(IDLE_STATE_UNKNOWN); |
22 } else { | 22 } else { |
23 notify.Run(IDLE_STATE_ACTIVE); | 23 notify.Run(IDLE_STATE_ACTIVE); |
24 } | 24 } |
25 } | 25 } |
26 | 26 |
27 void CalculateIdleState(unsigned int idle_threshold, IdleCallback notify) { | 27 void CalculateIdleState(unsigned int idle_threshold, IdleCallback notify) { |
28 if (CheckIdleStateIsLocked()) { | 28 if (CheckIdleStateIsLocked()) { |
29 notify.Run(IDLE_STATE_LOCKED); | 29 notify.Run(IDLE_STATE_LOCKED); |
30 return; | 30 return; |
31 } | 31 } |
32 chromeos::CalculateIdleTimeCallback* callback = | 32 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
33 new base::Callback<void(int64_t)>(base::Bind(&CalculateIdleStateNotifier, | 33 CalculateIdleTime(base::Bind(&CalculateIdleStateNotifier, idle_threshold, |
34 idle_threshold, | 34 notify)); |
35 notify)); | |
36 chromeos::CrosLibrary::Get()->GetPowerLibrary()->CalculateIdleTime(callback); | |
37 } | 35 } |
38 | 36 |
39 bool CheckIdleStateIsLocked() { | 37 bool CheckIdleStateIsLocked() { |
40 // Usually the screensaver is used to lock the screen, so we do not need to | 38 // Usually the screensaver is used to lock the screen, so we do not need to |
41 // check if the workstation is locked. | 39 // check if the workstation is locked. |
42 #if defined(USE_AURA) | 40 #if defined(USE_AURA) |
43 return false; | 41 return false; |
44 #else | 42 #else |
45 return ScreensaverWindowFinder::ScreensaverWindowExists(); | 43 return ScreensaverWindowFinder::ScreensaverWindowExists(); |
46 #endif | 44 #endif |
47 } | 45 } |
OLD | NEW |