diff options
-rw-r--r-- | webkit/glue/webkitclient_impl.cc | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/webkit/glue/webkitclient_impl.cc b/webkit/glue/webkitclient_impl.cc index e726a6c..12a4d14 100644 --- a/webkit/glue/webkitclient_impl.cc +++ b/webkit/glue/webkitclient_impl.cc @@ -21,6 +21,66 @@ double WebKitClientImpl::currentTime() { return base::Time::Now().ToDoubleT(); } +// HACK to see if this code impacts the intl1 page cycler +#if defined(OS_WIN) +class SharedTimerTask; + +// We maintain a single active timer and a single active task for +// setting timers directly on the platform. +static SharedTimerTask* shared_timer_task; +static void (*shared_timer_function)(); + +// Timer task to run in the chrome message loop. +class SharedTimerTask : public Task { + public: + SharedTimerTask(void (*callback)()) : callback_(callback) {} + + virtual void Run() { + if (!callback_) + return; + // Since we only have one task running at a time, verify 'this' is it + DCHECK(shared_timer_task == this); + shared_timer_task = NULL; + callback_(); + } + + void Cancel() { + callback_ = NULL; + } + + private: + void (*callback_)(); + DISALLOW_COPY_AND_ASSIGN(SharedTimerTask); +}; + +void WebKitClientImpl::setSharedTimerFiredFunction(void (*func)()) { + shared_timer_function = func; +} + +void WebKitClientImpl::setSharedTimerFireTime(double fire_time) { + DCHECK(shared_timer_function); + int interval = static_cast<int>((fire_time - currentTime()) * 1000); + if (interval < 0) + interval = 0; + + stopSharedTimer(); + + // Verify that we didn't leak the task or timer objects. + DCHECK(shared_timer_task == NULL); + shared_timer_task = new SharedTimerTask(shared_timer_function); + MessageLoop::current()->PostDelayedTask(FROM_HERE, shared_timer_task, + interval); +} + +void WebKitClientImpl::stopSharedTimer() { + if (!shared_timer_task) + return; + shared_timer_task->Cancel(); + shared_timer_task = NULL; +} + +#else + void WebKitClientImpl::setSharedTimerFiredFunction(void (*func)()) { shared_timer_func_ = func; } @@ -39,6 +99,8 @@ void WebKitClientImpl::stopSharedTimer() { shared_timer_.Stop(); } +#endif + void WebKitClientImpl::callOnMainThread(void (*func)()) { main_loop_->PostTask(FROM_HERE, NewRunnableFunction(func)); } |