Title: [175111] branches/safari-600.3-branch/Source/WebCore

Diff

Modified: branches/safari-600.3-branch/Source/WebCore/ChangeLog (175110 => 175111)


--- branches/safari-600.3-branch/Source/WebCore/ChangeLog	2014-10-23 09:28:01 UTC (rev 175110)
+++ branches/safari-600.3-branch/Source/WebCore/ChangeLog	2014-10-23 09:29:10 UTC (rev 175111)
@@ -1,5 +1,49 @@
 2014-10-23  Babak Shafiei  <[email protected]>
 
+        Merge r173208.
+
+    2014-08-29  Gavin Barraclough  <[email protected]>
+
+            Simplify DOMTimer::adjustMinimumTimerInterval -> updateTimerIntervalIfNecessary
+            https://bugs.webkit.org/show_bug.cgi?id=136402
+
+            Reviewed by Andreas Kling.
+
+            When the minimum DOM timer interval changes, the Page updates all DOMTimers accordingly.
+            Updating the fire/repeat interval on TimerBase requires a delta, but in
+            DOMTimer::adjustMinimumTimerInterval we have the new requested interval. In the case of
+            timers we can get the current interval to calculate the delta by calling repeatInterval(),
+            but in the case of one-shot timers neither TimerBase nor DOMTimer have store the interval
+            that was actually set for the timer (DOMTimer knows the original, unadjusted timer, but
+            not the actual interval). The way this currently works is that when the minimum interval
+            changes, Page calls adjustMinimumTimerInterval providing the previous minimum. If the
+            timer is one-shot, then adjustMinimumTimerInterval will use this to compute the delta
+            based on what the interval would have been.
+
+            We can simplify & unify with the code to throttle interval timers when the nesting
+            threshold is hit, by instead tracking the current timer interval as a member on DOMTimer &
+            using this to compute the delta in all cases.
+
+            * dom/ScriptExecutionContext.cpp:
+            (WebCore::ScriptExecutionContext::adjustMinimumTimerInterval):
+                - adjustMinimumTimerInterval -> updateTimerIntervalIfNecessary
+            * page/DOMTimer.cpp:
+            (WebCore::DOMTimer::DOMTimer):
+                initialize m_currentTimerInterval
+            (WebCore::DOMTimer::fired):
+                - when the nesting level changes (potentially triggering throttling) just call updateTimerIntervalIfNecessary
+            (WebCore::DOMTimer::updateTimerIntervalIfNecessary):
+                - compute delta based on m_currentTimerInterval
+            (WebCore::DOMTimer::intervalClampedToMinimum):
+                - this now always takes m_originalInterval and scriptExecutionContext()->minimumTimerInterval()
+                  as its inputs, so remove arguments.
+            (WebCore::DOMTimer::adjustMinimumTimerInterval): Deleted.
+                - adjustMinimumTimerInterval -> updateTimerIntervalIfNecessary
+            * page/DOMTimer.h:
+                - adjustMinimumTimerInterval -> updateTimerIntervalIfNecessary, added m_currentTimerInterval
+
+2014-10-23  Babak Shafiei  <[email protected]>
+
         Merge r173133.
 
     2014-08-29  Gavin Barraclough  <[email protected]>

Modified: branches/safari-600.3-branch/Source/WebCore/dom/ScriptExecutionContext.cpp (175110 => 175111)


--- branches/safari-600.3-branch/Source/WebCore/dom/ScriptExecutionContext.cpp	2014-10-23 09:28:01 UTC (rev 175110)
+++ branches/safari-600.3-branch/Source/WebCore/dom/ScriptExecutionContext.cpp	2014-10-23 09:29:10 UTC (rev 175111)
@@ -418,7 +418,7 @@
 {
     if (minimumTimerInterval() != oldMinimumTimerInterval) {
         for (auto& timer : m_timeouts.values())
-            timer->adjustMinimumTimerInterval(oldMinimumTimerInterval);
+            timer->updateTimerIntervalIfNecessary();
     }
 }
 

Modified: branches/safari-600.3-branch/Source/WebCore/page/DOMTimer.cpp (175110 => 175111)


--- branches/safari-600.3-branch/Source/WebCore/page/DOMTimer.cpp	2014-10-23 09:28:01 UTC (rev 175110)
+++ branches/safari-600.3-branch/Source/WebCore/page/DOMTimer.cpp	2014-10-23 09:29:10 UTC (rev 175111)
@@ -61,6 +61,7 @@
     , m_nestingLevel(context->timerNestingLevel())
     , m_action(WTF::move(action))
     , m_originalInterval(interval)
+    , m_currentTimerInterval(intervalClampedToMinimum())
     , m_shouldForwardUserGesture(shouldForwardUserGesture(interval, m_nestingLevel))
 {
     RefPtr<DOMTimer> reference = adoptRef(this);
@@ -70,11 +71,10 @@
         m_timeoutId = context->circularSequentialID();
     } while (!context->addTimeout(m_timeoutId, reference));
 
-    double intervalMilliseconds = intervalClampedToMinimum(interval, context->minimumTimerInterval());
     if (singleShot)
-        startOneShot(intervalMilliseconds);
+        startOneShot(m_currentTimerInterval);
     else
-        startRepeating(intervalMilliseconds);
+        startRepeating(m_currentTimerInterval);
 }
 
 int DOMTimer::install(ScriptExecutionContext* context, std::unique_ptr<ScheduledAction> action, int timeout, bool singleShot)
@@ -142,12 +142,7 @@
     if (isActive()) {
         if (m_nestingLevel < maxTimerNestingLevel) {
             m_nestingLevel++;
-
-            double minimumInterval = context->minimumTimerInterval();
-            if (repeatInterval() && repeatInterval() < minimumInterval) {
-                if (m_nestingLevel == maxTimerNestingLevel)
-                    augmentRepeatInterval(minimumInterval - repeatInterval());
-            }
+            updateTimerIntervalIfNecessary();
         }
 
         m_action->execute(context);
@@ -201,31 +196,34 @@
     m_action = nullptr;
 }
 
-void DOMTimer::adjustMinimumTimerInterval(double oldMinimumTimerInterval)
+void DOMTimer::updateTimerIntervalIfNecessary()
 {
     ASSERT(m_nestingLevel <= maxTimerNestingLevel);
     if (m_nestingLevel < maxTimerNestingLevel)
         return;
 
-    double newMinimumInterval = scriptExecutionContext()->minimumTimerInterval();
-    double newClampedInterval = intervalClampedToMinimum(m_originalInterval, newMinimumInterval);
+    double previousInterval = m_currentTimerInterval;
+    m_currentTimerInterval = intervalClampedToMinimum();
 
-    if (repeatInterval()) {
-        augmentRepeatInterval(newClampedInterval - repeatInterval());
+    if (previousInterval == m_currentTimerInterval)
         return;
-    }
 
-    double previousClampedInterval = intervalClampedToMinimum(m_originalInterval, oldMinimumTimerInterval);
-    augmentFireInterval(newClampedInterval - previousClampedInterval);
+    if (repeatInterval()) {
+        ASSERT(repeatInterval() == previousInterval);
+        augmentRepeatInterval(m_currentTimerInterval - previousInterval);
+    } else
+        augmentFireInterval(m_currentTimerInterval - previousInterval);
 }
 
-double DOMTimer::intervalClampedToMinimum(int timeout, double minimumTimerInterval) const
+double DOMTimer::intervalClampedToMinimum() const
 {
+    ASSERT(scriptExecutionContext());
     ASSERT(m_nestingLevel <= maxTimerNestingLevel);
 
-    double intervalMilliseconds = std::max(oneMillisecond, timeout * oneMillisecond);
+    double minimumTimerInterval = scriptExecutionContext()->minimumTimerInterval();
+    double intervalMilliseconds = std::max(oneMillisecond, m_originalInterval * oneMillisecond);
 
-    if (intervalMilliseconds < minimumTimerInterval && m_nestingLevel >= maxTimerNestingLevel)
+    if (intervalMilliseconds < minimumTimerInterval && m_nestingLevel == maxTimerNestingLevel)
         intervalMilliseconds = minimumTimerInterval;
     return intervalMilliseconds;
 }

Modified: branches/safari-600.3-branch/Source/WebCore/page/DOMTimer.h (175110 => 175111)


--- branches/safari-600.3-branch/Source/WebCore/page/DOMTimer.h	2014-10-23 09:28:01 UTC (rev 175110)
+++ branches/safari-600.3-branch/Source/WebCore/page/DOMTimer.h	2014-10-23 09:29:10 UTC (rev 175111)
@@ -44,14 +44,13 @@
         static int install(ScriptExecutionContext*, std::unique_ptr<ScheduledAction>, int timeout, bool singleShot);
         static void removeById(ScriptExecutionContext*, int timeoutId);
 
-        // Adjust to a change in the ScriptExecutionContext's minimum timer interval.
-        // This allows the minimum allowable interval time to be changed in response
-        // to events like moving a tab to the background.
-        void adjustMinimumTimerInterval(double oldMinimumTimerInterval);
+        // Notify that the interval may need updating (e.g. because the minimum interval
+        // setting for the context has changed).
+        void updateTimerIntervalIfNecessary();
 
     private:
         DOMTimer(ScriptExecutionContext*, std::unique_ptr<ScheduledAction>, int interval, bool singleShot);
-        double intervalClampedToMinimum(int timeout, double minimumTimerInterval) const;
+        double intervalClampedToMinimum() const;
 
         // SuspendableTimer
         virtual void fired() override;
@@ -62,6 +61,7 @@
         int m_nestingLevel;
         std::unique_ptr<ScheduledAction> m_action;
         int m_originalInterval;
+        double m_currentTimerInterval;
         bool m_shouldForwardUserGesture;
     };
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to