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

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

Issue 2007083002: Validate that ui::Event::time_stamp comes from the same clock as TimeTicks::Now (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@453559-use-timeticks-ui-event
Patch Set: Address feedback 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 | « ui/events/x/events_x.cc ('k') | ui/message_center/message_center.gyp » ('j') | 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 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
« no previous file with comments | « ui/events/x/events_x.cc ('k') | ui/message_center/message_center.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698