Maintain timer ordering when alignment is used
commit38b2bf7233694f699b9ad58393a636d7b17981f8
authorskyostil@chromium.org <skyostil@chromium.org>
Fri, 17 Jul 2015 16:46:34 +0000 (17 16:46 +0000)
committerskyostil@chromium.org <skyostil@chromium.org>
Fri, 17 Jul 2015 16:46:34 +0000 (17 16:46 +0000)
tree5fad0ef5230ed42820b9996a568e0848b70872ee
parentf3ce01c6bd66d3b46cb319a3b7ac63356cb58659
Maintain timer ordering when alignment is used

Prior to this patch, timers were not getting executed in the correct
order when timer alignment was turned on (e.g., for background tabs).
This was because of two reasons:

1. Timers were scheduled by computing the delay from the current time to
   the desired run time and passing that delay to the platform layer.
   When alignment is enabled, all timers are trying to aim for the exact
   same point in time. This meant that the timers were getting scheduled
   with delays that were very close to each other, leading to a random
   order of execution.

2. When the alignment timer alignment was changed, each timer was getting
   rescheduled in random order. This meant that timers that were
   targeting the same aligned time would again be executed in a random
   order.

This patch fixes the first problem by passing the desired run time
instead of the delay to the platform layer. This enables the platform
to consistently schedule timers for the same point in time based on
their posted order.

The second problem is fixed by rescheduling timers in the order of their
desired run time when the timer alignment changes.

Note that the Chromium side patch which implements postTimerTaskAt
needs to land before this one.

BUG=508279
TEST=fast/dom/timers-maintain-order-while-throttled.html

Review URL: https://codereview.chromium.org/1227403005

git-svn-id: svn://svn.chromium.org/blink/trunk@199114 bbb929c8-8fbe-4397-9dbb-9b2b20218538
third_party/WebKit/LayoutTests/fast/dom/timers-maintain-order-while-throttled-expected.txt [new file with mode: 0644]
third_party/WebKit/LayoutTests/fast/dom/timers-maintain-order-while-throttled.html [new file with mode: 0644]
third_party/WebKit/Source/core/frame/DOMTimerCoordinator.cpp
third_party/WebKit/Source/platform/Timer.cpp
third_party/WebKit/Source/platform/Timer.h
third_party/WebKit/Source/platform/TimerTest.cpp
third_party/WebKit/public/platform/WebScheduler.h