Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(867)

Unified Diff: chrome/browser/chromeos/idle_detector.cc

Issue 156493004: Add the ability to show a demo app on OOBE if a machine is derelict. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/idle_detector.cc
diff --git a/chrome/browser/chromeos/idle_detector.cc b/chrome/browser/chromeos/idle_detector.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a4391667ca5e110992b9aeaa03efc5f76e290d07
--- /dev/null
+++ b/chrome/browser/chromeos/idle_detector.cc
@@ -0,0 +1,45 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/idle_detector.h"
+
+#include "ash/shell.h"
+#include "ash/wm/user_activity_detector.h"
+#include "base/bind.h"
bartfab (slow) 2014/02/13 19:51:53 Nit: Not used.
rkc 2014/02/13 23:22:01 Done.
+#include "base/logging.h"
bartfab (slow) 2014/02/13 19:51:53 Nit: Not used.
rkc 2014/02/13 23:22:01 Done.
+
+namespace chromeos {
+
+IdleDetector::IdleDetector(const base::Closure& on_active_callback,
+ const base::Closure& on_idle_callback)
+ : active_callback_(on_active_callback), idle_callback_(on_idle_callback) {}
+
+IdleDetector::~IdleDetector() {
+ 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.
+ ash::Shell::GetInstance()->user_activity_detector()->HasObserver(this))
+ ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this);
+}
+
+void IdleDetector::OnUserActivity(const ui::Event* event) {
+ if (!active_callback_.is_null())
+ active_callback_.Run();
+ ResetTimer();
+}
+
+void IdleDetector::Start(const base::TimeDelta& timeout) {
+ timeout_ = timeout;
+ if (!ash::Shell::GetInstance()->user_activity_detector()->HasObserver(this))
+ ash::Shell::GetInstance()->user_activity_detector()->AddObserver(this);
+ ResetTimer();
+}
+
+void IdleDetector::ResetTimer() {
+ 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.
+ timer_.Reset();
+ } else {
+ 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.
+ }
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698