提交 fa57fe28 编写于 作者: A Adam Barth

WTF should get time from base directly

There's no reason to bounce through several indirections to get the current
time.  We can just call into base directly now.

R=ojan@chromium.org

Review URL: https://codereview.chromium.org/887883002
上级 05137682
......@@ -39,11 +39,6 @@
#include "sky/engine/wtf/MainThread.h"
#include "sky/engine/wtf/WTF.h"
static double CurrentTime()
{
return 0.0;
}
static void AlwaysZeroNumberSource(unsigned char* buf, size_t len)
{
memset(buf, '\0', len);
......@@ -52,7 +47,7 @@ static void AlwaysZeroNumberSource(unsigned char* buf, size_t len)
int main(int argc, char** argv)
{
WTF::setRandomSource(AlwaysZeroNumberSource);
WTF::initialize(CurrentTime, 0);
WTF::initialize();
WTF::initializeMainThread();
blink::TestingPlatformSupport::Config platformConfig;
......
......@@ -132,16 +132,6 @@ v8::Isolate* mainThreadIsolate()
return V8PerIsolateData::mainThreadIsolate();
}
static double currentTimeFunction()
{
return Platform::current()->currentTime();
}
static double monotonicallyIncreasingTimeFunction()
{
return Platform::current()->monotonicallyIncreasingTime();
}
static void cryptographicallyRandomValues(unsigned char* buffer, size_t length)
{
base::RandBytes(buffer, length);
......@@ -156,7 +146,7 @@ void initializeWithoutV8(Platform* platform)
Platform::initialize(platform);
WTF::setRandomSource(cryptographicallyRandomValues);
WTF::initialize(currentTimeFunction, monotonicallyIncreasingTimeFunction);
WTF::initialize();
WTF::initializeMainThread();
DEFINE_STATIC_LOCAL(CoreInitializer, initializer, ());
......
......@@ -28,32 +28,21 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "base/time/time.h"
#include "sky/engine/config.h"
#include "sky/engine/wtf/CurrentTime.h"
namespace WTF {
static TimeFunction currentTimeFunction;
static TimeFunction monotonicallyIncreasingTimeFunction;
void setCurrentTimeFunction(TimeFunction func)
{
currentTimeFunction = func;
}
void setMonotonicallyIncreasingTimeFunction(TimeFunction func)
{
monotonicallyIncreasingTimeFunction = func;
}
double currentTime()
{
return (*currentTimeFunction)();
return base::Time::Now().ToDoubleT();
}
double monotonicallyIncreasingTime()
{
return (*monotonicallyIncreasingTimeFunction)();
return base::TimeTicks::Now().ToInternalValue() /
static_cast<double>(base::Time::kMicrosecondsPerSecond);
}
} // namespace WTF
......@@ -52,9 +52,6 @@ inline double currentTimeMS()
WTF_EXPORT double monotonicallyIncreasingTime();
typedef double(*TimeFunction)(void);
void setCurrentTimeFunction(TimeFunction);
void setMonotonicallyIncreasingTimeFunction(TimeFunction);
} // namespace WTF
......
......@@ -43,7 +43,7 @@ bool s_shutdown;
bool Partitions::s_initialized;
PartitionAllocatorGeneric Partitions::m_bufferAllocator;
void initialize(TimeFunction currentTimeFunction, TimeFunction monotonicallyIncreasingTimeFunction)
void initialize()
{
// WTF, and Blink in general, cannot handle being re-initialized, even if shutdown first.
// Make that explicit here.
......@@ -51,8 +51,6 @@ void initialize(TimeFunction currentTimeFunction, TimeFunction monotonicallyIncr
ASSERT(!s_shutdown);
s_initialized = true;
Partitions::initialize();
setCurrentTimeFunction(currentTimeFunction);
setMonotonicallyIncreasingTimeFunction(monotonicallyIncreasingTimeFunction);
initializeThreading();
}
......
......@@ -39,7 +39,7 @@
namespace WTF {
// This function must be called exactly once from the main thread before using anything else in WTF.
WTF_EXPORT void initialize(TimeFunction currentTimeFunction, TimeFunction monotonicallyIncreasingTimeFunction);
WTF_EXPORT void initialize();
WTF_EXPORT void shutdown();
WTF_EXPORT bool isShutdown();
......
......@@ -36,11 +36,6 @@
#include "sky/engine/wtf/MainThread.h"
#include "sky/engine/wtf/WTF.h"
static double CurrentTime()
{
return 0.0;
}
static void AlwaysZeroNumberSource(unsigned char* buf, size_t len)
{
memset(buf, '\0', len);
......@@ -49,7 +44,7 @@ static void AlwaysZeroNumberSource(unsigned char* buf, size_t len)
int main(int argc, char** argv)
{
WTF::setRandomSource(AlwaysZeroNumberSource);
WTF::initialize(CurrentTime, 0);
WTF::initialize();
WTF::initializeMainThread();
return base::RunUnitTestsUsingBaseTestSuite(argc, argv);
}
......@@ -59,22 +59,16 @@ blink::WebString PlatformImpl::defaultLocale() {
return blink::WebString::fromUTF8("en-US");
}
double PlatformImpl::currentTime() {
return base::Time::Now().ToDoubleT();
}
double PlatformImpl::monotonicallyIncreasingTime() {
return base::TimeTicks::Now().ToInternalValue() /
static_cast<double>(base::Time::kMicrosecondsPerSecond);
}
void PlatformImpl::setSharedTimerFiredFunction(void (*func)()) {
shared_timer_func_ = func;
}
void PlatformImpl::setSharedTimerFireInterval(
double interval_seconds) {
shared_timer_fire_time_ = interval_seconds + monotonicallyIncreasingTime();
double now = base::TimeTicks::Now().ToInternalValue() /
static_cast<double>(base::Time::kMicrosecondsPerSecond);
shared_timer_fire_time_ = interval_seconds + now;
if (shared_timer_suspended_) {
shared_timer_fire_time_was_set_while_suspended_ = true;
return;
......
......@@ -25,8 +25,6 @@ class PlatformImpl : public blink::Platform {
// blink::Platform methods:
virtual blink::WebString defaultLocale();
virtual double currentTime();
virtual double monotonicallyIncreasingTime();
virtual void setSharedTimerFiredFunction(void (*func)());
virtual void setSharedTimerFireInterval(double interval_seconds);
virtual void stopSharedTimer();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册