OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
Lei Zhang
2014/02/11 22:13:59
also 2014, no (c)
rkc
2014/02/11 22:37:38
Fixed, also fixed the year since its a new file -
| |
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 "chrome/browser/chromeos/idle_detector.h" | |
6 | |
7 #include "ash/shell.h" | |
8 #include "ash/wm/user_activity_detector.h" | |
9 #include "base/bind.h" | |
10 #include "base/lazy_instance.h" | |
Lei Zhang
2014/02/11 22:13:59
not used
rkc
2014/02/11 22:37:38
Done.
| |
11 #include "base/logging.h" | |
12 #include "base/message_loop/message_loop.h" | |
Lei Zhang
2014/02/11 22:13:59
not used? probably #include "base/location.h" inst
rkc
2014/02/11 22:37:38
Done.
| |
13 | |
14 namespace chromeos { | |
15 | |
16 IdleDetector::IdleDetector(const base::Closure& on_active_callback, | |
17 const base::Closure& on_idle_callback) | |
18 : active_callback_(on_active_callback), idle_callback_(on_idle_callback) {} | |
19 | |
20 IdleDetector::~IdleDetector() { | |
21 if (ash::Shell::HasInstance() && | |
22 ash::Shell::GetInstance()->user_activity_detector()->HasObserver(this)) | |
23 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); | |
24 } | |
25 | |
26 void IdleDetector::OnUserActivity(const ui::Event* event) { | |
27 if (!active_callback_.is_null()) | |
28 active_callback_.Run(); | |
29 ResetTimer(); | |
30 } | |
31 | |
32 void IdleDetector::Start(const base::TimeDelta& timeout) { | |
33 timeout_ = timeout; | |
34 if (!ash::Shell::GetInstance()->user_activity_detector()->HasObserver(this)) | |
35 ash::Shell::GetInstance()->user_activity_detector()->AddObserver(this); | |
36 ResetTimer(); | |
37 } | |
38 | |
39 void IdleDetector::ResetTimer() { | |
40 if (timer_.IsRunning()) { | |
41 timer_.Reset(); | |
42 } else { | |
43 timer_.Start(FROM_HERE, timeout_, idle_callback_); | |
44 } | |
45 } | |
46 | |
47 } // namespace chromeos | |
OLD | NEW |