Index: third_party/WebKit/Source/wtf/CurrentTime.cpp |
diff --git a/third_party/WebKit/Source/wtf/CurrentTime.cpp b/third_party/WebKit/Source/wtf/CurrentTime.cpp |
index 2c284b1416bbd2e461d0fe15e3f0380de229fe6f..0598cd7a088206e90984d57a3573edf10e75aca0 100644 |
--- a/third_party/WebKit/Source/wtf/CurrentTime.cpp |
+++ b/third_party/WebKit/Source/wtf/CurrentTime.cpp |
@@ -30,40 +30,38 @@ |
#include "wtf/CurrentTime.h" |
-namespace WTF { |
- |
-static TimeFunction currentTimeFunction; |
-static TimeFunction monotonicallyIncreasingTimeFunction; |
-static TimeFunction systemTraceTimeFunction; |
+#include "base/time/time.h" |
-void setCurrentTimeFunction(TimeFunction func) |
-{ |
- currentTimeFunction = func; |
-} |
- |
-void setMonotonicallyIncreasingTimeFunction(TimeFunction func) |
-{ |
- monotonicallyIncreasingTimeFunction = func; |
-} |
+namespace WTF { |
-void setSystemTraceTimeFunction(TimeFunction func) |
-{ |
- systemTraceTimeFunction = func; |
-} |
+static TimeFunction mockTimeFunctionForTesting = nullptr; |
double currentTime() |
{ |
- return (*currentTimeFunction)(); |
+ if (mockTimeFunctionForTesting) |
+ return mockTimeFunctionForTesting(); |
+ return base::Time::Now().ToDoubleT(); |
} |
double monotonicallyIncreasingTime() |
{ |
- return (*monotonicallyIncreasingTimeFunction)(); |
+ if (mockTimeFunctionForTesting) |
+ return mockTimeFunctionForTesting(); |
+ return base::TimeTicks::Now().ToInternalValue() / static_cast<double>(base::Time::kMicrosecondsPerSecond); |
} |
double systemTraceTime() |
{ |
- return (*systemTraceTimeFunction)(); |
+ if (mockTimeFunctionForTesting) |
+ return mockTimeFunctionForTesting(); |
+ return (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); |
+} |
+ |
+TimeFunction setTimeFunctionsForTesting(TimeFunction newFunction) |
+{ |
+ TimeFunction oldFunction = mockTimeFunctionForTesting; |
+ mockTimeFunctionForTesting = newFunction; |
+ return oldFunction; |
} |
} // namespace WTF |