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 be04deebaddd2b187669d106a74b2180f1240e78..250851067f916e0366c1dfc4709ed73acf2414c9 100644 |
--- a/ui/events/x/events_x_utils.cc |
+++ b/ui/events/x/events_x_utils.cc |
@@ -13,7 +13,6 @@ |
#include <X11/Xutil.h> |
#include <cmath> |
-#include "base/lazy_instance.h" |
#include "base/logging.h" |
#include "base/macros.h" |
#include "base/memory/singleton.h" |
@@ -310,9 +309,6 @@ bool GetGestureTimes(const XEvent& xev, double* start_time, double* end_time) { |
int64_t g_last_seen_timestamp_ms = 0; |
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; |
// 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,10 +316,7 @@ base::TimeTicks TimeTicksFromXEventTime(Time timestamp) { |
int64_t timestamp64 = timestamp; |
if (!timestamp) |
- return base::TimeTicks(); |
- |
- if (g_bogus_x11_timestamps) |
- return base::TimeTicks::Now(); |
+ return ui::EventTimeForNow(); |
// If this is the first event that we get, assume the time stamp roll-over |
// might have happened before the process was started. |
@@ -337,31 +330,16 @@ base::TimeTicks TimeTicksFromXEventTime(Time timestamp) { |
g_last_seen_timestamp_ms = timestamp64; |
if (!had_recent_rollover) |
return base::TimeTicks() + |
- base::TimeDelta::FromMilliseconds(g_rollover_ms + timestamp); |
+ base::TimeDelta::FromMilliseconds(g_rollover_ms + timestamp); |
DCHECK(timestamp64 <= UINT32_MAX) |
<< "X11 Time does not roll over 32 bit, the below logic is likely wrong"; |
- base::TimeTicks now_ticks = g_tick_clock.Get() != nullptr |
- ? g_tick_clock.Get()->NowTicks() |
- : base::TimeTicks::Now(); |
+ base::TimeTicks now_ticks = ui::EventTimeForNow(); |
int64_t now_ms = (now_ticks - base::TimeTicks()).InMilliseconds(); |
g_rollover_ms = now_ms & ~static_cast<int64_t>(UINT32_MAX); |
uint32_t delta = static_cast<uint32_t>(now_ms - timestamp); |
- if (!g_tick_clock.Get()) { |
- if (delta > 60 * 1000) { |
- // 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."; |
- } |
- UMA_HISTOGRAM_BOOLEAN("Event.TimestampHasValidTimebase", |
- !g_bogus_x11_timestamps); |
- } |
- |
return base::TimeTicks() + base::TimeDelta::FromMilliseconds(now_ms - delta); |
} |
@@ -826,8 +804,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); |
+ SetEventTickClockForTesting(std::move(tick_clock)); |
} |
} // namespace ui |