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

Unified Diff: ui/events/x/events_x_utils.cc

Issue 1982203002: Replace DCHECK() upon unexpected x11 event time with a workaround (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/x/events_x_utils.cc
diff --git a/ui/events/x/events_x_utils.cc b/ui/events/x/events_x_utils.cc
index aab272373068313cf5ae95cd5fbb27b34fa12287..a0abd325046414396427db72b8a84b65bbf5153e 100644
--- a/ui/events/x/events_x_utils.cc
+++ b/ui/events/x/events_x_utils.cc
@@ -306,11 +306,13 @@ bool GetGestureTimes(const XEvent& xev, double* start_time, double* end_time) {
return true;
}
+namespace {
int64_t g_last_seen_timestamp_ms = 0;
-// accumulated rollover time.
int64_t g_rollover_ms = 0;
+bool g_bogus_x11_timestamps = false;
base::LazyInstance<std::unique_ptr<base::TickClock>>::Leaky g_tick_clock =
LAZY_INSTANCE_INITIALIZER;
+} // namespace
// Takes Xlib Time and returns a time delta that is immune to timer rollover.
// This function is not thread safe as we do not use a lock.
@@ -320,6 +322,11 @@ base::TimeDelta TimeDeltaFromXEventTime(Time timestamp) {
if (!timestamp)
return base::TimeDelta();
+ if (g_bogus_x11_timestamps) {
+ return base::TimeDelta::FromMilliseconds(
+ (base::TimeTicks::Now() - base::TimeTicks()).InMilliseconds());
majidvp 2016/05/17 13:27:53 Please use ui::EventTimeForNow() instead. I don't
caseq 2016/05/20 23:41:33 Done.
+ }
+
// If this is the first event that we get, assume the time stamp roll-over
// might have happened before the process was started.
// Register a rollover if the distance between last timestamp and current one
@@ -343,11 +350,13 @@ base::TimeDelta TimeDeltaFromXEventTime(Time timestamp) {
g_rollover_ms = now_ms & ~static_cast<int64_t>(UINT32_MAX);
uint32_t delta = static_cast<uint32_t>(now_ms - timestamp);
- // If using a mock clock, all bets are off -- in some tests, actual X11 events
- // come through with real timestamps.
- DCHECK(delta < 60 * 1000 || g_tick_clock.Get() != nullptr)
- << "Unexpected X11 event time, now: " << now_ticks
- << " event at: " << timestamp;
+ if (delta > 60 * 1000 && !g_tick_clock.Get()) {
+ // x11 timestamps don't seem to be using the same time base as TimeTicks,
+ // so ignore them altogether and always use current time instead.
+ delta = 0;
+ g_bogus_x11_timestamps = true;
+ LOG(WARNING) << "Unexpected x11 timestamps, will use browser time instead.";
majidvp 2016/05/17 13:27:53 I wonder if it makes sense to also collect UMA met
caseq 2016/05/20 23:41:33 Done.
+ }
return base::TimeDelta::FromMilliseconds(now_ms - delta);
}
@@ -813,6 +822,7 @@ void ResetTimestampRolloverCountersForTesting(
std::unique_ptr<base::TickClock> tick_clock) {
g_last_seen_timestamp_ms = 0;
g_rollover_ms = 0;
+ g_bogus_x11_timestamps = false;
g_tick_clock.Get() = std::move(tick_clock);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698