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

Unified Diff: ash/wm/user_activity_detector.cc

Issue 10544011: chromeos: Notify power manager about user activity. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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: ash/wm/user_activity_detector.cc
diff --git a/ash/wm/user_activity_detector.cc b/ash/wm/user_activity_detector.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cff36296e1e5e876d98dfd57fee0c155933c1402
--- /dev/null
+++ b/ash/wm/user_activity_detector.cc
@@ -0,0 +1,59 @@
+// Copyright (c) 2012 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 "ash/wm/user_activity_detector.h"
+
+namespace ash {
+
+const double UserActivityDetector::kNotifyIntervalSec = 1.0;
+
+UserActivityDetector::UserActivityDetector() {
+}
+
+UserActivityDetector::~UserActivityDetector() {
+}
+
+void UserActivityDetector::AddObserver(UserActivityObserver* observer) {
+ observers_.AddObserver(observer);
+}
+
+void UserActivityDetector::RemoveObserver(UserActivityObserver* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+bool UserActivityDetector::PreHandleKeyEvent(
+ aura::Window* target, aura::KeyEvent* event) {
+ MaybeNotify();
+ return false;
+}
+
+bool UserActivityDetector::PreHandleMouseEvent(
+ aura::Window* target, aura::MouseEvent* event) {
+ MaybeNotify();
+ return false;
+}
+
+ui::TouchStatus UserActivityDetector::PreHandleTouchEvent(
+ aura::Window* target, aura::TouchEvent* event) {
+ MaybeNotify();
+ return ui::TOUCH_STATUS_UNKNOWN;
+}
+
+ui::GestureStatus UserActivityDetector::PreHandleGestureEvent(
+ aura::Window* target, aura::GestureEvent* event) {
+ MaybeNotify();
+ return ui::GESTURE_STATUS_UNKNOWN;
+}
+
+void UserActivityDetector::MaybeNotify() {
+ base::TimeTicks now = base::TimeTicks::Now();
+ if (last_observer_notification_time_.is_null() ||
+ (now - last_observer_notification_time_).InSecondsF() >=
+ kNotifyIntervalSec) {
+ FOR_EACH_OBSERVER(UserActivityObserver, observers_, OnUserActivity());
+ last_observer_notification_time_ = now;
+ }
+}
+
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698