Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 "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" | |
| 11 #include "base/logging.h" | |
| 12 #include "base/message_loop/message_loop.h" | |
| 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 active_callback_.Run(); | |
|
xiyuan
2014/02/11 03:42:45
OnUserActivity is called quite frequently and we s
rkc
2014/02/11 04:35:57
Done.
| |
| 28 ResetTimer(); | |
| 29 } | |
| 30 | |
| 31 void IdleDetector::Start(const base::TimeDelta& timeout) { | |
| 32 timeout_ = timeout; | |
| 33 if (!ash::Shell::GetInstance()->user_activity_detector()->HasObserver(this)) | |
| 34 ash::Shell::GetInstance()->user_activity_detector()->AddObserver(this); | |
| 35 ResetTimer(); | |
| 36 } | |
| 37 | |
| 38 void IdleDetector::ResetTimer() { | |
| 39 if (timer_.IsRunning()) { | |
| 40 timer_.Reset(); | |
| 41 } else { | |
| 42 timer_.Start(FROM_HERE, timeout_, idle_callback_); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 } // namespace chromeos | |
| OLD | NEW |