Simplify WebProcessProxy state accessors
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Feb 2014 23:16:41 +0000 (23:16 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Feb 2014 23:16:41 +0000 (23:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=129453

Reviewed by Andreas Kling.

Replace WebProcessProxy::isLaunching() and WebProcessProxy::isValid() with a single
WebProcessProxy::state() that return one of three values: Launching, Running or Terminated.

* Shared/ChildProcessProxy.cpp:
(WebKit::ChildProcessProxy::state):
(WebKit::ChildProcessProxy::sendMessage):
(WebKit::ChildProcessProxy::abortProcessLaunchIfNeeded):
* Shared/ChildProcessProxy.h:
(WebKit::ChildProcessProxy::canSendMessage):
* UIProcess/Databases/DatabaseProcessProxy.cpp:
(WebKit::DatabaseProcessProxy::getDatabaseProcessConnection):
* UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::getNetworkProcessConnection):
* UIProcess/Network/mac/NetworkProcessProxyMac.mm:
(WebKit::NetworkProcessProxy::setProcessSuppressionEnabled):
* UIProcess/Plugins/PluginProcessProxy.cpp:
(WebKit::PluginProcessProxy::getPluginProcessConnection):
(WebKit::PluginProcessProxy::getSitesWithData):
(WebKit::PluginProcessProxy::clearSiteData):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::WebPageProxy):
(WebKit::WebPageProxy::reattachToWebProcess):
(WebKit::WebPageProxy::waitForDidUpdateViewState):
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::requestTermination):
(WebKit::WebProcessProxy::enableSuddenTermination):
(WebKit::WebProcessProxy::disableSuddenTermination):
* UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.mm:
(WebKit::TiledCoreAnimationDrawingAreaProxy::waitForPossibleGeometryUpdate):
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::shouldDelayWindowOrderingForEvent):
* UIProcess/mac/WebProcessProxyMac.mm:
(WebKit::WebProcessProxy::updateProcessSuppressionState):

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

12 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/ChildProcessProxy.cpp
Source/WebKit2/Shared/ChildProcessProxy.h
Source/WebKit2/UIProcess/Databases/DatabaseProcessProxy.cpp
Source/WebKit2/UIProcess/Network/NetworkProcessProxy.cpp
Source/WebKit2/UIProcess/Network/mac/NetworkProcessProxyMac.mm
Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebProcessProxy.cpp
Source/WebKit2/UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.mm
Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm
Source/WebKit2/UIProcess/mac/WebProcessProxyMac.mm

index 1dd7e614e9e3eb90ede652668ab924387077b075..d3719ed61b972bfe1b2cce011497c864e3508ab8 100644 (file)
@@ -1,3 +1,44 @@
+2014-02-27  Anders Carlsson  <andersca@apple.com>
+
+        Simplify WebProcessProxy state accessors
+        https://bugs.webkit.org/show_bug.cgi?id=129453
+
+        Reviewed by Andreas Kling.
+
+        Replace WebProcessProxy::isLaunching() and WebProcessProxy::isValid() with a single
+        WebProcessProxy::state() that return one of three values: Launching, Running or Terminated.
+
+        * Shared/ChildProcessProxy.cpp:
+        (WebKit::ChildProcessProxy::state):
+        (WebKit::ChildProcessProxy::sendMessage):
+        (WebKit::ChildProcessProxy::abortProcessLaunchIfNeeded):
+        * Shared/ChildProcessProxy.h:
+        (WebKit::ChildProcessProxy::canSendMessage):
+        * UIProcess/Databases/DatabaseProcessProxy.cpp:
+        (WebKit::DatabaseProcessProxy::getDatabaseProcessConnection):
+        * UIProcess/Network/NetworkProcessProxy.cpp:
+        (WebKit::NetworkProcessProxy::getNetworkProcessConnection):
+        * UIProcess/Network/mac/NetworkProcessProxyMac.mm:
+        (WebKit::NetworkProcessProxy::setProcessSuppressionEnabled):
+        * UIProcess/Plugins/PluginProcessProxy.cpp:
+        (WebKit::PluginProcessProxy::getPluginProcessConnection):
+        (WebKit::PluginProcessProxy::getSitesWithData):
+        (WebKit::PluginProcessProxy::clearSiteData):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::WebPageProxy):
+        (WebKit::WebPageProxy::reattachToWebProcess):
+        (WebKit::WebPageProxy::waitForDidUpdateViewState):
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::requestTermination):
+        (WebKit::WebProcessProxy::enableSuddenTermination):
+        (WebKit::WebProcessProxy::disableSuddenTermination):
+        * UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.mm:
+        (WebKit::TiledCoreAnimationDrawingAreaProxy::waitForPossibleGeometryUpdate):
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::shouldDelayWindowOrderingForEvent):
+        * UIProcess/mac/WebProcessProxyMac.mm:
+        (WebKit::WebProcessProxy::updateProcessSuppressionState):
+
 2014-02-27  Simon Fraser  <simon.fraser@apple.com>
 
         Crash tapping on play button on video on iOS
index 264d10b24578e4a312aa46e4e1a1fb5db18bc968..14ac5bb0702b88b3eee22c0f2a3a969730ea805c 100644 (file)
@@ -69,19 +69,33 @@ void ChildProcessProxy::terminate()
         m_processLauncher->terminateProcess();
 }
 
+ChildProcessProxy::State ChildProcessProxy::state() const
+{
+    if (m_processLauncher && m_processLauncher->isLaunching())
+        return ChildProcessProxy::State::Launching;
+
+    if (!m_connection)
+        return ChildProcessProxy::State::Terminated;
+
+    return ChildProcessProxy::State::Running;
+}
+
 bool ChildProcessProxy::sendMessage(std::unique_ptr<IPC::MessageEncoder> encoder, unsigned messageSendFlags)
 {
-    // If we're waiting for the child process to launch, we need to stash away the messages so we can send them once we have a connection.
-    if (isLaunching()) {
+    switch (state()) {
+    case State::Launching:
+        // If we're waiting for the child process to launch, we need to stash away the messages so we can send them once we have a connection.
         m_pendingMessages.append(std::make_pair(std::move(encoder), messageSendFlags));
         return true;
-    }
 
-    // If the web process has exited, connection will be null here.
-    if (!m_connection)
+    case State::Running:
+        return connection()->sendMessage(std::move(encoder), messageSendFlags);
+
+    case State::Terminated:
         return false;
+    }
 
-    return connection()->sendMessage(std::move(encoder), messageSendFlags);
+    return false;
 }
 
 void ChildProcessProxy::addMessageReceiver(IPC::StringReference messageReceiverName, IPC::MessageReceiver& messageReceiver)
@@ -109,14 +123,6 @@ bool ChildProcessProxy::dispatchSyncMessage(IPC::Connection* connection, IPC::Me
     return m_messageReceiverMap.dispatchSyncMessage(connection, decoder, replyEncoder);
 }
 
-bool ChildProcessProxy::isLaunching() const
-{
-    if (m_processLauncher)
-        return m_processLauncher->isLaunching();
-
-    return false;
-}
-
 void ChildProcessProxy::didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier connectionIdentifier)
 {
     ASSERT(!m_connection);
@@ -140,11 +146,11 @@ void ChildProcessProxy::didFinishLaunching(ProcessLauncher*, IPC::Connection::Id
 
 void ChildProcessProxy::abortProcessLaunchIfNeeded()
 {
-    if (!isLaunching())
+    if (state() != State::Launching)
         return;
 
     m_processLauncher->invalidate();
-    m_processLauncher = 0;
+    m_processLauncher = nullptr;
 }
 
 void ChildProcessProxy::clearConnection()
index f53b98a526dba22eb64d9ce84158eea22c862f7a..b61b19b4114b4eb052a71ed952a7a0c20e02e3f3 100644 (file)
@@ -60,9 +60,15 @@ public:
     void addMessageReceiver(IPC::StringReference messageReceiverName, uint64_t destinationID, IPC::MessageReceiver&);
     void removeMessageReceiver(IPC::StringReference messageReceiverName, uint64_t destinationID);
 
-    bool isValid() const { return m_connection; }
-    bool isLaunching() const;
-    bool canSendMessage() const { return isValid() || isLaunching(); }
+    enum class State {
+        Launching,
+        Running,
+        Terminated,
+    };
+    State state() const;
+
+//    bool isValid() const { return m_connection; }
+    bool canSendMessage() const { return state() != State::Terminated;}
 
     PlatformProcessIdentifier processIdentifier() const { return m_processLauncher->processIdentifier(); }
 
index 841a798cbcd46d8ee2a631deaaf81994710d852e..bb9d5342faaf6655ed1c38e668123d966b28ee61 100644 (file)
@@ -70,7 +70,7 @@ void DatabaseProcessProxy::getDatabaseProcessConnection(PassRefPtr<Messages::Web
 {
     m_pendingConnectionReplies.append(reply);
 
-    if (isLaunching()) {
+    if (state() == State::Launching) {
         m_numPendingConnectionRequests++;
         return;
     }
index 8d86bf140489b02abf6685c9485bef3af98c429d..067e30ef33c2facb9f9bfa3c3b32cf91e5e3a0ff 100644 (file)
@@ -87,7 +87,7 @@ void NetworkProcessProxy::getNetworkProcessConnection(PassRefPtr<Messages::WebPr
 {
     m_pendingConnectionReplies.append(reply);
 
-    if (isLaunching()) {
+    if (state() == State::Launching) {
         m_numPendingConnectionRequests++;
         return;
     }
index f063ea839def65d6df395948edbdc481394cdd74..ffb5d3a29b723463a4d7418725940a1c16891e99 100644 (file)
@@ -36,7 +36,7 @@ namespace WebKit {
 
 void NetworkProcessProxy::setProcessSuppressionEnabled(bool processSuppressionEnabled)
 {
-    if (!isValid())
+    if (state() != State::Running)
         return;
     
     connection()->send(Messages::NetworkProcess::SetProcessSuppressionEnabled(processSuppressionEnabled), 0);
index 2c15f5e6b830a622842894e61e204c2fc0393a0d..4e4f30ccc59b193b897b83ebe7d7e19588142157 100644 (file)
@@ -88,7 +88,7 @@ void PluginProcessProxy::getPluginProcessConnection(PassRefPtr<Messages::WebProc
 {
     m_pendingConnectionReplies.append(reply);
 
-    if (isLaunching()) {
+    if (state() == State::Launching) {
         m_numPendingConnectionRequests++;
         return;
     }
@@ -103,7 +103,7 @@ void PluginProcessProxy::getSitesWithData(WebPluginSiteDataManager* webPluginSit
     ASSERT(!m_pendingGetSitesReplies.contains(callbackID));
     m_pendingGetSitesReplies.set(callbackID, webPluginSiteDataManager);
 
-    if (isLaunching()) {
+    if (state() == State::Launching) {
         m_pendingGetSitesRequests.append(callbackID);
         return;
     }
@@ -117,7 +117,7 @@ void PluginProcessProxy::clearSiteData(WebPluginSiteDataManager* webPluginSiteDa
     ASSERT(!m_pendingClearSiteDataReplies.contains(callbackID));
     m_pendingClearSiteDataReplies.set(callbackID, webPluginSiteDataManager);
 
-    if (isLaunching()) {
+    if (state() == State::Launching) {
         ClearSiteDataRequest request;
         request.sites = sites;
         request.flags = flags;
index 5c8ec73ab06c9856a5aa544ac8c9c0594c900e09..a3e1d0307281b03a343875dfb605e92342883e39 100644 (file)
@@ -371,7 +371,8 @@ WebPageProxy::WebPageProxy(PageClient& pageClient, WebProcessProxy& process, uin
     m_process->addMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID, *this);
 
     // FIXME: If we ever expose the session storage size as a preference, we need to pass it here.
-    m_process->context().storageManager().createSessionStorageNamespace(m_pageID, m_process->isValid() ? m_process->connection() : 0, std::numeric_limits<unsigned>::max());
+    IPC::Connection* connection = m_process->state() == WebProcessProxy::State::Running ? m_process->connection() : nullptr;
+    m_process->context().storageManager().createSessionStorageNamespace(m_pageID, connection, std::numeric_limits<unsigned>::max());
     setSession(*configuration.session);
 }
 
@@ -483,8 +484,7 @@ void WebPageProxy::initializeContextMenuClient(const WKPageContextMenuClientBase
 void WebPageProxy::reattachToWebProcess()
 {
     ASSERT(!isValid());
-    ASSERT(!m_process->isValid());
-    ASSERT(!m_process->isLaunching());
+    ASSERT(m_process->state() == WebProcessProxy::State::Terminated);
 
     updateViewState();
 
@@ -1031,7 +1031,7 @@ void WebPageProxy::waitForDidUpdateViewState()
 
     m_waitingForDidUpdateViewState = true;
 
-    if (!m_process->isLaunching()) {
+    if (m_process->state() != WebProcessProxy::State::Launching) {
         auto viewStateUpdateTimeout = std::chrono::milliseconds(250);
         m_process->connection()->waitForAndDispatchImmediately<Messages::WebPageProxy::DidUpdateViewState>(m_pageID, viewStateUpdateTimeout);
     }
index a9963e118006a9eff2a9a4a44c1c573b9fb04cd2..22f9ac048b7c442eac17be539d3a6ef12acff637 100644 (file)
@@ -646,7 +646,7 @@ void WebProcessProxy::windowServerConnectionStateChanged()
 
 void WebProcessProxy::requestTermination()
 {
-    if (!isValid())
+    if (state() != State::Running)
         return;
 
     ChildProcessProxy::terminate();
@@ -659,7 +659,7 @@ void WebProcessProxy::requestTermination()
 
 void WebProcessProxy::enableSuddenTermination()
 {
-    if (!isValid())
+    if (state() != State::Running)
         return;
 
     ASSERT(m_numberOfTimesSuddenTerminationWasDisabled);
@@ -669,7 +669,7 @@ void WebProcessProxy::enableSuddenTermination()
 
 void WebProcessProxy::disableSuddenTermination()
 {
-    if (!isValid())
+    if (state() != State::Running)
         return;
 
     WebCore::disableSuddenTermination();
index 523d99a1958d042c9d12868131e726f76c1ffd23..ae06cd3dd2f089653fedcf7c83d399e428a1cebf 100644 (file)
@@ -72,7 +72,7 @@ void TiledCoreAnimationDrawingAreaProxy::waitForPossibleGeometryUpdate(std::chro
     if (!m_isWaitingForDidUpdateGeometry)
         return;
 
-    if (m_webPageProxy->process().isLaunching())
+    if (m_webPageProxy->process().state() != WebProcessProxy::State::Running)
         return;
 
     m_webPageProxy->process().connection()->waitForAndDispatchImmediately<Messages::DrawingAreaProxy::DidUpdateGeometry>(m_webPageProxy->pageID(), timeout);
index e5be48cb0ae95213e7be097195ea9da81f793d09..2a0e54ecaa94325f1e94354d0b6153aa0b3f20d6 100644 (file)
@@ -437,7 +437,7 @@ void WebPageProxy::executeSavedCommandBySelector(const String& selector, bool& h
 
 bool WebPageProxy::shouldDelayWindowOrderingForEvent(const WebKit::WebMouseEvent& event)
 {
-    if (!process().isValid())
+    if (process().state() != WebProcessProxy::State::Running)
         return false;
 
     bool result = false;
index 9940f940188e9a0781b8a631a3defdec35fdbf55..effc20bd9ed5319914c02d876078904c61a3849e 100644 (file)
@@ -68,7 +68,7 @@ bool WebProcessProxy::allPagesAreProcessSuppressible() const
 
 void WebProcessProxy::updateProcessSuppressionState()
 {
-    if (!isValid())
+    if (state() != State::Running)
         return;
 
     bool canEnable = allPagesAreProcessSuppressible();