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

Unified Diff: ui/wm/core/user_activity_detector.cc

Issue 833893003: Move UserActivityDetector to ui/base/user_activity/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: don't build test on android Created 5 years, 11 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 | « ui/wm/core/user_activity_detector.h ('k') | ui/wm/core/user_activity_detector_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/wm/core/user_activity_detector.cc
diff --git a/ui/wm/core/user_activity_detector.cc b/ui/wm/core/user_activity_detector.cc
deleted file mode 100644
index a9f85e8b1cee9a24800e917c44a5bd42c5f3a2a0..0000000000000000000000000000000000000000
--- a/ui/wm/core/user_activity_detector.cc
+++ /dev/null
@@ -1,123 +0,0 @@
-// 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 "ui/wm/core/user_activity_detector.h"
-
-#include "base/format_macros.h"
-#include "base/logging.h"
-#include "base/strings/stringprintf.h"
-#include "ui/events/event.h"
-#include "ui/wm/core/user_activity_observer.h"
-
-namespace wm {
-
-namespace {
-
-UserActivityDetector* g_instance = nullptr;
-
-// Returns a string describing |event|.
-std::string GetEventDebugString(const ui::Event* event) {
- std::string details = base::StringPrintf(
- "type=%d name=%s flags=%d time=%" PRId64,
- event->type(), event->name().c_str(), event->flags(),
- event->time_stamp().InMilliseconds());
-
- if (event->IsKeyEvent()) {
- details += base::StringPrintf(" key_code=%d",
- static_cast<const ui::KeyEvent*>(event)->key_code());
- } else if (event->IsMouseEvent() || event->IsTouchEvent() ||
- event->IsGestureEvent()) {
- details += base::StringPrintf(" location=%s",
- static_cast<const ui::LocatedEvent*>(
- event)->location().ToString().c_str());
- }
-
- return details;
-}
-
-} // namespace
-
-const int UserActivityDetector::kNotifyIntervalMs = 200;
-
-// Too low and mouse events generated at the tail end of reconfiguration
-// will be reported as user activity and turn the screen back on; too high
-// and we'll ignore legitimate activity.
-const int UserActivityDetector::kDisplayPowerChangeIgnoreMouseMs = 1000;
-
-UserActivityDetector::UserActivityDetector() {
- CHECK(!g_instance);
- g_instance = this;
-}
-
-UserActivityDetector::~UserActivityDetector() {
- g_instance = nullptr;
-}
-
-// static
-UserActivityDetector* UserActivityDetector::Get() {
- return g_instance;
-}
-
-bool UserActivityDetector::HasObserver(
- const UserActivityObserver* observer) const {
- return observers_.HasObserver(observer);
-}
-
-void UserActivityDetector::AddObserver(UserActivityObserver* observer) {
- observers_.AddObserver(observer);
-}
-
-void UserActivityDetector::RemoveObserver(UserActivityObserver* observer) {
- observers_.RemoveObserver(observer);
-}
-
-void UserActivityDetector::OnDisplayPowerChanging() {
- honor_mouse_events_time_ = GetCurrentTime() +
- base::TimeDelta::FromMilliseconds(kDisplayPowerChangeIgnoreMouseMs);
-}
-
-void UserActivityDetector::OnKeyEvent(ui::KeyEvent* event) {
- HandleActivity(event);
-}
-
-void UserActivityDetector::OnMouseEvent(ui::MouseEvent* event) {
- if (event->flags() & ui::EF_IS_SYNTHESIZED)
- return;
- if (!honor_mouse_events_time_.is_null() &&
- GetCurrentTime() < honor_mouse_events_time_)
- return;
-
- HandleActivity(event);
-}
-
-void UserActivityDetector::OnScrollEvent(ui::ScrollEvent* event) {
- HandleActivity(event);
-}
-
-void UserActivityDetector::OnTouchEvent(ui::TouchEvent* event) {
- HandleActivity(event);
-}
-
-void UserActivityDetector::OnGestureEvent(ui::GestureEvent* event) {
- HandleActivity(event);
-}
-
-base::TimeTicks UserActivityDetector::GetCurrentTime() const {
- return !now_for_test_.is_null() ? now_for_test_ : base::TimeTicks::Now();
-}
-
-void UserActivityDetector::HandleActivity(const ui::Event* event) {
- base::TimeTicks now = GetCurrentTime();
- last_activity_time_ = now;
- if (last_observer_notification_time_.is_null() ||
- (now - last_observer_notification_time_).InMillisecondsF() >=
- kNotifyIntervalMs) {
- if (VLOG_IS_ON(1))
- VLOG(1) << "Reporting user activity: " << GetEventDebugString(event);
- FOR_EACH_OBSERVER(UserActivityObserver, observers_, OnUserActivity(event));
- last_observer_notification_time_ = now;
- }
-}
-
-} // namespace wm
« no previous file with comments | « ui/wm/core/user_activity_detector.h ('k') | ui/wm/core/user_activity_detector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698