Title: [197459] trunk/Source/WebCore
Revision
197459
Author
[email protected]
Date
2016-03-02 12:39:37 -0800 (Wed, 02 Mar 2016)

Log Message

Add Page::TimerThrottlingState
https://bugs.webkit.org/show_bug.cgi?id=154926

Reviewed by Chris Dumez.

Hidden page timer throttling is currently a boolean state, indicated by whether the Optional
m_timerThrottlingEnabledTime is in a set/unset state. When enabled, the increasing mechanism
may or may not be enabled, this is controlled directly by the setting.

Refactor to add an enum tracking timer throttling being in one of three states - disabled,
enabled, or enabled-increasing. This cleans things up, and will enabled up to introduce a
dynamic policy for when enabled-throttling is enabled. (Behavior is unchanged in this patch.)

* page/Page.cpp:
(WebCore::Page::Page):
(WebCore::Page::setIsVisuallyIdleInternal):
(WebCore::Page::hiddenPageDOMTimerThrottlingStateChanged):
    - setTimerThrottlingEnabled -> updateTimerThrottlingState.
(WebCore::Page::updateTimerThrottlingState):
    - policy decision (currently enabled if visually-idle) was scattered across
      all call sites to setTimerThrottlingState. Unify in one place.
(WebCore::Page::setTimerThrottlingState):
    - Was setTimerThrottlingEnabled.
(WebCore::Page::setTimerAlignmentIntervalIncreaseLimit):
(WebCore::Page::setDOMTimerAlignmentInterval):
(WebCore::Page::timerAlignmentIntervalIncreaseTimerFired):
    - updated to check m_timerThrottlingState.
(WebCore::Page::setTimerThrottlingEnabled): Deleted.
    - This became updateTimerThrottlingState.
* page/Page.h:
(WebCore::Page::timerThrottlingEnabled): Deleted.
    - Removed, it's easy enough now to just check m_timerThrottlingState.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (197458 => 197459)


--- trunk/Source/WebCore/ChangeLog	2016-03-02 20:38:23 UTC (rev 197458)
+++ trunk/Source/WebCore/ChangeLog	2016-03-02 20:39:37 UTC (rev 197459)
@@ -1,3 +1,38 @@
+2016-03-02  Gavin Barraclough  <[email protected]>
+
+        Add Page::TimerThrottlingState
+        https://bugs.webkit.org/show_bug.cgi?id=154926
+
+        Reviewed by Chris Dumez.
+
+        Hidden page timer throttling is currently a boolean state, indicated by whether the Optional
+        m_timerThrottlingEnabledTime is in a set/unset state. When enabled, the increasing mechanism
+        may or may not be enabled, this is controlled directly by the setting.
+
+        Refactor to add an enum tracking timer throttling being in one of three states - disabled,
+        enabled, or enabled-increasing. This cleans things up, and will enabled up to introduce a
+        dynamic policy for when enabled-throttling is enabled. (Behavior is unchanged in this patch.)
+
+        * page/Page.cpp:
+        (WebCore::Page::Page):
+        (WebCore::Page::setIsVisuallyIdleInternal):
+        (WebCore::Page::hiddenPageDOMTimerThrottlingStateChanged):
+            - setTimerThrottlingEnabled -> updateTimerThrottlingState.
+        (WebCore::Page::updateTimerThrottlingState):
+            - policy decision (currently enabled if visually-idle) was scattered across
+              all call sites to setTimerThrottlingState. Unify in one place.
+        (WebCore::Page::setTimerThrottlingState):
+            - Was setTimerThrottlingEnabled.
+        (WebCore::Page::setTimerAlignmentIntervalIncreaseLimit):
+        (WebCore::Page::setDOMTimerAlignmentInterval):
+        (WebCore::Page::timerAlignmentIntervalIncreaseTimerFired):
+            - updated to check m_timerThrottlingState.
+        (WebCore::Page::setTimerThrottlingEnabled): Deleted.
+            - This became updateTimerThrottlingState.
+        * page/Page.h:
+        (WebCore::Page::timerThrottlingEnabled): Deleted.
+            - Removed, it's easy enough now to just check m_timerThrottlingState.
+
 2016-03-02  Chris Dumez  <[email protected]>
 
         Align HTMLInputElement.maxLength with the specification

Modified: trunk/Source/WebCore/page/Page.cpp (197458 => 197459)


--- trunk/Source/WebCore/page/Page.cpp	2016-03-02 20:38:23 UTC (rev 197458)
+++ trunk/Source/WebCore/page/Page.cpp	2016-03-02 20:39:37 UTC (rev 197459)
@@ -236,7 +236,7 @@
     , m_sessionID(SessionID::defaultSessionID())
     , m_isClosing(false)
 {
-    setTimerThrottlingEnabled(m_viewState & ViewState::IsVisuallyIdle);
+    updateTimerThrottlingState();
 
     m_storageNamespaceProvider->addPage(*this);
 
@@ -1031,7 +1031,7 @@
 
 void Page::setIsVisuallyIdleInternal(bool isVisuallyIdle)
 {
-    setTimerThrottlingEnabled(isVisuallyIdle);
+    updateTimerThrottlingState();
     
     for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
         if (frame->document())
@@ -1179,25 +1179,36 @@
 void Page::hiddenPageDOMTimerThrottlingStateChanged()
 {
     // Disable & reengage to ensure state is updated.
-    setTimerThrottlingEnabled(false);
-    setTimerThrottlingEnabled(m_viewState & ViewState::IsVisuallyIdle);
+    setTimerThrottlingState(TimerThrottlingState::Disabled);
+    updateTimerThrottlingState();
 }
 
-void Page::setTimerThrottlingEnabled(bool enabled)
+void Page::updateTimerThrottlingState()
 {
-    if (!m_settings->hiddenPageDOMTimerThrottlingEnabled())
-        enabled = false;
+    TimerThrottlingState state = TimerThrottlingState::Disabled;
 
-    if (enabled == timerThrottlingEnabled())
-        return;
+    if (m_settings->hiddenPageDOMTimerThrottlingEnabled() && m_viewState & ViewState::IsVisuallyIdle)
+        state = m_settings->hiddenPageDOMTimerThrottlingAutoIncreases() ? TimerThrottlingState::EnabledIncreasing : TimerThrottlingState::Enabled;
 
-    m_timerThrottlingEnabledTime = enabled ? monotonicallyIncreasingTime() : Optional<double>();
-    setDOMTimerAlignmentInterval(enabled ? DOMTimer::hiddenPageAlignmentInterval() : DOMTimer::defaultAlignmentInterval());
+    setTimerThrottlingState(state);
+}
 
-    if (enabled)
+void Page::setTimerThrottlingState(TimerThrottlingState state)
+{
+    if (state == m_timerThrottlingState)
         return;
+    m_timerThrottlingState = state;
 
-    // If throttling was disabled, release all throttled timers.
+    if (state != TimerThrottlingState::Disabled) {
+        m_timerThrottlingEnabledTime = monotonicallyIncreasingTime();
+        setDOMTimerAlignmentInterval(DOMTimer::hiddenPageAlignmentInterval());
+        return;
+    }
+
+    m_timerThrottlingEnabledTime = 0;
+    setDOMTimerAlignmentInterval(DOMTimer::defaultAlignmentInterval());
+
+    // When throttling is disabled, release all throttled timers.
     for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
         if (auto* document = frame->document())
             document->didChangeTimerAlignmentInterval();
@@ -1209,12 +1220,10 @@
     // FIXME: std::chrono-ify all timer allignment related code.
     m_timerAlignmentIntervalIncreaseLimit = limit.count() * 0.001;
 
-    if (!timerThrottlingEnabled())
-        return;
-
     // If (m_timerAlignmentIntervalIncreaseLimit < m_timerAlignmentInterval) then we need
     // to update m_timerAlignmentInterval, if greater then need to restart the increase timer.
-    setDOMTimerAlignmentInterval(std::min(m_timerAlignmentIntervalIncreaseLimit, m_timerAlignmentInterval));
+    if (m_timerThrottlingState == TimerThrottlingState::EnabledIncreasing)
+        setDOMTimerAlignmentInterval(std::min(m_timerAlignmentIntervalIncreaseLimit, m_timerAlignmentInterval));
 }
 
 void Page::setDOMTimerAlignmentInterval(double alignmentInterval)
@@ -1225,20 +1234,22 @@
     // limit has not yet been reached, and then arm the timer to consider an increase. Time to wait
     // between increases is equal to the current throttle time. Since alinment interval increases
     // exponentially, time between steps is exponential too.
-    if (!timerThrottlingEnabled() || !m_settings->hiddenPageDOMTimerThrottlingAutoIncreases()
-        || m_timerAlignmentInterval >= m_timerAlignmentIntervalIncreaseLimit)
+    if (m_timerThrottlingState == TimerThrottlingState::EnabledIncreasing && m_timerAlignmentInterval < m_timerAlignmentIntervalIncreaseLimit) {
+        if (!m_timerAlignmentIntervalIncreaseTimer.isActive())
+            m_timerAlignmentIntervalIncreaseTimer.startOneShot(m_timerAlignmentInterval);
+    } else
         m_timerAlignmentIntervalIncreaseTimer.stop();
-    else if (!m_timerAlignmentIntervalIncreaseTimer.isActive())
-        m_timerAlignmentIntervalIncreaseTimer.startOneShot(m_timerAlignmentInterval);
 }
 
 void Page::timerAlignmentIntervalIncreaseTimerFired()
 {
-    ASSERT(timerThrottlingEnabled() && m_settings->hiddenPageDOMTimerThrottlingAutoIncreases());
+    ASSERT(m_settings->hiddenPageDOMTimerThrottlingAutoIncreases());
+    ASSERT(m_timerThrottlingState == TimerThrottlingState::EnabledIncreasing);
     ASSERT(m_timerAlignmentInterval < m_timerAlignmentIntervalIncreaseLimit);
-        
+    ASSERT(m_timerThrottlingEnabledTime);
+    
     // Alignment interval is increased to equal the time the page has been throttled, to a limit.
-    double throttledDuration = monotonicallyIncreasingTime() - m_timerThrottlingEnabledTime.value();
+    double throttledDuration = monotonicallyIncreasingTime() - m_timerThrottlingEnabledTime;
     double alignmentInterval = std::max(m_timerAlignmentInterval, throttledDuration);
     setDOMTimerAlignmentInterval(std::min(alignmentInterval, m_timerAlignmentIntervalIncreaseLimit));
 }

Modified: trunk/Source/WebCore/page/Page.h (197458 => 197459)


--- trunk/Source/WebCore/page/Page.h	2016-03-02 20:38:23 UTC (rev 197458)
+++ trunk/Source/WebCore/page/Page.h	2016-03-02 20:39:37 UTC (rev 197459)
@@ -526,11 +526,12 @@
 
     Vector<Ref<PluginViewBase>> pluginViews();
 
+    enum class TimerThrottlingState { Disabled, Enabled, EnabledIncreasing };
     void hiddenPageDOMTimerThrottlingStateChanged();
-    void setTimerThrottlingEnabled(bool);
+    void setTimerThrottlingState(TimerThrottlingState);
+    void updateTimerThrottlingState();
     void setDOMTimerAlignmentInterval(double);
     void timerAlignmentIntervalIncreaseTimerFired();
-    bool timerThrottlingEnabled() const { return !!m_timerThrottlingEnabledTime; }
 
     const std::unique_ptr<Chrome> m_chrome;
     const std::unique_ptr<DragCaretController> m_dragCaretController;
@@ -616,7 +617,8 @@
     ViewMode m_viewMode;
 #endif // ENABLE(VIEW_MODE_CSS_MEDIA)
 
-    Optional<double> m_timerThrottlingEnabledTime;
+    TimerThrottlingState m_timerThrottlingState { TimerThrottlingState::Disabled };
+    double m_timerThrottlingEnabledTime { 0 };
     double m_timerAlignmentInterval;
     Timer m_timerAlignmentIntervalIncreaseTimer;
     double m_timerAlignmentIntervalIncreaseLimit { 0 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to