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

Unified Diff: components/mus/ws/user_activity_monitor.h

Issue 2094933003: mus: Add UserActivityMonitor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 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
« no previous file with comments | « components/mus/ws/test_utils.h ('k') | components/mus/ws/user_activity_monitor.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/mus/ws/user_activity_monitor.h
diff --git a/components/mus/ws/user_activity_monitor.h b/components/mus/ws/user_activity_monitor.h
new file mode 100644
index 0000000000000000000000000000000000000000..f490a6dfdfb4ee98bfe26f691312ff23cd2fed25
--- /dev/null
+++ b/components/mus/ws/user_activity_monitor.h
@@ -0,0 +1,82 @@
+// Copyright 2016 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.
+
+#ifndef COMPONENTS_MUS_WS_USER_ACTIVITY_MONITOR_H_
+#define COMPONENTS_MUS_WS_USER_ACTIVITY_MONITOR_H_
+
+#include "base/time/tick_clock.h"
+#include "base/time/time.h"
+#include "base/timer/timer.h"
+#include "components/mus/public/interfaces/user_activity_monitor.mojom.h"
+#include "mojo/public/cpp/bindings/binding_set.h"
+#include "mojo/public/cpp/bindings/interface_ptr_set.h"
+
+namespace mus {
+namespace ws {
+
+namespace test {
+class UserActivityMonitorTestApi;
+}
+
+class UserActivityMonitor : public mojom::UserActivityMonitor {
+ public:
+ // |now_clock| is used to get the timestamp. If |now_clock| is nullptr, then
+ // DefaultTickClock is used.
+ explicit UserActivityMonitor(std::unique_ptr<base::TickClock> now_clock);
+ ~UserActivityMonitor() override;
+
+ // Should be called whenever some input event is received from the user.
+ void OnUserActivity();
+
+ // Provides an implementation for the remote request.
+ void Add(mojom::UserActivityMonitorRequest request);
+
+ // mojom::UserActivityMonitor:
+ void AddUserActivityObserver(
+ uint32_t delay_between_notify_secs,
+ mojom::UserActivityObserverPtr observer) override;
+ void AddUserIdleObserver(uint32_t idleness_in_minutes,
+ mojom::UserIdleObserverPtr observer) override;
+
+ private:
+ friend class test::UserActivityMonitorTestApi;
+
+ // Makes sure the idle timer is running.
+ void ActivateIdleTimer();
+
+ // Called every minute when |idle_timer_| is active.
+ void OnMinuteTimer();
+
+ void OnActivityObserverDisconnected(mojom::UserActivityObserver* observer);
+ void OnIdleObserverDisconnected(mojom::UserIdleObserver* observer);
+
+ mojo::BindingSet<mojom::UserActivityMonitor> bindings_;
+ std::unique_ptr<base::TickClock> now_clock_;
+
+ struct ActivityObserverInfo {
+ base::TimeTicks last_activity_notification;
+ base::TimeDelta delay;
+ };
+ std::vector<std::pair<ActivityObserverInfo, mojom::UserActivityObserverPtr>>
+ activity_observers_;
+
+ struct IdleObserverInfo {
+ base::TimeTicks last_idle_state_notification;
+ base::TimeDelta idle_duration;
+ mojom::UserIdleObserver::IdleState idle_state;
+ };
+ std::vector<std::pair<IdleObserverInfo, mojom::UserIdleObserverPtr>>
+ idle_observers_;
+ // Timer used to determine user's idleness. The timer is run only when at
+ // least one of the idle-observers are notified ACTIVE.
+ base::RepeatingTimer idle_timer_;
+ base::TimeTicks last_activity_;
+
+ DISALLOW_COPY_AND_ASSIGN(UserActivityMonitor);
+};
+
+} // namespace ws
+} // namespace mus
+
+#endif // COMPONENTS_MUS_WS_USER_ACTIVITY_MONITOR_H_
« no previous file with comments | « components/mus/ws/test_utils.h ('k') | components/mus/ws/user_activity_monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698