<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[198929] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/198929">198929</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2016-03-31 16:33:56 -0700 (Thu, 31 Mar 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[iOS] Both WebPage's volatility timer and WebProcess's processSuspensionCleanupTimer are trying to make surfaces volatile with very short interval
https://bugs.webkit.org/show_bug.cgi?id=156065
&lt;rdar://problem/25452004&gt;

Reviewed by Simon Fraser.

Source/WebCore:

Export a symbol so it can be used from WebKit2.

* page/Page.h:

Source/WebKit2:

Upon process suspension, both the WebPage's volatility timer and
WebProcess' processSuspensionCleanupTimer are trying to make surfaces
volatile with a very short interval. This is overly aggressive given
that this operation normally succeeds very quickly or does not (due
to underlying bugs).

This patch does the following:
- Drop the WebProcess' processSuspensionCleanupTimer and have the
  WebProcess drive the WebPages' volatility timer instead.
- Update the WebPages' volatility timer to do exponential back off.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::layerVolatilityTimerFired):
(WebKit::WebPage::markLayersVolatileImmediatelyIfPossible):
(WebKit::WebPage::markLayersVolatile):
(WebKit::WebPage::cancelMarkLayersVolatile):
(WebKit::WebPage::isAlwaysOnLoggingAllowed):
(WebKit::WebPage::setLayerTreeStateIsFrozen): Deleted.
* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::markLayersVolatile):
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::applicationDidEnterBackground):
(WebKit::WebPage::applicationWillEnterForeground):
(WebKit::WebPage::applicationDidBecomeActive): Deleted.
(WebKit::adjustVelocityDataForBoundedScale): Deleted.
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::actualPrepareToSuspend):
(WebKit::WebProcess::processWillSuspendImminently):
(WebKit::WebProcess::prepareToSuspend):
(WebKit::WebProcess::cancelPrepareToSuspend):
(WebKit::WebProcess::markAllLayersVolatile):
(WebKit::WebProcess::cancelMarkAllLayersVolatile):
(WebKit::WebProcess::setAllLayerTreeStatesFrozen):
(WebKit::WebProcess::processDidResume):
(WebKit::WebProcess::WebProcess): Deleted.
* WebProcess/WebProcess.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorepagePageh">trunk/Source/WebCore/page/Page.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPagecpp">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPageh">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm">trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebProcesscpp">trunk/Source/WebKit2/WebProcess/WebProcess.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebProcessh">trunk/Source/WebKit2/WebProcess/WebProcess.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (198928 => 198929)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-03-31 23:07:39 UTC (rev 198928)
+++ trunk/Source/WebCore/ChangeLog        2016-03-31 23:33:56 UTC (rev 198929)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2016-03-31  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        [iOS] Both WebPage's volatility timer and WebProcess's processSuspensionCleanupTimer are trying to make surfaces volatile with very short interval
+        https://bugs.webkit.org/show_bug.cgi?id=156065
+        &lt;rdar://problem/25452004&gt;
+
+        Reviewed by Simon Fraser.
+
+        Export a symbol so it can be used from WebKit2.
+
+        * page/Page.h:
+
</ins><span class="cx"> 2016-03-31  Daniel Bates  &lt;dabates@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         REGRESSION (r195605): ASSERTION FAILED: !NoEventDispatchAssertion::isEventDispatchForbidden()
</span></span></pre></div>
<a id="trunkSourceWebCorepagePageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Page.h (198928 => 198929)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Page.h        2016-03-31 23:07:39 UTC (rev 198928)
+++ trunk/Source/WebCore/page/Page.h        2016-03-31 23:33:56 UTC (rev 198929)
</span><span class="lines">@@ -509,7 +509,7 @@
</span><span class="cx">     bool isControlledByAutomation() const { return m_controlledByAutomation; }
</span><span class="cx">     void setControlledByAutomation(bool controlled) { m_controlledByAutomation = controlled; }
</span><span class="cx"> 
</span><del>-    bool isAlwaysOnLoggingAllowed() const;
</del><ins>+    WEBCORE_EXPORT bool isAlwaysOnLoggingAllowed() const;
</ins><span class="cx"> 
</span><span class="cx">     String captionUserPreferencesStyleSheet();
</span><span class="cx">     void setCaptionUserPreferencesStyleSheet(const String&amp;);
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (198928 => 198929)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-03-31 23:07:39 UTC (rev 198928)
+++ trunk/Source/WebKit2/ChangeLog        2016-03-31 23:33:56 UTC (rev 198929)
</span><span class="lines">@@ -1,3 +1,48 @@
</span><ins>+2016-03-31  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        [iOS] Both WebPage's volatility timer and WebProcess's processSuspensionCleanupTimer are trying to make surfaces volatile with very short interval
+        https://bugs.webkit.org/show_bug.cgi?id=156065
+        &lt;rdar://problem/25452004&gt;
+
+        Reviewed by Simon Fraser.
+
+        Upon process suspension, both the WebPage's volatility timer and
+        WebProcess' processSuspensionCleanupTimer are trying to make surfaces
+        volatile with a very short interval. This is overly aggressive given
+        that this operation normally succeeds very quickly or does not (due
+        to underlying bugs).
+
+        This patch does the following:
+        - Drop the WebProcess' processSuspensionCleanupTimer and have the
+          WebProcess drive the WebPages' volatility timer instead.
+        - Update the WebPages' volatility timer to do exponential back off.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::layerVolatilityTimerFired):
+        (WebKit::WebPage::markLayersVolatileImmediatelyIfPossible):
+        (WebKit::WebPage::markLayersVolatile):
+        (WebKit::WebPage::cancelMarkLayersVolatile):
+        (WebKit::WebPage::isAlwaysOnLoggingAllowed):
+        (WebKit::WebPage::setLayerTreeStateIsFrozen): Deleted.
+        * WebProcess/WebPage/WebPage.h:
+        (WebKit::WebPage::markLayersVolatile):
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::applicationDidEnterBackground):
+        (WebKit::WebPage::applicationWillEnterForeground):
+        (WebKit::WebPage::applicationDidBecomeActive): Deleted.
+        (WebKit::adjustVelocityDataForBoundedScale): Deleted.
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::actualPrepareToSuspend):
+        (WebKit::WebProcess::processWillSuspendImminently):
+        (WebKit::WebProcess::prepareToSuspend):
+        (WebKit::WebProcess::cancelPrepareToSuspend):
+        (WebKit::WebProcess::markAllLayersVolatile):
+        (WebKit::WebProcess::cancelMarkAllLayersVolatile):
+        (WebKit::WebProcess::setAllLayerTreeStatesFrozen):
+        (WebKit::WebProcess::processDidResume):
+        (WebKit::WebProcess::WebProcess): Deleted.
+        * WebProcess/WebProcess.h:
+
</ins><span class="cx"> 2016-03-31  Brian Burg  &lt;bburg@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Web Automation: the interaction queue in WebAutomationSession::performKeyInteractions doesn't work
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (198928 => 198929)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2016-03-31 23:07:39 UTC (rev 198928)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2016-03-31 23:33:56 UTC (rev 198929)
</span><span class="lines">@@ -243,7 +243,12 @@
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><span class="cx"> static const double pageScrollHysteresisSeconds = 0.3;
</span><ins>+static const std::chrono::milliseconds initialLayerVolatilityTimerInterval { 20 };
+static const std::chrono::seconds maximumLayerVolatilityTimerInterval { 10 };
</ins><span class="cx"> 
</span><ins>+#define WEBPAGE_LOG_ALWAYS(...) LOG_ALWAYS(isAlwaysOnLoggingAllowed(), __VA_ARGS__)
+#define WEBPAGE_LOG_ALWAYS_ERROR(...) LOG_ALWAYS_ERROR(isAlwaysOnLoggingAllowed(), __VA_ARGS__)
+
</ins><span class="cx"> class SendStopResponsivenessTimer {
</span><span class="cx"> public:
</span><span class="cx">     SendStopResponsivenessTimer(WebPage* page)
</span><span class="lines">@@ -351,8 +356,8 @@
</span><span class="cx">     , m_availableScreenSize(parameters.availableScreenSize)
</span><span class="cx">     , m_deviceOrientation(0)
</span><span class="cx">     , m_inDynamicSizeUpdate(false)
</span><del>-    , m_volatilityTimer(*this, &amp;WebPage::volatilityTimerFired)
</del><span class="cx"> #endif
</span><ins>+    , m_layerVolatilityTimer(*this, &amp;WebPage::layerVolatilityTimerFired)
</ins><span class="cx">     , m_backgroundColor(Color::white)
</span><span class="cx">     , m_maximumRenderingSuppressionToken(0)
</span><span class="cx">     , m_scrollPinningBehavior(DoNotPin)
</span><span class="lines">@@ -2026,15 +2031,55 @@
</span><span class="cx">     drawingArea-&gt;setLayerTreeStateIsFrozen(frozen);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPage::layerVolatilityTimerFired()
+{
+    if (markLayersVolatileImmediatelyIfPossible()) {
+        m_layerVolatilityTimer.stop();
+        return;
+    }
+
+    auto newInterval = std::min(2 * m_layerVolatilityTimer.repeatIntervalMS(), std::chrono::duration_cast&lt;std::chrono::milliseconds&gt;(maximumLayerVolatilityTimerInterval));
+    WEBPAGE_LOG_ALWAYS_ERROR(&quot;%p - WebPage - Failed to mark all layers as volatile, will retry in %lld ms&quot;, this, newInterval.count());
+    m_layerVolatilityTimer.startRepeating(newInterval);
+}
+
</ins><span class="cx"> bool WebPage::markLayersVolatileImmediatelyIfPossible()
</span><span class="cx"> {
</span><del>-    auto* drawingArea = this-&gt;drawingArea();
-    if (!drawingArea)
-        return true;
</del><ins>+    bool success = !drawingArea() || drawingArea()-&gt;markLayersVolatileImmediatelyIfPossible();
+    if (success) {
+        WEBPAGE_LOG_ALWAYS(&quot;%p - WebPage - Successfully marked layers as volatile&quot;, this);
+        auto completionHandlers = WTFMove(m_markLayersAsVolatileCompletionHandlers);
+        for (auto&amp; completionHandler : completionHandlers)
+            completionHandler();
+    }
</ins><span class="cx"> 
</span><del>-    return drawingArea-&gt;markLayersVolatileImmediatelyIfPossible();
</del><ins>+    return success;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPage::markLayersVolatile(std::function&lt;void()&gt; completionHandler)
+{
+    WEBPAGE_LOG_ALWAYS(&quot;%p - WebPage::markLayersVolatile()&quot;, this);
+
+    if (m_layerVolatilityTimer.isActive())
+        m_layerVolatilityTimer.stop();
+
+    if (completionHandler)
+        m_markLayersAsVolatileCompletionHandlers.append(WTFMove(completionHandler));
+
+    if (markLayersVolatileImmediatelyIfPossible())
+        return;
+
+    WEBPAGE_LOG_ALWAYS(&quot;%p - Failed to mark all layers as volatile, will retry in %lld ms&quot;, this, initialLayerVolatilityTimerInterval.count());
+    m_layerVolatilityTimer.startRepeating(initialLayerVolatilityTimerInterval);
+}
+
+void WebPage::cancelMarkLayersVolatile()
+{
+    WEBPAGE_LOG_ALWAYS(&quot;%p - WebPage::cancelMarkLayersVolatile()&quot;, this);
+    m_layerVolatilityTimer.stop();
+    m_markLayersAsVolatileCompletionHandlers.clear();
+}
+
</ins><span class="cx"> class CurrentEvent {
</span><span class="cx"> public:
</span><span class="cx">     explicit CurrentEvent(const WebEvent&amp; event)
</span><span class="lines">@@ -3337,6 +3382,11 @@
</span><span class="cx">     m_undoStepMap.remove(stepID);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool WebPage::isAlwaysOnLoggingAllowed() const
+{
+    return corePage() &amp;&amp; corePage()-&gt;isAlwaysOnLoggingAllowed();
+}
+
</ins><span class="cx"> void WebPage::unapplyEditCommand(uint64_t stepID)
</span><span class="cx"> {
</span><span class="cx">     WebUndoStep* step = webUndoStep(stepID);
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (198928 => 198929)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2016-03-31 23:07:39 UTC (rev 198928)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2016-03-31 23:33:56 UTC (rev 198929)
</span><span class="lines">@@ -287,6 +287,7 @@
</span><span class="cx">     void removeWebEditCommand(uint64_t);
</span><span class="cx">     bool isInRedo() const { return m_isInRedo; }
</span><span class="cx"> 
</span><ins>+    bool isAlwaysOnLoggingAllowed() const;
</ins><span class="cx">     void setActivePopupMenu(WebPopupMenu*);
</span><span class="cx"> 
</span><span class="cx">     void setHiddenPageTimerThrottlingIncreaseLimit(std::chrono::milliseconds limit)
</span><span class="lines">@@ -579,7 +580,8 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     void setLayerTreeStateIsFrozen(bool);
</span><del>-    bool markLayersVolatileImmediatelyIfPossible();
</del><ins>+    void markLayersVolatile(std::function&lt;void()&gt; completionHandler = {});
+    void cancelMarkLayersVolatile();
</ins><span class="cx"> 
</span><span class="cx">     NotificationPermissionRequestManager* notificationPermissionRequestManager();
</span><span class="cx"> 
</span><span class="lines">@@ -974,7 +976,6 @@
</span><span class="cx">     void resetTextAutosizingBeforeLayoutIfNeeded(const WebCore::FloatSize&amp; oldSize, const WebCore::FloatSize&amp; newSize);
</span><span class="cx">     WebCore::VisiblePosition visiblePositionInFocusedNodeForPoint(const WebCore::Frame&amp;, const WebCore::IntPoint&amp;, bool isInteractingWithAssistedNode);
</span><span class="cx">     PassRefPtr&lt;WebCore::Range&gt; rangeForGranularityAtPoint(const WebCore::Frame&amp;, const WebCore::IntPoint&amp;, uint32_t granularity, bool isInteractingWithAssistedNode);
</span><del>-    void volatilityTimerFired();
</del><span class="cx"> #endif
</span><span class="cx"> #if !PLATFORM(COCOA)
</span><span class="cx">     static const char* interpretKeyEvent(const WebCore::KeyboardEvent*);
</span><span class="lines">@@ -985,6 +986,9 @@
</span><span class="cx">     bool executeKeypressCommandsInternal(const Vector&lt;WebCore::KeypressCommand&gt;&amp;, WebCore::KeyboardEvent*);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    bool markLayersVolatileImmediatelyIfPossible();
+    void layerVolatilityTimerFired();
+
</ins><span class="cx">     String sourceForFrame(WebFrame*);
</span><span class="cx"> 
</span><span class="cx">     void loadDataImpl(uint64_t navigationID, PassRefPtr&lt;WebCore::SharedBuffer&gt;, const String&amp; MIMEType, const String&amp; encodingName, const WebCore::URL&amp; baseURL, const WebCore::URL&amp; failingURL, const UserData&amp;);
</span><span class="lines">@@ -1412,9 +1416,11 @@
</span><span class="cx">     RefPtr&lt;WebCore::Node&gt; m_pendingSyntheticClickNode;
</span><span class="cx">     WebCore::FloatPoint m_pendingSyntheticClickLocation;
</span><span class="cx">     WebCore::FloatRect m_previousExposedContentRect;
</span><del>-    WebCore::Timer m_volatilityTimer;
</del><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    WebCore::Timer m_layerVolatilityTimer;
+    Vector&lt;std::function&lt;void()&gt;&gt; m_markLayersAsVolatileCompletionHandlers;
+
</ins><span class="cx">     HashSet&lt;String, ASCIICaseInsensitiveHash&gt; m_mimeTypesWithCustomContentProviders;
</span><span class="cx">     WebCore::Color m_backgroundColor;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (198928 => 198929)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2016-03-31 23:07:39 UTC (rev 198928)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2016-03-31 23:33:56 UTC (rev 198929)
</span><span class="lines">@@ -2866,28 +2866,17 @@
</span><span class="cx">     [[NSNotificationCenter defaultCenter] postNotificationName:WebUIApplicationWillResignActiveNotification object:nil];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebPage::volatilityTimerFired()
-{
-    if (!markLayersVolatileImmediatelyIfPossible())
-        return;
-
-    m_volatilityTimer.stop();
-}
-
</del><span class="cx"> void WebPage::applicationDidEnterBackground(bool isSuspendedUnderLock)
</span><span class="cx"> {
</span><span class="cx">     [[NSNotificationCenter defaultCenter] postNotificationName:WebUIApplicationDidEnterBackgroundNotification object:nil userInfo:@{@&quot;isSuspendedUnderLock&quot;: [NSNumber numberWithBool:isSuspendedUnderLock]}];
</span><span class="cx"> 
</span><span class="cx">     setLayerTreeStateIsFrozen(true);
</span><del>-    if (markLayersVolatileImmediatelyIfPossible())
-        return;
-
-    m_volatilityTimer.startRepeating(std::chrono::milliseconds(200));
</del><ins>+    markLayersVolatile();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebPage::applicationWillEnterForeground(bool isSuspendedUnderLock)
</span><span class="cx"> {
</span><del>-    m_volatilityTimer.stop();
</del><ins>+    cancelMarkLayersVolatile();
</ins><span class="cx">     setLayerTreeStateIsFrozen(false);
</span><span class="cx"> 
</span><span class="cx">     [[NSNotificationCenter defaultCenter] postNotificationName:WebUIApplicationWillEnterForegroundNotification object:nil userInfo:@{@&quot;isSuspendedUnderLock&quot;: @(isSuspendedUnderLock)}];
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebProcesscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebProcess.cpp (198928 => 198929)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebProcess.cpp        2016-03-31 23:07:39 UTC (rev 198928)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.cpp        2016-03-31 23:33:56 UTC (rev 198929)
</span><span class="lines">@@ -140,6 +140,8 @@
</span><span class="cx"> // This should be greater than tileRevalidationTimeout in TileController.
</span><span class="cx"> static const double nonVisibleProcessCleanupDelay = 10;
</span><span class="cx"> 
</span><ins>+#define WEBPROCESS_LOG_ALWAYS(...) LOG_ALWAYS(true, __VA_ARGS__)
+
</ins><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><span class="cx"> WebProcess&amp; WebProcess::singleton()
</span><span class="lines">@@ -153,7 +155,6 @@
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">     , m_viewUpdateDispatcher(ViewUpdateDispatcher::create())
</span><span class="cx"> #endif
</span><del>-    , m_processSuspensionCleanupTimer(*this, &amp;WebProcess::processSuspensionCleanupTimerFired)
</del><span class="cx">     , m_inDidClose(false)
</span><span class="cx">     , m_hasSetCacheModel(false)
</span><span class="cx">     , m_cacheModel(CacheModelDocumentViewer)
</span><span class="lines">@@ -1209,13 +1210,14 @@
</span><span class="cx"> 
</span><span class="cx">     setAllLayerTreeStatesFrozen(true);
</span><span class="cx"> 
</span><del>-    if (markAllLayersVolatileIfPossible()) {
-        if (shouldAcknowledgeWhenReadyToSuspend == ShouldAcknowledgeWhenReadyToSuspend::Yes)
</del><ins>+    markAllLayersVolatile([this, shouldAcknowledgeWhenReadyToSuspend] {
+        WEBPROCESS_LOG_ALWAYS(&quot;%p - WebProcess::markAllLayersVolatile() Successfuly marked all layers as volatile&quot;, this);
+
+        if (shouldAcknowledgeWhenReadyToSuspend == ShouldAcknowledgeWhenReadyToSuspend::Yes) {
+            WEBPROCESS_LOG_ALWAYS(&quot;%p - WebProcess::actualPrepareToSuspend() Sending ProcessReadyToSuspend IPC message&quot;, this);
</ins><span class="cx">             parentProcessConnection()-&gt;send(Messages::WebProcessProxy::ProcessReadyToSuspend(), 0);
</span><del>-        return;
-    }
-    m_shouldAcknowledgeWhenReadyToSuspend = shouldAcknowledgeWhenReadyToSuspend;
-    m_processSuspensionCleanupTimer.startRepeating(std::chrono::milliseconds(20));
</del><ins>+        }
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebProcess::processWillSuspendImminently(bool&amp; handled)
</span><span class="lines">@@ -1228,6 +1230,7 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    WEBPROCESS_LOG_ALWAYS(&quot;%p - WebProcess::processWillSuspendImminently()&quot;, this);
</ins><span class="cx">     DatabaseTracker::tracker().closeAllDatabases();
</span><span class="cx">     actualPrepareToSuspend(ShouldAcknowledgeWhenReadyToSuspend::No);
</span><span class="cx">     handled = true;
</span><span class="lines">@@ -1235,29 +1238,51 @@
</span><span class="cx"> 
</span><span class="cx"> void WebProcess::prepareToSuspend()
</span><span class="cx"> {
</span><ins>+    WEBPROCESS_LOG_ALWAYS(&quot;%p - WebProcess::prepareToSuspend()&quot;, this);
</ins><span class="cx">     actualPrepareToSuspend(ShouldAcknowledgeWhenReadyToSuspend::Yes);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebProcess::cancelPrepareToSuspend()
</span><span class="cx"> {
</span><ins>+    WEBPROCESS_LOG_ALWAYS(&quot;%p - WebProcess::cancelPrepareToSuspend()&quot;, this);
</ins><span class="cx">     setAllLayerTreeStatesFrozen(false);
</span><span class="cx"> 
</span><span class="cx">     // If we've already finished cleaning up and sent ProcessReadyToSuspend, we
</span><span class="cx">     // shouldn't send DidCancelProcessSuspension; the UI process strictly expects one or the other.
</span><del>-    if (!m_processSuspensionCleanupTimer.isActive())
</del><ins>+    if (!m_pagesMarkingLayersAsVolatile)
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    m_processSuspensionCleanupTimer.stop();
</del><ins>+    cancelMarkAllLayersVolatile();
+
+    WEBPROCESS_LOG_ALWAYS(&quot;%p - WebProcess::cancelPrepareToSuspend() Sending DidCancelProcessSuspension IPC message&quot;, this);
</ins><span class="cx">     parentProcessConnection()-&gt;send(Messages::WebProcessProxy::DidCancelProcessSuspension(), 0);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool WebProcess::markAllLayersVolatileIfPossible()
</del><ins>+void WebProcess::markAllLayersVolatile(std::function&lt;void()&gt; completionHandler)
</ins><span class="cx"> {
</span><del>-    bool successfullyMarkedAllLayersVolatile = true;
</del><ins>+    WEBPROCESS_LOG_ALWAYS(&quot;%p - WebProcess::markAllLayersVolatile()&quot;, this);
+    m_pagesMarkingLayersAsVolatile = m_pageMap.size();
+    if (!m_pagesMarkingLayersAsVolatile) {
+        completionHandler();
+        return;
+    }
+    for (auto&amp; page : m_pageMap.values()) {
+        page-&gt;markLayersVolatile([this, completionHandler] {
+            ASSERT(m_pagesMarkingLayersAsVolatile);
+            if (!--m_pagesMarkingLayersAsVolatile)
+                completionHandler();
+        });
+    }
+}
+
+void WebProcess::cancelMarkAllLayersVolatile()
+{
+    if (!m_pagesMarkingLayersAsVolatile)
+        return;
+
</ins><span class="cx">     for (auto&amp; page : m_pageMap.values())
</span><del>-        successfullyMarkedAllLayersVolatile &amp;= page-&gt;markLayersVolatileImmediatelyIfPossible();
-
-    return successfullyMarkedAllLayersVolatile;
</del><ins>+        page-&gt;cancelMarkLayersVolatile();
+    m_pagesMarkingLayersAsVolatile = 0;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebProcess::setAllLayerTreeStatesFrozen(bool frozen)
</span><span class="lines">@@ -1265,19 +1290,12 @@
</span><span class="cx">     for (auto&amp; page : m_pageMap.values())
</span><span class="cx">         page-&gt;setLayerTreeStateIsFrozen(frozen);
</span><span class="cx"> }
</span><del>-
-void WebProcess::processSuspensionCleanupTimerFired()
-{
-    if (!markAllLayersVolatileIfPossible())
-        return;
-    m_processSuspensionCleanupTimer.stop();
-    if (m_shouldAcknowledgeWhenReadyToSuspend == ShouldAcknowledgeWhenReadyToSuspend::Yes)
-        parentProcessConnection()-&gt;send(Messages::WebProcessProxy::ProcessReadyToSuspend(), 0);
-}
</del><span class="cx">     
</span><span class="cx"> void WebProcess::processDidResume()
</span><span class="cx"> {
</span><del>-    m_processSuspensionCleanupTimer.stop();
</del><ins>+    WEBPROCESS_LOG_ALWAYS(&quot;%p - WebProcess::processDidResume()&quot;, this);
+
+    cancelMarkAllLayersVolatile();
</ins><span class="cx">     setAllLayerTreeStatesFrozen(false);
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebProcessh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebProcess.h (198928 => 198929)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebProcess.h        2016-03-31 23:07:39 UTC (rev 198928)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.h        2016-03-31 23:33:56 UTC (rev 198929)
</span><span class="lines">@@ -186,9 +186,6 @@
</span><span class="cx">     void processWillSuspendImminently(bool&amp; handled);
</span><span class="cx">     void prepareToSuspend();
</span><span class="cx">     void cancelPrepareToSuspend();
</span><del>-    bool markAllLayersVolatileIfPossible();
-    void setAllLayerTreeStatesFrozen(bool);
-    void processSuspensionCleanupTimerFired();
</del><span class="cx">     void processDidResume();
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="lines">@@ -224,6 +221,11 @@
</span><span class="cx">     void registerWithStateDumper();
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    void markAllLayersVolatile(std::function&lt;void()&gt; completionHandler);
+    void cancelMarkAllLayersVolatile();
+    void setAllLayerTreeStatesFrozen(bool);
+    void processSuspensionCleanupTimerFired();
+
</ins><span class="cx">     void clearCachedCredentials();
</span><span class="cx"> 
</span><span class="cx">     void platformTerminate();
</span><span class="lines">@@ -327,7 +329,6 @@
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">     RefPtr&lt;ViewUpdateDispatcher&gt; m_viewUpdateDispatcher;
</span><span class="cx"> #endif
</span><del>-    WebCore::Timer m_processSuspensionCleanupTimer;
</del><span class="cx"> 
</span><span class="cx">     bool m_inDidClose;
</span><span class="cx"> 
</span><span class="lines">@@ -386,7 +387,7 @@
</span><span class="cx"> 
</span><span class="cx">     Ref&lt;WebCore::ResourceLoadStatisticsStore&gt; m_resourceLoadStatisticsStorage;
</span><span class="cx"> 
</span><del>-    ShouldAcknowledgeWhenReadyToSuspend m_shouldAcknowledgeWhenReadyToSuspend;
</del><ins>+    unsigned m_pagesMarkingLayersAsVolatile { 0 };
</ins><span class="cx">     bool m_suppressMemoryPressureHandler { false };
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>