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

Side by Side Diff: ui/base/user_activity/user_activity_detector.cc

Issue 2639703004: mus: Forward user activity from window server to detector. (Closed)
Patch Set: add comments to UserActivityPowerManagerNotifier Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/base/user_activity/user_activity_detector.h" 5 #include "ui/base/user_activity/user_activity_detector.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // will be reported as user activity and turn the screen back on; too high 46 // will be reported as user activity and turn the screen back on; too high
47 // and we'll ignore legitimate activity. 47 // and we'll ignore legitimate activity.
48 const int UserActivityDetector::kDisplayPowerChangeIgnoreMouseMs = 1000; 48 const int UserActivityDetector::kDisplayPowerChangeIgnoreMouseMs = 1000;
49 49
50 UserActivityDetector::UserActivityDetector() { 50 UserActivityDetector::UserActivityDetector() {
51 CHECK(!g_instance); 51 CHECK(!g_instance);
52 g_instance = this; 52 g_instance = this;
53 53
54 ui::PlatformEventSource* platform_event_source = 54 ui::PlatformEventSource* platform_event_source =
55 ui::PlatformEventSource::GetInstance(); 55 ui::PlatformEventSource::GetInstance();
56 // TODO(sad): Need a PES for mus.
57 if (platform_event_source) 56 if (platform_event_source)
58 platform_event_source->AddPlatformEventObserver(this); 57 platform_event_source->AddPlatformEventObserver(this);
59 } 58 }
60 59
61 UserActivityDetector::~UserActivityDetector() { 60 UserActivityDetector::~UserActivityDetector() {
62 ui::PlatformEventSource* platform_event_source = 61 ui::PlatformEventSource* platform_event_source =
63 ui::PlatformEventSource::GetInstance(); 62 ui::PlatformEventSource::GetInstance();
64 if (platform_event_source) 63 if (platform_event_source)
65 platform_event_source->RemovePlatformEventObserver(this); 64 platform_event_source->RemovePlatformEventObserver(this);
66 g_instance = nullptr; 65 g_instance = nullptr;
(...skipping 15 matching lines...) Expand all
82 81
83 void UserActivityDetector::RemoveObserver(UserActivityObserver* observer) { 82 void UserActivityDetector::RemoveObserver(UserActivityObserver* observer) {
84 observers_.RemoveObserver(observer); 83 observers_.RemoveObserver(observer);
85 } 84 }
86 85
87 void UserActivityDetector::OnDisplayPowerChanging() { 86 void UserActivityDetector::OnDisplayPowerChanging() {
88 honor_mouse_events_time_ = GetCurrentTime() + 87 honor_mouse_events_time_ = GetCurrentTime() +
89 base::TimeDelta::FromMilliseconds(kDisplayPowerChangeIgnoreMouseMs); 88 base::TimeDelta::FromMilliseconds(kDisplayPowerChangeIgnoreMouseMs);
90 } 89 }
91 90
91 void UserActivityDetector::HandleExternalUserActivity() {
92 HandleActivity(nullptr);
93 }
94
92 void UserActivityDetector::DidProcessEvent( 95 void UserActivityDetector::DidProcessEvent(
93 const PlatformEvent& platform_event) { 96 const PlatformEvent& platform_event) {
94 std::unique_ptr<ui::Event> event(ui::EventFromNative(platform_event)); 97 std::unique_ptr<ui::Event> event(ui::EventFromNative(platform_event));
95 ProcessReceivedEvent(event.get()); 98 ProcessReceivedEvent(event.get());
96 } 99 }
97 100
98 base::TimeTicks UserActivityDetector::GetCurrentTime() const { 101 base::TimeTicks UserActivityDetector::GetCurrentTime() const {
99 return !now_for_test_.is_null() ? now_for_test_ : base::TimeTicks::Now(); 102 return !now_for_test_.is_null() ? now_for_test_ : base::TimeTicks::Now();
100 } 103 }
101 104
102 void UserActivityDetector::ProcessReceivedEvent(const ui::Event* event) { 105 void UserActivityDetector::ProcessReceivedEvent(const ui::Event* event) {
103 if (!event) 106 if (!event)
104 return; 107 return;
105 108
106 if (event->IsMouseEvent() || event->IsMouseWheelEvent()) { 109 if (event->IsMouseEvent() || event->IsMouseWheelEvent()) {
107 if (event->flags() & ui::EF_IS_SYNTHESIZED) 110 if (event->flags() & ui::EF_IS_SYNTHESIZED)
108 return; 111 return;
109 if (!honor_mouse_events_time_.is_null() 112 if (!honor_mouse_events_time_.is_null()
110 && GetCurrentTime() < honor_mouse_events_time_) 113 && GetCurrentTime() < honor_mouse_events_time_)
111 return; 114 return;
112 } 115 }
113 116
114 HandleActivity(event); 117 HandleActivity(event);
115 } 118 }
116 119
117 void UserActivityDetector::HandleActivity(const ui::Event* event) { 120 void UserActivityDetector::HandleActivity(const ui::Event* event) {
118 base::TimeTicks now = GetCurrentTime(); 121 base::TimeTicks now = GetCurrentTime();
119 last_activity_time_ = now; 122 last_activity_time_ = now;
120 last_activity_name_ = event->name(); 123 last_activity_name_ = event ? event->name() : "";
sadrul 2017/01/18 22:10:58 s/""/std::string()/
Daniel Erat 2017/01/19 01:56:24 Done.
121 if (last_observer_notification_time_.is_null() || 124 if (last_observer_notification_time_.is_null() ||
122 (now - last_observer_notification_time_).InMillisecondsF() >= 125 (now - last_observer_notification_time_).InMillisecondsF() >=
123 kNotifyIntervalMs) { 126 kNotifyIntervalMs) {
124 if (VLOG_IS_ON(1)) 127 if (VLOG_IS_ON(1) && event)
125 VLOG(1) << "Reporting user activity: " << GetEventDebugString(event); 128 VLOG(1) << "Reporting user activity: " << GetEventDebugString(event);
126 for (UserActivityObserver& observer : observers_) 129 for (UserActivityObserver& observer : observers_)
127 observer.OnUserActivity(event); 130 observer.OnUserActivity(event);
128 last_observer_notification_time_ = now; 131 last_observer_notification_time_ = now;
129 } 132 }
130 } 133 }
131 134
132 } // namespace ui 135 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698