PPT: Closing tab that is hung or chewing 100% CPU leaves abandoned WebProcess.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 May 2013 22:55:49 +0000 (22:55 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 May 2013 22:55:49 +0000 (22:55 +0000)
<http://webkit.org/b/116464>
<rdar://problem/10103795>

Reviewed by Anders Carlsson.

Give the web process a 10 second chance to exit nicely after closing the last tab belonging to it.
This code only runs if there was something on the page (e.g an unload/beforeunload event handler)
preventing the UI process from killing it right away.

* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::WebProcessProxy):
(WebKit::WebProcessProxy::removeWebPage):
(WebKit::WebProcessProxy::forcefulTerminationTimerFired):
* UIProcess/WebProcessProxy.h:
(WebProcessProxy):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@150384 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/WebProcessProxy.cpp
Source/WebKit2/UIProcess/WebProcessProxy.h

index 66ab0ca..c7cf3ad 100644 (file)
@@ -1,3 +1,22 @@
+2013-05-20  Andreas Kling  <akling@apple.com>
+
+        PPT: Closing tab that is hung or chewing 100% CPU leaves abandoned WebProcess.
+        <http://webkit.org/b/116464>
+        <rdar://problem/10103795>
+
+        Reviewed by Anders Carlsson.
+
+        Give the web process a 10 second chance to exit nicely after closing the last tab belonging to it.
+        This code only runs if there was something on the page (e.g an unload/beforeunload event handler)
+        preventing the UI process from killing it right away.
+
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::WebProcessProxy):
+        (WebKit::WebProcessProxy::removeWebPage):
+        (WebKit::WebProcessProxy::forcefulTerminationTimerFired):
+        * UIProcess/WebProcessProxy.h:
+        (WebProcessProxy):
+
 2013-05-20  Anders Carlsson  <andersca@apple.com>
 
         Add helper function for converting a KeyedCodingValue to a CFTypeRef
index 38c866a..37468fd 100644 (file)
@@ -98,6 +98,7 @@ WebProcessProxy::WebProcessProxy(PassRefPtr<WebContext> context)
 #if PLATFORM(MAC)
     , m_processSuppressionEnabled(false)
 #endif
+    , m_forcefulTerminationTimer(RunLoop::main(), this, &WebProcessProxy::forcefulTerminationTimerFired)
 {
     connect();
 }
@@ -201,12 +202,17 @@ void WebProcessProxy::removeWebPage(uint64_t pageID)
     updateProcessSuppressionState();
 #endif
 
-#if ENABLE(NETWORK_PROCESS)
+    if (!canTerminateChildProcess())
+        return;
+
     // Terminate the web process immediately if we have enough information to confidently do so.
     // This only works if we're using a network process. Otherwise we have to wait for the web process to clean up.
-    if (!m_suddenTerminationCounter && canTerminateChildProcess() && m_context->usesNetworkProcess())
+    if (m_context->usesNetworkProcess() && !m_suddenTerminationCounter)
         requestTermination();
-#endif
+    else {
+        const double timeBeforeForcefullyKillingWebProcessInSeconds = 10;
+        m_forcefulTerminationTimer.startOneShot(timeBeforeForcefullyKillingWebProcessInSeconds);
+    }
 }
 
 Vector<WebPageProxy*> WebProcessProxy::pages() const
@@ -655,6 +661,13 @@ void WebProcessProxy::releasePageCache()
         send(Messages::WebProcess::ReleasePageCache(), 0);
 }
 
+void WebProcessProxy::forcefulTerminationTimerFired()
+{
+#if PLATFORM(MAC)
+    WTFLogAlways("Killing runaway web process, pid=%d\n", processIdentifier());
+#endif
+    requestTermination();
+}
 
 void WebProcessProxy::requestTermination()
 {
index 0212d2d..5d21411 100644 (file)
@@ -185,6 +185,7 @@ private:
     void didReceiveSyncWebProcessProxyMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&, OwnPtr<CoreIPC::MessageEncoder>&);
 
     bool canTerminateChildProcess();
+    void forcefulTerminationTimerFired();
 
     ResponsivenessTimer m_responsivenessTimer;
     
@@ -210,6 +211,8 @@ private:
     HashSet<uint64_t> m_processSuppressiblePages;
     bool m_processSuppressionEnabled;
 #endif
+
+    WebCore::RunLoop::Timer<WebProcessProxy> m_forcefulTerminationTimer;
 };
     
 } // namespace WebKit