Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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" | |
|
bartfab (slow)
2014/02/13 19:51:53
Nit: Not used.
rkc
2014/02/13 23:22:01
Done.
| |
| 10 #include "base/logging.h" | |
|
bartfab (slow)
2014/02/13 19:51:53
Nit: Not used.
rkc
2014/02/13 23:22:01
Done.
| |
| 11 | |
| 12 namespace chromeos { | |
| 13 | |
| 14 IdleDetector::IdleDetector(const base::Closure& on_active_callback, | |
| 15 const base::Closure& on_idle_callback) | |
| 16 : active_callback_(on_active_callback), idle_callback_(on_idle_callback) {} | |
| 17 | |
| 18 IdleDetector::~IdleDetector() { | |
| 19 if (ash::Shell::HasInstance() && | |
|
bartfab (slow)
2014/02/13 19:51:53
Nit: Multi-line ifs should have curly braces.
rkc
2014/02/13 23:22:01
Done.
| |
| 20 ash::Shell::GetInstance()->user_activity_detector()->HasObserver(this)) | |
| 21 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); | |
| 22 } | |
| 23 | |
| 24 void IdleDetector::OnUserActivity(const ui::Event* event) { | |
| 25 if (!active_callback_.is_null()) | |
| 26 active_callback_.Run(); | |
| 27 ResetTimer(); | |
| 28 } | |
| 29 | |
| 30 void IdleDetector::Start(const base::TimeDelta& timeout) { | |
| 31 timeout_ = timeout; | |
| 32 if (!ash::Shell::GetInstance()->user_activity_detector()->HasObserver(this)) | |
| 33 ash::Shell::GetInstance()->user_activity_detector()->AddObserver(this); | |
| 34 ResetTimer(); | |
| 35 } | |
| 36 | |
| 37 void IdleDetector::ResetTimer() { | |
| 38 if (timer_.IsRunning()) { | |
|
bartfab (slow)
2014/02/13 19:51:53
Nit: No need for curly braces in single-line ifs.
rkc
2014/02/13 23:22:01
Done.
| |
| 39 timer_.Reset(); | |
| 40 } else { | |
| 41 timer_.Start(FROM_HERE, timeout_, idle_callback_); | |
|
bartfab (slow)
2014/02/13 19:51:53
Nit: #include "base/location.h"
rkc
2014/02/13 23:22:01
Done.
| |
| 42 } | |
| 43 } | |
| 44 | |
| 45 } // namespace chromeos | |
| OLD | NEW |