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

Unified Diff: ui/events/base_event_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/base_event_utils.h ('k') | ui/events/cocoa/events_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/base_event_utils.cc
diff --git a/ui/events/base_event_utils.cc b/ui/events/base_event_utils.cc
index c8eacb161b95d28604e0aef8df2efb28ba1034b8..d4545bc45c4560dddc39c2c217a5e0045dd39914 100644
--- a/ui/events/base_event_utils.cc
+++ b/ui/events/base_event_utils.cc
@@ -6,6 +6,7 @@
#include "base/atomic_sequence_num.h"
#include "base/command_line.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/time/time.h"
#include "build/build_config.h"
@@ -43,6 +44,18 @@ bool IsSystemKeyModifier(int flags) {
(EF_ALTGR_DOWN & flags) == 0;
}
+base::LazyInstance<std::unique_ptr<base::TickClock>>::Leaky g_tick_clock =
+ LAZY_INSTANCE_INITIALIZER;
+
+base::TimeTicks EventTimeForNow() {
+ return g_tick_clock.Get() ? g_tick_clock.Get()->NowTicks()
+ : base::TimeTicks::Now();
+}
+
+void SetEventTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock) {
+ g_tick_clock.Get() = std::move(tick_clock);
+}
+
double EventTimeStampToSeconds(base::TimeTicks time_stamp) {
return (time_stamp - base::TimeTicks()).InSecondsF();
}
« no previous file with comments | « ui/events/base_event_utils.h ('k') | ui/events/cocoa/events_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698