Add an --enable-container-culling commandline flag.
[chromium-blink-merge.git] / chrome / browser / chromeos / idle_detector.cc
blob12e80c74c71b4c6e09f2b394f3e471beadb603e4
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.
5 #include "chrome/browser/chromeos/idle_detector.h"
7 #include "ash/shell.h"
8 #include "base/bind.h"
9 #include "base/logging.h"
10 #include "ui/wm/core/user_activity_detector.h"
12 namespace chromeos {
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) {}
18 IdleDetector::~IdleDetector() {
19 if (ash::Shell::HasInstance() &&
20 ash::Shell::GetInstance()->user_activity_detector()->HasObserver(this))
21 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this);
24 void IdleDetector::OnUserActivity(const ui::Event* event) {
25 if (!active_callback_.is_null())
26 active_callback_.Run();
27 ResetTimer();
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();
37 void IdleDetector::ResetTimer() {
38 if (timer_.IsRunning())
39 timer_.Reset();
40 else
41 timer_.Start(FROM_HERE, timeout_, idle_callback_);
44 } // namespace chromeos