Chromium Code Reviews| 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 c29636f98c9cc551ec735476ecca99893408a8a3..dc64e33663f4e558739a699d96be1a4519a2098d 100644 |
| --- a/third_party/WebKit/Source/wtf/CurrentTime.cpp |
| +++ b/third_party/WebKit/Source/wtf/CurrentTime.cpp |
| @@ -30,29 +30,31 @@ |
| #include "wtf/CurrentTime.h" |
| -namespace WTF { |
| +#include "base/time/time.h" |
| -static TimeFunction currentTimeFunction; |
| -static TimeFunction monotonicallyIncreasingTimeFunction; |
| +namespace WTF { |
| -void setCurrentTimeFunction(TimeFunction func) |
| -{ |
| - currentTimeFunction = func; |
| -} |
| +static TimeFunction mockTimeFunctionForTesting = nullptr; |
| -void setMonotonicallyIncreasingTimeFunction(TimeFunction func) |
| +double currentTime() |
|
haraken
2016/02/09 09:13:58
Given that this method is performance-sensitive, I
Yuta Kitamura
2016/02/09 09:54:56
Hm, that would make mockTimeFunctionForTesting pub
Yuta Kitamura
2016/02/15 07:26:38
According to my local testing, inlining had a nega
|
| { |
| - monotonicallyIncreasingTimeFunction = func; |
| + if (mockTimeFunctionForTesting) |
|
haraken
2016/02/09 09:13:58
I'd add UNLIKELY.
Yuta Kitamura
2016/02/09 09:54:57
I'm almost certain that PGO (profile-guided optimi
tkent
2016/02/10 00:04:39
I agree with yutak.
|
| + return mockTimeFunctionForTesting(); |
| + return base::Time::Now().ToDoubleT(); |
| } |
| -double currentTime() |
| +double monotonicallyIncreasingTime() |
|
haraken
2016/02/09 09:13:58
Ditto.
|
| { |
| - return (*currentTimeFunction)(); |
| + if (mockTimeFunctionForTesting) |
| + return mockTimeFunctionForTesting(); |
| + return base::TimeTicks::Now().ToInternalValue() / static_cast<double>(base::Time::kMicrosecondsPerSecond); |
| } |
| -double monotonicallyIncreasingTime() |
| +TimeFunction setTimeFunctionsForTesting(TimeFunction newFunction) |
| { |
| - return (*monotonicallyIncreasingTimeFunction)(); |
| + TimeFunction oldFunction = mockTimeFunctionForTesting; |
| + mockTimeFunctionForTesting = newFunction; |
| + return oldFunction; |
| } |
| } // namespace WTF |