Title: [213824] trunk/Source
Revision
213824
Author
[email protected]
Date
2017-03-13 04:16:29 -0700 (Mon, 13 Mar 2017)

Log Message

[WK2] Only report background WebProcesses as unresponsive in the background after 90 seconds
https://bugs.webkit.org/show_bug.cgi?id=169425
<rdar://problem/30954003>

Reviewed by Andreas Kling.

Source/WebKit2:

The background responsiveness checking was previously relying on the
isResponsive(std::function<void(bool)>) API which uses the ResponsivenessTimer
and has a timeout of 3 seconds. We believe this is too aggressive for background
tabs. Update BackgroundResponsiveTimer to stop relying on ResponsivenessTimer
and have its own timeout Timer which a delay of 90 seconds instead.

* UIProcess/API/C/mac/WKPagePrivateMac.mm:
(-[WKObservablePageState _webProcessIsResponsive]):
* UIProcess/API/Cocoa/WKBrowsingContextController.mm:
(-[WKBrowsingContextController _webProcessIsResponsive]):
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _webProcessIsResponsive]):
* UIProcess/BackgroundProcessResponsivenessTimer.cpp:
(WebKit::BackgroundProcessResponsivenessTimer::BackgroundProcessResponsivenessTimer):
(WebKit::BackgroundProcessResponsivenessTimer::~BackgroundProcessResponsivenessTimer):
(WebKit::BackgroundProcessResponsivenessTimer::updateState):
(WebKit::BackgroundProcessResponsivenessTimer::didReceiveBackgroundResponsivenessPong):
(WebKit::BackgroundProcessResponsivenessTimer::invalidate):
(WebKit::BackgroundProcessResponsivenessTimer::processTerminated):
(WebKit::BackgroundProcessResponsivenessTimer::responsivenessCheckTimerFired):
(WebKit::BackgroundProcessResponsivenessTimer::timeoutTimerFired):
(WebKit::BackgroundProcessResponsivenessTimer::setResponsive):
(WebKit::BackgroundProcessResponsivenessTimer::shouldBeActive):
(WebKit::BackgroundProcessResponsivenessTimer::scheduleNextResponsivenessCheck):
(WebKit::BackgroundProcessResponsivenessTimer::client):
* UIProcess/BackgroundProcessResponsivenessTimer.h:
(WebKit::BackgroundProcessResponsivenessTimer::isResponsive):
* UIProcess/ResponsivenessTimer.h:
(WebKit::ResponsivenessTimer::isResponsive):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::resetStateAfterProcessExited):
(WebKit::WebPageProxy::updateBackingStoreDiscardableState):
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::WebProcessProxy):
(WebKit::WebProcessProxy::shutDown):
(WebKit::WebProcessProxy::isResponsive):
(WebKit::WebProcessProxy::didReceiveBackgroundResponsivenessPing):
(WebKit::WebProcessProxy::processTerminated):
(WebKit::WebProcessProxy::updateBackgroundResponsivenessTimer):
* UIProcess/WebProcessProxy.h:
* UIProcess/WebProcessProxy.messages.in:
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::backgroundResponsivenessPing):
* WebProcess/WebProcess.h:
* WebProcess/WebProcess.messages.in:

Source/WTF:

* wtf/RunLoop.h:
(WTF::RunLoop::TimerBase::startRepeating):
(WTF::RunLoop::TimerBase::startOneShot):
Add overloads to RunLoop::Timer that take Seconds in parameter,
for convenience.

* wtf/Seconds.h:
(WTF::Seconds::fromHours):
(WTF::seconds_literals::operator _h):
Allow _h suffix for initializing Seconds type to hours.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (213823 => 213824)


--- trunk/Source/WTF/ChangeLog	2017-03-13 11:12:47 UTC (rev 213823)
+++ trunk/Source/WTF/ChangeLog	2017-03-13 11:16:29 UTC (rev 213824)
@@ -1,3 +1,22 @@
+2017-03-13  Chris Dumez  <[email protected]>
+
+        [WK2] Only report background WebProcesses as unresponsive in the background after 90 seconds
+        https://bugs.webkit.org/show_bug.cgi?id=169425
+        <rdar://problem/30954003>
+
+        Reviewed by Andreas Kling.
+
+        * wtf/RunLoop.h:
+        (WTF::RunLoop::TimerBase::startRepeating):
+        (WTF::RunLoop::TimerBase::startOneShot):
+        Add overloads to RunLoop::Timer that take Seconds in parameter,
+        for convenience.
+
+        * wtf/Seconds.h:
+        (WTF::Seconds::fromHours):
+        (WTF::seconds_literals::operator _h):
+        Allow _h suffix for initializing Seconds type to hours.
+
 2017-03-11  Csaba Osztrogonác  <[email protected]>
 
         REGRESSION(r213645): It made JSC tests super slow and timeout on AArch64 Linux

Modified: trunk/Source/WTF/wtf/RunLoop.h (213823 => 213824)


--- trunk/Source/WTF/wtf/RunLoop.h	2017-03-13 11:12:47 UTC (rev 213823)
+++ trunk/Source/WTF/wtf/RunLoop.h	2017-03-13 11:16:29 UTC (rev 213824)
@@ -85,8 +85,10 @@
 
         void startRepeating(double repeatInterval) { start(repeatInterval, true); }
         void startRepeating(std::chrono::milliseconds repeatInterval) { startRepeating(repeatInterval.count() * 0.001); }
+        void startRepeating(Seconds repeatInterval) { startRepeating(repeatInterval.value()); }
         void startOneShot(double interval) { start(interval, false); }
         void startOneShot(std::chrono::milliseconds interval) { start(interval.count() * 0.001, false); }
+        void startOneShot(Seconds interval) { start(interval.value(), false); }
 
         WTF_EXPORT_PRIVATE void stop();
         WTF_EXPORT_PRIVATE bool isActive() const;

Modified: trunk/Source/WTF/wtf/Seconds.h (213823 => 213824)


--- trunk/Source/WTF/wtf/Seconds.h	2017-03-13 11:12:47 UTC (rev 213823)
+++ trunk/Source/WTF/wtf/Seconds.h	2017-03-13 11:16:29 UTC (rev 213824)
@@ -57,6 +57,11 @@
         return Seconds(minutes * 60);
     }
 
+    static constexpr Seconds fromHours(double hours)
+    {
+        return Seconds(hours * 3600);
+    }
+
     static constexpr Seconds fromMilliseconds(double milliseconds)
     {
         return Seconds(milliseconds / 1000);
@@ -208,6 +213,11 @@
     return Seconds::fromMinutes(minutes);
 }
 
+constexpr Seconds operator"" _h(long double hours)
+{
+    return Seconds::fromHours(hours);
+}
+
 constexpr Seconds operator"" _s(long double seconds)
 {
     return Seconds(seconds);
@@ -233,6 +243,11 @@
     return Seconds::fromMinutes(minutes);
 }
 
+constexpr Seconds operator"" _h(unsigned long long hours)
+{
+    return Seconds::fromHours(hours);
+}
+
 constexpr Seconds operator"" _s(unsigned long long seconds)
 {
     return Seconds(seconds);

Modified: trunk/Source/WebKit2/ChangeLog (213823 => 213824)


--- trunk/Source/WebKit2/ChangeLog	2017-03-13 11:12:47 UTC (rev 213823)
+++ trunk/Source/WebKit2/ChangeLog	2017-03-13 11:16:29 UTC (rev 213824)
@@ -1,3 +1,57 @@
+2017-03-13  Chris Dumez  <[email protected]>
+
+        [WK2] Only report background WebProcesses as unresponsive in the background after 90 seconds
+        https://bugs.webkit.org/show_bug.cgi?id=169425
+        <rdar://problem/30954003>
+
+        Reviewed by Andreas Kling.
+
+        The background responsiveness checking was previously relying on the
+        isResponsive(std::function<void(bool)>) API which uses the ResponsivenessTimer
+        and has a timeout of 3 seconds. We believe this is too aggressive for background
+        tabs. Update BackgroundResponsiveTimer to stop relying on ResponsivenessTimer
+        and have its own timeout Timer which a delay of 90 seconds instead.
+
+        * UIProcess/API/C/mac/WKPagePrivateMac.mm:
+        (-[WKObservablePageState _webProcessIsResponsive]):
+        * UIProcess/API/Cocoa/WKBrowsingContextController.mm:
+        (-[WKBrowsingContextController _webProcessIsResponsive]):
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _webProcessIsResponsive]):
+        * UIProcess/BackgroundProcessResponsivenessTimer.cpp:
+        (WebKit::BackgroundProcessResponsivenessTimer::BackgroundProcessResponsivenessTimer):
+        (WebKit::BackgroundProcessResponsivenessTimer::~BackgroundProcessResponsivenessTimer):
+        (WebKit::BackgroundProcessResponsivenessTimer::updateState):
+        (WebKit::BackgroundProcessResponsivenessTimer::didReceiveBackgroundResponsivenessPong):
+        (WebKit::BackgroundProcessResponsivenessTimer::invalidate):
+        (WebKit::BackgroundProcessResponsivenessTimer::processTerminated):
+        (WebKit::BackgroundProcessResponsivenessTimer::responsivenessCheckTimerFired):
+        (WebKit::BackgroundProcessResponsivenessTimer::timeoutTimerFired):
+        (WebKit::BackgroundProcessResponsivenessTimer::setResponsive):
+        (WebKit::BackgroundProcessResponsivenessTimer::shouldBeActive):
+        (WebKit::BackgroundProcessResponsivenessTimer::scheduleNextResponsivenessCheck):
+        (WebKit::BackgroundProcessResponsivenessTimer::client):
+        * UIProcess/BackgroundProcessResponsivenessTimer.h:
+        (WebKit::BackgroundProcessResponsivenessTimer::isResponsive):
+        * UIProcess/ResponsivenessTimer.h:
+        (WebKit::ResponsivenessTimer::isResponsive):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::resetStateAfterProcessExited):
+        (WebKit::WebPageProxy::updateBackingStoreDiscardableState):
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::WebProcessProxy):
+        (WebKit::WebProcessProxy::shutDown):
+        (WebKit::WebProcessProxy::isResponsive):
+        (WebKit::WebProcessProxy::didReceiveBackgroundResponsivenessPing):
+        (WebKit::WebProcessProxy::processTerminated):
+        (WebKit::WebProcessProxy::updateBackgroundResponsivenessTimer):
+        * UIProcess/WebProcessProxy.h:
+        * UIProcess/WebProcessProxy.messages.in:
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::backgroundResponsivenessPing):
+        * WebProcess/WebProcess.h:
+        * WebProcess/WebProcess.messages.in:
+
 2017-03-13  Carlos Garcia Campos  <[email protected]>
 
         Web Automation: automation commands hang when trying to navigate go/back and it's not possible

Modified: trunk/Source/WebKit2/UIProcess/API/C/mac/WKPagePrivateMac.mm (213823 => 213824)


--- trunk/Source/WebKit2/UIProcess/API/C/mac/WKPagePrivateMac.mm	2017-03-13 11:12:47 UTC (rev 213823)
+++ trunk/Source/WebKit2/UIProcess/API/C/mac/WKPagePrivateMac.mm	2017-03-13 11:16:29 UTC (rev 213824)
@@ -88,7 +88,7 @@
 
 - (BOOL)_webProcessIsResponsive
 {
-    return _page->process().responsivenessTimer().isResponsive();
+    return _page->process().isResponsive();
 }
 
 - (double)estimatedProgress

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKBrowsingContextController.mm (213823 => 213824)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKBrowsingContextController.mm	2017-03-13 11:12:47 UTC (rev 213823)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKBrowsingContextController.mm	2017-03-13 11:16:29 UTC (rev 213824)
@@ -779,7 +779,7 @@
 
 - (BOOL)_webProcessIsResponsive
 {
-    return _page->process().responsivenessTimer().isResponsive();
+    return _page->process().isResponsive();
 }
 
 @end

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (213823 => 213824)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2017-03-13 11:12:47 UTC (rev 213823)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2017-03-13 11:16:29 UTC (rev 213824)
@@ -4357,7 +4357,7 @@
 
 - (BOOL)_webProcessIsResponsive
 {
-    return _page->process().responsivenessTimer().isResponsive();
+    return _page->process().isResponsive();
 }
 
 - (void)_setFullscreenDelegate:(id<_WKFullscreenDelegate>)delegate

Modified: trunk/Source/WebKit2/UIProcess/BackgroundProcessResponsivenessTimer.cpp (213823 => 213824)


--- trunk/Source/WebKit2/UIProcess/BackgroundProcessResponsivenessTimer.cpp	2017-03-13 11:12:47 UTC (rev 213823)
+++ trunk/Source/WebKit2/UIProcess/BackgroundProcessResponsivenessTimer.cpp	2017-03-13 11:16:29 UTC (rev 213824)
@@ -27,48 +27,123 @@
 #include "BackgroundProcessResponsivenessTimer.h"
 
 #include "Logging.h"
+#include "WebProcessMessages.h"
+#include "WebProcessProxy.h"
 
 namespace WebKit {
 
-static const std::chrono::seconds initialInterval { 20s };
-static const std::chrono::seconds maximumInterval { 8h };
+static const Seconds initialCheckingInterval { 20_s };
+static const Seconds maximumCheckingInterval { 8_h };
+static const Seconds responsivenessTimeout { 90_s };
 
 BackgroundProcessResponsivenessTimer::BackgroundProcessResponsivenessTimer(WebProcessProxy& webProcessProxy)
     : m_webProcessProxy(webProcessProxy)
-    , m_interval(initialInterval)
-    , m_timer(RunLoop::main(), this, &BackgroundProcessResponsivenessTimer::timerFired)
+    , m_checkingInterval(initialCheckingInterval)
+    , m_responsivenessCheckTimer(RunLoop::main(), this, &BackgroundProcessResponsivenessTimer::responsivenessCheckTimerFired)
+    , m_timeoutTimer(RunLoop::main(), this, &BackgroundProcessResponsivenessTimer::timeoutTimerFired)
 {
 }
 
+BackgroundProcessResponsivenessTimer::~BackgroundProcessResponsivenessTimer()
+{
+}
+
 void BackgroundProcessResponsivenessTimer::updateState()
 {
     if (!shouldBeActive()) {
-        if (m_timer.isActive()) {
-            m_interval = initialInterval;
-            m_timer.stop();
+        if (m_responsivenessCheckTimer.isActive()) {
+            m_checkingInterval = initialCheckingInterval;
+            m_responsivenessCheckTimer.stop();
         }
+        m_timeoutTimer.stop();
+        m_isResponsive = true;
         return;
     }
 
-    if (!m_timer.isActive())
-        m_timer.startOneShot(m_interval);
+    if (!m_responsivenessCheckTimer.isActive())
+        m_responsivenessCheckTimer.startOneShot(m_checkingInterval);
 }
 
-void BackgroundProcessResponsivenessTimer::timerFired()
+void BackgroundProcessResponsivenessTimer::didReceiveBackgroundResponsivenessPong()
 {
+    if (!m_timeoutTimer.isActive())
+        return;
+
+    m_timeoutTimer.stop();
+    scheduleNextResponsivenessCheck();
+
+    setResponsive(true);
+}
+
+void BackgroundProcessResponsivenessTimer::invalidate()
+{
+    m_timeoutTimer.stop();
+    m_responsivenessCheckTimer.stop();
+}
+
+void BackgroundProcessResponsivenessTimer::processTerminated()
+{
+    invalidate();
+    setResponsive(true);
+}
+
+void BackgroundProcessResponsivenessTimer::responsivenessCheckTimerFired()
+{
     ASSERT(shouldBeActive());
-    // WebProcessProxy::responsive() takes care of calling processDidBecomeUnresponsive for us.
-    m_webProcessProxy.isResponsive([this](bool processIsResponsive) {
-        if (processIsResponsive) {
-            // Exponential backoff to avoid waking up the process too often.
-            m_interval = std::min(m_interval * 2, maximumInterval);
-            m_timer.startOneShot(m_interval);
-            return;
-        }
+    ASSERT(!m_timeoutTimer.isActive());
 
-        RELEASE_LOG_ERROR(PerformanceLogging, "Notified the client that a background WebProcess has become unresponsive");
-        m_interval = initialInterval;
-    });
+    m_timeoutTimer.startOneShot(responsivenessTimeout);
+    m_webProcessProxy.send(Messages::WebProcess::BackgroundResponsivenessPing(), 0);
 }
 
+void BackgroundProcessResponsivenessTimer::timeoutTimerFired()
+{
+    ASSERT(shouldBeActive());
+
+    scheduleNextResponsivenessCheck();
+
+    if (!m_isResponsive)
+        return;
+
+    if (!client().mayBecomeUnresponsive())
+        return;
+
+    setResponsive(false);
+}
+
+void BackgroundProcessResponsivenessTimer::setResponsive(bool isResponsive)
+{
+    if (m_isResponsive == isResponsive)
+        return;
+
+    client().willChangeIsResponsive();
+    m_isResponsive = isResponsive;
+    client().didChangeIsResponsive();
+
+    if (m_isResponsive) {
+        RELEASE_LOG_ERROR(PerformanceLogging, "Notifying the client that a background WebProcess has become responsive again");
+        client().didBecomeResponsive();
+    } else {
+        RELEASE_LOG_ERROR(PerformanceLogging, "Notifying the client that a background WebProcess has become unresponsive");
+        client().didBecomeUnresponsive();
+    }
+}
+
+bool BackgroundProcessResponsivenessTimer::shouldBeActive() const
+{
+    return !m_webProcessProxy.visiblePageCount() && m_webProcessProxy.pageCount();
+}
+
+void BackgroundProcessResponsivenessTimer::scheduleNextResponsivenessCheck()
+{
+    // Exponential backoff to avoid waking up the process too often.
+    m_checkingInterval = std::min(m_checkingInterval * 2, maximumCheckingInterval);
+    m_responsivenessCheckTimer.startOneShot(m_checkingInterval);
+}
+
+ResponsivenessTimer::Client& BackgroundProcessResponsivenessTimer::client() const
+{
+    return m_webProcessProxy;
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/BackgroundProcessResponsivenessTimer.h (213823 => 213824)


--- trunk/Source/WebKit2/UIProcess/BackgroundProcessResponsivenessTimer.h	2017-03-13 11:12:47 UTC (rev 213823)
+++ trunk/Source/WebKit2/UIProcess/BackgroundProcessResponsivenessTimer.h	2017-03-13 11:16:29 UTC (rev 213824)
@@ -25,23 +25,39 @@
 
 #pragma once
 
-#include "WebProcessProxy.h"
+#include "ResponsivenessTimer.h"
 #include <wtf/RunLoop.h>
 
 namespace WebKit {
 
+class WebProcessProxy;
+
 class BackgroundProcessResponsivenessTimer {
 public:
     explicit BackgroundProcessResponsivenessTimer(WebProcessProxy&);
+    ~BackgroundProcessResponsivenessTimer();
     void updateState();
 
+    void didReceiveBackgroundResponsivenessPong();
+    bool isResponsive() const { return m_isResponsive; }
+
+    void invalidate();
+    void processTerminated();
+
 private:
-    void timerFired();
-    bool shouldBeActive() const { return !m_webProcessProxy.visiblePageCount() && m_webProcessProxy.pageCount(); }
+    void responsivenessCheckTimerFired();
+    void timeoutTimerFired();
+    void setResponsive(bool);
 
+    bool shouldBeActive() const;
+    void scheduleNextResponsivenessCheck();
+    ResponsivenessTimer::Client& client() const;
+
     WebProcessProxy& m_webProcessProxy;
-    std::chrono::seconds m_interval;
-    RunLoop::Timer<BackgroundProcessResponsivenessTimer> m_timer;
+    Seconds m_checkingInterval;
+    RunLoop::Timer<BackgroundProcessResponsivenessTimer> m_responsivenessCheckTimer;
+    RunLoop::Timer<BackgroundProcessResponsivenessTimer> m_timeoutTimer;
+    bool m_isResponsive { true };
 };
 
 }

Modified: trunk/Source/WebKit2/UIProcess/ResponsivenessTimer.h (213823 => 213824)


--- trunk/Source/WebKit2/UIProcess/ResponsivenessTimer.h	2017-03-13 11:12:47 UTC (rev 213823)
+++ trunk/Source/WebKit2/UIProcess/ResponsivenessTimer.h	2017-03-13 11:16:29 UTC (rev 213824)
@@ -52,7 +52,7 @@
 
     void invalidate();
     
-    bool isResponsive() { return m_isResponsive; }
+    bool isResponsive() const { return m_isResponsive; }
 
     void processTerminated();
 

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (213823 => 213824)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2017-03-13 11:12:47 UTC (rev 213823)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2017-03-13 11:16:29 UTC (rev 213824)
@@ -5514,7 +5514,7 @@
     PageLoadState::Transaction transaction = m_pageLoadState.transaction();
     m_pageLoadState.reset(transaction);
 
-    m_process->responsivenessTimer().processTerminated();
+    m_process->processTerminated();
 }
 
 WebPageCreationParameters WebPageProxy::creationParameters()
@@ -6027,7 +6027,7 @@
 
     bool isDiscardable;
 
-    if (!m_process->responsivenessTimer().isResponsive())
+    if (!m_process->isResponsive())
         isDiscardable = false;
     else
         isDiscardable = !m_pageClient.isViewWindowActive() || !isViewVisible();

Modified: trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp (213823 => 213824)


--- trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp	2017-03-13 11:12:47 UTC (rev 213823)
+++ trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp	2017-03-13 11:16:29 UTC (rev 213824)
@@ -29,7 +29,6 @@
 #include "APIFrameHandle.h"
 #include "APIPageGroupHandle.h"
 #include "APIPageHandle.h"
-#include "BackgroundProcessResponsivenessTimer.h"
 #include "DataReference.h"
 #include "DownloadProxyMap.h"
 #include "Logging.h"
@@ -97,6 +96,7 @@
 WebProcessProxy::WebProcessProxy(WebProcessPool& processPool, WebsiteDataStore* websiteDataStore)
     : ChildProcessProxy(processPool.alwaysRunsAtBackgroundPriority())
     , m_responsivenessTimer(*this)
+    , m_backgroundResponsivenessTimer(*this)
     , m_processPool(processPool)
     , m_mayHaveUniversalFileReadSandboxExtension(false)
     , m_numberOfTimesSuddenTerminationWasDisabled(0)
@@ -103,7 +103,6 @@
     , m_throttler(*this)
     , m_isResponsive(NoOrMaybe::Maybe)
     , m_visiblePageCounter([this](RefCounterEvent) { updateBackgroundResponsivenessTimer(); })
-    , m_backgroundResponsivenessTimer(std::make_unique<BackgroundProcessResponsivenessTimer>(*this))
     , m_websiteDataStore(websiteDataStore)
 {
     WebPasteboardProxy::singleton().addWebProcessProxy(*this);
@@ -177,6 +176,7 @@
     }
 
     m_responsivenessTimer.invalidate();
+    m_backgroundResponsivenessTimer.invalidate();
     m_tokenForHoldingLockedFiles = nullptr;
 
     Vector<RefPtr<WebFrameProxy>> frames;
@@ -741,6 +741,11 @@
     return result.iterator->value;
 }
 
+bool WebProcessProxy::isResponsive() const
+{
+    return m_responsivenessTimer.isResponsive() && m_backgroundResponsivenessTimer.isResponsive();
+}
+
 void WebProcessProxy::didDestroyUserGestureToken(uint64_t identifier)
 {
     ASSERT(UserInitiatedActionMap::isValidKey(identifier));
@@ -1097,10 +1102,20 @@
         callback(isWebProcessResponsive);
 }
 
+void WebProcessProxy::didReceiveBackgroundResponsivenessPing()
+{
+    m_backgroundResponsivenessTimer.didReceiveBackgroundResponsivenessPong();
+}
+
+void WebProcessProxy::processTerminated()
+{
+    m_responsivenessTimer.processTerminated();
+    m_backgroundResponsivenessTimer.processTerminated();
+}
+
 void WebProcessProxy::updateBackgroundResponsivenessTimer()
 {
-    if (m_backgroundResponsivenessTimer)
-        m_backgroundResponsivenessTimer->updateState();
+    m_backgroundResponsivenessTimer.updateState();
 }
 
 #if !PLATFORM(COCOA)

Modified: trunk/Source/WebKit2/UIProcess/WebProcessProxy.h (213823 => 213824)


--- trunk/Source/WebKit2/UIProcess/WebProcessProxy.h	2017-03-13 11:12:47 UTC (rev 213823)
+++ trunk/Source/WebKit2/UIProcess/WebProcessProxy.h	2017-03-13 11:16:29 UTC (rev 213824)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include "APIUserInitiatedAction.h"
+#include "BackgroundProcessResponsivenessTimer.h"
 #include "ChildProcessProxy.h"
 #include "MessageReceiverMap.h"
 #include "PluginInfoStore.h"
@@ -54,7 +55,6 @@
 
 namespace WebKit {
 
-class BackgroundProcessResponsivenessTimer;
 class NetworkProcessProxy;
 class WebBackForwardListItem;
 class WebPageGroup;
@@ -64,7 +64,7 @@
 struct WebNavigationDataStore;
 struct WebsiteData;
 
-class WebProcessProxy : public ChildProcessProxy, ResponsivenessTimer::Client, private ProcessThrottlerClient {
+class WebProcessProxy : public ChildProcessProxy, public ResponsivenessTimer::Client, private ProcessThrottlerClient {
 public:
     typedef HashMap<uint64_t, RefPtr<WebBackForwardListItem>> WebBackForwardListItemMap;
     typedef HashMap<uint64_t, RefPtr<WebFrameProxy>> WebFrameProxyMap;
@@ -99,6 +99,7 @@
     RefPtr<API::UserInitiatedAction> userInitiatedActivity(uint64_t);
 
     ResponsivenessTimer& responsivenessTimer() { return m_responsivenessTimer; }
+    bool isResponsive() const;
 
     WebFrameProxy* webFrame(uint64_t) const;
     bool canCreateFrame(uint64_t frameID) const;
@@ -157,10 +158,13 @@
 
     void isResponsive(std::function<void(bool isWebProcessResponsive)>);
     void didReceiveMainThreadPing();
+    void didReceiveBackgroundResponsivenessPing();
 
     void memoryPressureStatusChanged(bool isUnderMemoryPressure) { m_isUnderMemoryPressure = isUnderMemoryPressure; }
     bool isUnderMemoryPressure() const { return m_isUnderMemoryPressure; }
 
+    void processTerminated();
+
 private:
     explicit WebProcessProxy(WebProcessPool&, WebsiteDataStore*);
 
@@ -233,6 +237,7 @@
     bool canTerminateChildProcess();
 
     ResponsivenessTimer m_responsivenessTimer;
+    BackgroundProcessResponsivenessTimer m_backgroundResponsivenessTimer;
     
     RefPtr<WebConnectionToWebProcess> m_webConnection;
     Ref<WebProcessPool> m_processPool;
@@ -262,7 +267,6 @@
     Vector<std::function<void(bool webProcessIsResponsive)>> m_isResponsiveCallbacks;
 
     VisibleWebPageCounter m_visiblePageCounter;
-    std::unique_ptr<BackgroundProcessResponsivenessTimer> m_backgroundResponsivenessTimer;
 
     // FIXME: WebsiteDataStores should be made per-WebPageProxy throughout WebKit2. Get rid of this member.
     RefPtr<WebsiteDataStore> m_websiteDataStore;

Modified: trunk/Source/WebKit2/UIProcess/WebProcessProxy.messages.in (213823 => 213824)


--- trunk/Source/WebKit2/UIProcess/WebProcessProxy.messages.in	2017-03-13 11:12:47 UTC (rev 213823)
+++ trunk/Source/WebKit2/UIProcess/WebProcessProxy.messages.in	2017-03-13 11:16:29 UTC (rev 213824)
@@ -49,6 +49,7 @@
     ReleaseIconForPageURL(String pageURL)
 
     DidReceiveMainThreadPing()
+    DidReceiveBackgroundResponsivenessPing()
 
     MemoryPressureStatusChanged(bool isUnderMemoryPressure)
 }

Modified: trunk/Source/WebKit2/WebProcess/WebProcess.cpp (213823 => 213824)


--- trunk/Source/WebKit2/WebProcess/WebProcess.cpp	2017-03-13 11:12:47 UTC (rev 213823)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.cpp	2017-03-13 11:16:29 UTC (rev 213824)
@@ -1020,6 +1020,11 @@
     parentProcessConnection()->send(Messages::WebProcessProxy::DidReceiveMainThreadPing(), 0);
 }
 
+void WebProcess::backgroundResponsivenessPing()
+{
+    parentProcessConnection()->send(Messages::WebProcessProxy::DidReceiveBackgroundResponsivenessPing(), 0);
+}
+
 #if ENABLE(GAMEPAD)
 
 void WebProcess::setInitialGamepads(const Vector<WebKit::GamepadData>& gamepadDatas)

Modified: trunk/Source/WebKit2/WebProcess/WebProcess.h (213823 => 213824)


--- trunk/Source/WebKit2/WebProcess/WebProcess.h	2017-03-13 11:12:47 UTC (rev 213823)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.h	2017-03-13 11:16:29 UTC (rev 213824)
@@ -283,6 +283,7 @@
     void setJavaScriptGarbageCollectorTimerEnabled(bool flag);
 
     void mainThreadPing();
+    void backgroundResponsivenessPing();
 
 #if ENABLE(GAMEPAD)
     void setInitialGamepads(const Vector<GamepadData>&);

Modified: trunk/Source/WebKit2/WebProcess/WebProcess.messages.in (213823 => 213824)


--- trunk/Source/WebKit2/WebProcess/WebProcess.messages.in	2017-03-13 11:12:47 UTC (rev 213823)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.messages.in	2017-03-13 11:16:29 UTC (rev 213824)
@@ -100,6 +100,7 @@
     ProcessDidResume()
 
     MainThreadPing()
+    BackgroundResponsivenessPing()
 
 #if ENABLE(GAMEPAD)
     SetInitialGamepads(Vector<WebKit::GamepadData> gamepadDatas)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to