Title: [252011] trunk/Source/WebKit
Revision
252011
Author
cdu...@apple.com
Date
2019-11-04 13:36:24 -0800 (Mon, 04 Nov 2019)

Log Message

[iOS][WK2] Simplify process assertion handling for the network process and service worker processes
https://bugs.webkit.org/show_bug.cgi?id=203633

Reviewed by Alex Christensen.

Simplify process assertion handling for the network process and service worker processes.
In particular, the following changes were made:
1. Put the NetworkProcessProxy in charge of keeping the network process runnable instead
   of relying on the WebProcessPool to do it.
2. Put the WebProcessProxy in charge of keeping the web process runnable due to service
   worker activity, instead of relying on the WebProcessPool to do it.
3. Introduce a new Variant data type which can store a foreground activity, a background
   activity or no activity. This avoid having 2 separate and mutually-exclusive data
   members for foreground and background activities.
4. The new code is a bit more correct because it makes sure the the activity we're holding
   is valid, instead of simply checking that it has an activity. This means that if the
   process assertion was previously invalidated, we will now properly take a new activity,
   which will re-take a process assertion.

This patch also reduces the #ifdefing for IOS_FAMILY, since ProcessThrottler and
ProcessAssertion exist on all platforms.

* UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::updateProcessAssertion):
* UIProcess/Network/NetworkProcessProxy.h:
* UIProcess/ProcessThrottler.cpp:
(WebKit::ProcessThrottler::isValidBackgroundActivity):
(WebKit::ProcessThrottler::isValidForegroundActivity):
* UIProcess/ProcessThrottler.h:
* UIProcess/WebProcessPool.cpp:
(WebKit::m_backgroundWebProcessCounter):
(WebKit::WebProcessPool::ensureNetworkProcess):
(WebKit::WebProcessPool::networkProcessCrashed):
(WebKit::WebProcessPool::establishWorkerContextConnectionToNetworkProcess):
(WebKit::WebProcessPool::disconnectProcess):
(WebKit::WebProcessPool::terminateNetworkProcess):
(WebKit::WebProcessPool::updateProcessAssertions):
* UIProcess/WebProcessPool.h:
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::didSetAssertionState):
(WebKit::WebProcessProxy::updateServiceWorkerProcessAssertion):
(WebKit::WebProcessProxy::enableServiceWorkers):
* UIProcess/WebProcessProxy.h:
(WebKit::WebProcessProxy::isStandaloneServiceWorkerProcess const):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (252010 => 252011)


--- trunk/Source/WebKit/ChangeLog	2019-11-04 21:21:53 UTC (rev 252010)
+++ trunk/Source/WebKit/ChangeLog	2019-11-04 21:36:24 UTC (rev 252011)
@@ -1,3 +1,50 @@
+2019-11-04  Chris Dumez  <cdu...@apple.com>
+
+        [iOS][WK2] Simplify process assertion handling for the network process and service worker processes
+        https://bugs.webkit.org/show_bug.cgi?id=203633
+
+        Reviewed by Alex Christensen.
+
+        Simplify process assertion handling for the network process and service worker processes.
+        In particular, the following changes were made:
+        1. Put the NetworkProcessProxy in charge of keeping the network process runnable instead
+           of relying on the WebProcessPool to do it.
+        2. Put the WebProcessProxy in charge of keeping the web process runnable due to service
+           worker activity, instead of relying on the WebProcessPool to do it.
+        3. Introduce a new Variant data type which can store a foreground activity, a background
+           activity or no activity. This avoid having 2 separate and mutually-exclusive data
+           members for foreground and background activities.
+        4. The new code is a bit more correct because it makes sure the the activity we're holding
+           is valid, instead of simply checking that it has an activity. This means that if the
+           process assertion was previously invalidated, we will now properly take a new activity,
+           which will re-take a process assertion.
+
+        This patch also reduces the #ifdefing for IOS_FAMILY, since ProcessThrottler and
+        ProcessAssertion exist on all platforms.
+
+        * UIProcess/Network/NetworkProcessProxy.cpp:
+        (WebKit::NetworkProcessProxy::updateProcessAssertion):
+        * UIProcess/Network/NetworkProcessProxy.h:
+        * UIProcess/ProcessThrottler.cpp:
+        (WebKit::ProcessThrottler::isValidBackgroundActivity):
+        (WebKit::ProcessThrottler::isValidForegroundActivity):
+        * UIProcess/ProcessThrottler.h:
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::m_backgroundWebProcessCounter):
+        (WebKit::WebProcessPool::ensureNetworkProcess):
+        (WebKit::WebProcessPool::networkProcessCrashed):
+        (WebKit::WebProcessPool::establishWorkerContextConnectionToNetworkProcess):
+        (WebKit::WebProcessPool::disconnectProcess):
+        (WebKit::WebProcessPool::terminateNetworkProcess):
+        (WebKit::WebProcessPool::updateProcessAssertions):
+        * UIProcess/WebProcessPool.h:
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::didSetAssertionState):
+        (WebKit::WebProcessProxy::updateServiceWorkerProcessAssertion):
+        (WebKit::WebProcessProxy::enableServiceWorkers):
+        * UIProcess/WebProcessProxy.h:
+        (WebKit::WebProcessProxy::isStandaloneServiceWorkerProcess const):
+
 2019-11-03  Jiewen Tan  <jiewen_...@apple.com>
 
         [WebAuthn] CtapAuthenticator::tryDowngrade should distinguish requestData().options

Modified: trunk/Source/WebKit/UIProcess/Cocoa/DownloadClient.mm (252010 => 252011)


--- trunk/Source/WebKit/UIProcess/Cocoa/DownloadClient.mm	2019-11-04 21:21:53 UTC (rev 252010)
+++ trunk/Source/WebKit/UIProcess/Cocoa/DownloadClient.mm	2019-11-04 21:36:24 UTC (rev 252011)
@@ -269,7 +269,7 @@
     if (auto* webPage = downloadProxy.originatingPage()) {
         RELEASE_LOG_IF(webPage->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - UIProcess is taking a background assertion because it is downloading a system preview", this);
         ASSERT(!m_activity);
-        m_activity = webPage->process().throttler().backgroundActivity("System preview download"_s);
+        m_activity = webPage->process().throttler().backgroundActivity("System preview download"_s).moveToUniquePtr();
     }
 #else
     UNUSED_PARAM(downloadProxy);

Modified: trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm (252010 => 252011)


--- trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm	2019-11-04 21:21:53 UTC (rev 252010)
+++ trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm	2019-11-04 21:36:24 UTC (rev 252011)
@@ -1237,7 +1237,7 @@
         }
         if (!m_networkActivity) {
             RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - NavigationState is taking a process network assertion because a page load started", this);
-            m_networkActivity = m_webView->_page->process().throttler().backgroundActivity("Page Load"_s);
+            m_networkActivity = m_webView->_page->process().throttler().backgroundActivity("Page Load"_s).moveToUniquePtr();
         }
     } else if (m_networkActivity) {
         // The application is visible so we delay releasing the background activity for 3 seconds to give it a chance to start another navigation
@@ -1347,7 +1347,7 @@
 #if PLATFORM(IOS_FAMILY)
     // Transfer our background assertion from the old process to the new one.
     if (m_networkActivity)
-        m_networkActivity = m_webView->_page->process().throttler().backgroundActivity("Page Load"_s);
+        m_networkActivity = m_webView->_page->process().throttler().backgroundActivity("Page Load"_s).moveToUniquePtr();
 #endif
 }
 

Modified: trunk/Source/WebKit/UIProcess/Cocoa/UIRemoteObjectRegistry.cpp (252010 => 252011)


--- trunk/Source/WebKit/UIProcess/Cocoa/UIRemoteObjectRegistry.cpp	2019-11-04 21:21:53 UTC (rev 252010)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIRemoteObjectRegistry.cpp	2019-11-04 21:36:24 UTC (rev 252011)
@@ -33,7 +33,7 @@
 
 std::unique_ptr<ProcessThrottler::BackgroundActivity> UIRemoteObjectRegistry::backgroundActivity(ASCIILiteral name)
 {
-    return m_page.process().throttler().backgroundActivity(name);
+    return m_page.process().throttler().backgroundActivity(name).moveToUniquePtr();
 }
 
 UIRemoteObjectRegistry::UIRemoteObjectRegistry(_WKRemoteObjectRegistry *remoteObjectRegistry, WebPageProxy& page)

Modified: trunk/Source/WebKit/UIProcess/GenericCallback.h (252010 => 252011)


--- trunk/Source/WebKit/UIProcess/GenericCallback.h	2019-11-04 21:21:53 UTC (rev 252010)
+++ trunk/Source/WebKit/UIProcess/GenericCallback.h	2019-11-04 21:36:24 UTC (rev 252011)
@@ -69,7 +69,7 @@
     struct TypeTag { };
     typedef const TypeTag* Type;
 
-    explicit CallbackBase(Type type, std::unique_ptr<ProcessThrottler::BackgroundActivity>&& activity)
+    explicit CallbackBase(Type type, ProcessThrottler::ActivityVariant&& activity)
         : m_type(type)
         , m_callbackID(CallbackID::generateID())
         , m_activity(WTFMove(activity))
@@ -79,7 +79,7 @@
 private:
     Type m_type;
     CallbackID m_callbackID;
-    std::unique_ptr<ProcessThrottler::BackgroundActivity> m_activity;
+    ProcessThrottler::ActivityVariant m_activity;
 };
 
 template<typename... T>
@@ -87,7 +87,7 @@
 public:
     typedef Function<void (T..., Error)> CallbackFunction;
 
-    static Ref<GenericCallback> create(CallbackFunction&& callback, std::unique_ptr<ProcessThrottler::BackgroundActivity>&& activity = nullptr)
+    static Ref<GenericCallback> create(CallbackFunction&& callback, ProcessThrottler::ActivityVariant&& activity = nullptr)
     {
         return adoptRef(*new GenericCallback(WTFMove(callback), WTFMove(activity)));
     }
@@ -126,7 +126,7 @@
     }
 
 private:
-    GenericCallback(CallbackFunction&& callback, std::unique_ptr<ProcessThrottler::BackgroundActivity>&& activity)
+    GenericCallback(CallbackFunction&& callback, ProcessThrottler::ActivityVariant&& activity)
         : CallbackBase(type(), WTFMove(activity))
         , m_callback(WTFMove(callback))
     {
@@ -189,7 +189,7 @@
     };
 
     template<typename... T>
-    CallbackID put(Function<void(T...)>&& function, std::unique_ptr<ProcessThrottler::BackgroundActivity>&& activity)
+    CallbackID put(Function<void(T...)>&& function, ProcessThrottler::ActivityVariant&& activity)
     {
         auto callback = GenericCallbackType<sizeof...(T), T...>::type::create(WTFMove(function), WTFMove(activity));
         return put(WTFMove(callback));

Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp (252010 => 252011)


--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp	2019-11-04 21:21:53 UTC (rev 252010)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp	2019-11-04 21:36:24 UTC (rev 252011)
@@ -1098,7 +1098,7 @@
     }
     if (!m_activityForHoldingLockedFiles) {
         RELEASE_LOG(ProcessSuspension, "UIProcess is taking a background assertion because the Network process is holding locked files");
-        m_activityForHoldingLockedFiles = m_throttler.backgroundActivity("Holding locked files"_s);
+        m_activityForHoldingLockedFiles = m_throttler.backgroundActivity("Holding locked files"_s).moveToUniquePtr();
     }
 }
 
@@ -1111,7 +1111,7 @@
         return;
     
     RELEASE_LOG(ProcessSuspension, "%p - NetworkProcessProxy is taking a background assertion because the Network process is syncing cookies", this);
-    m_syncAllCookiesActivity = throttler().backgroundActivity("Syncing cookies"_s);
+    m_syncAllCookiesActivity = throttler().backgroundActivity("Syncing cookies"_s).moveToUniquePtr();
 }
     
 void NetworkProcessProxy::didSyncAllCookies()
@@ -1204,16 +1204,6 @@
 }
 #endif
 
-void NetworkProcessProxy::sendProcessDidTransitionToForeground()
-{
-    send(Messages::NetworkProcess::ProcessDidTransitionToForeground(), 0);
-}
-
-void NetworkProcessProxy::sendProcessDidTransitionToBackground()
-{
-    send(Messages::NetworkProcess::ProcessDidTransitionToBackground(), 0);
-}
-
 #if ENABLE(SANDBOX_EXTENSIONS)
 void NetworkProcessProxy::getSandboxExtensionsForBlobFiles(const Vector<String>& paths, Messages::NetworkProcessProxy::GetSandboxExtensionsForBlobFiles::AsyncReply&& reply)
 {
@@ -1338,6 +1328,25 @@
     sendWithAsyncReply(Messages::NetworkProcess::GetLocalStorageOriginDetails(sessionID), WTFMove(completionHandler));
 }
 
+void NetworkProcessProxy::updateProcessAssertion()
+{
+    if (processPool().hasForegroundWebProcesses()) {
+        if (!ProcessThrottler::isValidForegroundActivity(m_activityFromWebProcesses)) {
+            m_activityFromWebProcesses = throttler().foregroundActivity("Networking for foreground view(s)"_s);
+            send(Messages::NetworkProcess::ProcessDidTransitionToForeground(), 0);
+        }
+        return;
+    }
+    if (processPool().hasBackgroundWebProcesses()) {
+        if (!ProcessThrottler::isValidBackgroundActivity(m_activityFromWebProcesses)) {
+            m_activityFromWebProcesses = throttler().backgroundActivity("Networking for foreground background view(s)"_s);
+            send(Messages::NetworkProcess::ProcessDidTransitionToBackground(), 0);
+        }
+        return;
+    }
+    m_activityFromWebProcesses = nullptr;
+}
+
 } // namespace WebKit
 
 #undef MESSAGE_CHECK

Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h (252010 => 252011)


--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2019-11-04 21:21:53 UTC (rev 252010)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2019-11-04 21:36:24 UTC (rev 252011)
@@ -160,8 +160,6 @@
     void setShouldBlockThirdPartyCookiesForTesting(PAL::SessionID, bool, CompletionHandler<void()>&&);
 #endif
     
-    void sendProcessDidTransitionToForeground();
-    void sendProcessDidTransitionToBackground();
     void synthesizeAppIsBackground(bool background);
 
     void setIsHoldingLockedFiles(bool);
@@ -172,6 +170,8 @@
     void testProcessIncomingSyncMessagesWhenWaitingForSyncReply(WebPageProxyIdentifier, Messages::NetworkProcessProxy::TestProcessIncomingSyncMessagesWhenWaitingForSyncReplyDelayedReply&&);
 
     ProcessThrottler& throttler() { return m_throttler; }
+    void updateProcessAssertion();
+
     WebProcessPool& processPool() { return m_processPool; }
 
 #if ENABLE(CONTENT_EXTENSIONS)
@@ -279,6 +279,7 @@
     ProcessThrottler m_throttler;
     std::unique_ptr<ProcessThrottler::BackgroundActivity> m_activityForHoldingLockedFiles;
     std::unique_ptr<ProcessThrottler::BackgroundActivity> m_syncAllCookiesActivity;
+    ProcessThrottler::ActivityVariant m_activityFromWebProcesses;
     
     unsigned m_syncAllCookiesCounter { 0 };
 

Modified: trunk/Source/WebKit/UIProcess/ProcessThrottler.cpp (252010 => 252011)


--- trunk/Source/WebKit/UIProcess/ProcessThrottler.cpp	2019-11-04 21:21:53 UTC (rev 252010)
+++ trunk/Source/WebKit/UIProcess/ProcessThrottler.cpp	2019-11-04 21:36:24 UTC (rev 252011)
@@ -205,4 +205,18 @@
     m_prepareToSuspendTimeoutTimer.stop();
 }
 
+bool ProcessThrottler::isValidBackgroundActivity(const ProcessThrottler::ActivityVariant& activity)
+{
+    if (!WTF::holds_alternative<UniqueRef<ProcessThrottler::BackgroundActivity>>(activity))
+        return false;
+    return WTF::get<UniqueRef<ProcessThrottler::BackgroundActivity>>(activity)->isValid();
+}
+
+bool ProcessThrottler::isValidForegroundActivity(const ProcessThrottler::ActivityVariant& activity)
+{
+    if (!WTF::holds_alternative<UniqueRef<ProcessThrottler::ForegroundActivity>>(activity))
+        return false;
+    return WTF::get<UniqueRef<ProcessThrottler::ForegroundActivity>>(activity)->isValid();
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/ProcessThrottler.h (252010 => 252011)


--- trunk/Source/WebKit/UIProcess/ProcessThrottler.h	2019-11-04 21:21:53 UTC (rev 252010)
+++ trunk/Source/WebKit/UIProcess/ProcessThrottler.h	2019-11-04 21:36:24 UTC (rev 252011)
@@ -31,6 +31,8 @@
 #include <wtf/ProcessID.h>
 #include <wtf/RefCounter.h>
 #include <wtf/RunLoop.h>
+#include <wtf/UniqueRef.h>
+#include <wtf/Variant.h>
 #include <wtf/WeakPtr.h>
 
 namespace WebKit {
@@ -86,10 +88,14 @@
     };
 
     using ForegroundActivity = Activity<ActivityType::Foreground>;
-    std::unique_ptr<ForegroundActivity> foregroundActivity(ASCIILiteral name);
+    UniqueRef<ForegroundActivity> foregroundActivity(ASCIILiteral name);
 
     using BackgroundActivity = Activity<ActivityType::Background>;
-    std::unique_ptr<BackgroundActivity> backgroundActivity(ASCIILiteral name);
+    UniqueRef<BackgroundActivity> backgroundActivity(ASCIILiteral name);
+
+    using ActivityVariant = Variant<std::nullptr_t, UniqueRef<BackgroundActivity>, UniqueRef<ForegroundActivity>>;
+    static bool isValidBackgroundActivity(const ActivityVariant&);
+    static bool isValidForegroundActivity(const ActivityVariant&);
     
     void didConnectToProcess(ProcessID);
     bool shouldBeRunnable() const { return m_foregroundActivities.size() || m_backgroundActivities.size(); }
@@ -124,14 +130,14 @@
     bool m_shouldTakeUIBackgroundAssertion;
 };
 
-inline auto ProcessThrottler::foregroundActivity(ASCIILiteral name) -> std::unique_ptr<ForegroundActivity>
+inline auto ProcessThrottler::foregroundActivity(ASCIILiteral name) -> UniqueRef<ForegroundActivity>
 {
-    return makeUnique<ForegroundActivity>(*this, name);
+    return makeUniqueRef<ForegroundActivity>(*this, name);
 }
 
-inline auto ProcessThrottler::backgroundActivity(ASCIILiteral name) -> std::unique_ptr<BackgroundActivity>
+inline auto ProcessThrottler::backgroundActivity(ASCIILiteral name) -> UniqueRef<BackgroundActivity>
 {
-    return makeUnique<BackgroundActivity>(*this, name);
+    return makeUniqueRef<BackgroundActivity>(*this, name);
 }
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/ProvisionalPageProxy.h (252010 => 252011)


--- trunk/Source/WebKit/UIProcess/ProvisionalPageProxy.h	2019-11-04 21:21:53 UTC (rev 252010)
+++ trunk/Source/WebKit/UIProcess/ProvisionalPageProxy.h	2019-11-04 21:36:24 UTC (rev 252011)
@@ -143,7 +143,7 @@
     Vector<uint8_t> m_accessibilityToken;
 #endif
 #if PLATFORM(IOS_FAMILY)
-    std::unique_ptr<ProcessThrottler::ForegroundActivity> m_provisionalLoadActivity;
+    UniqueRef<ProcessThrottler::ForegroundActivity> m_provisionalLoadActivity;
 #endif
 };
 

Modified: trunk/Source/WebKit/UIProcess/SuspendedPageProxy.cpp (252010 => 252011)


--- trunk/Source/WebKit/UIProcess/SuspendedPageProxy.cpp	2019-11-04 21:21:53 UTC (rev 252010)
+++ trunk/Source/WebKit/UIProcess/SuspendedPageProxy.cpp	2019-11-04 21:36:24 UTC (rev 252011)
@@ -102,7 +102,7 @@
     , m_shouldDelayClosingUntilEnteringAcceleratedCompositingMode(shouldDelayClosingUntilEnteringAcceleratedCompositingMode)
     , m_suspensionTimeoutTimer(RunLoop::main(), this, &SuspendedPageProxy::suspensionTimedOut)
 #if PLATFORM(IOS_FAMILY)
-    , m_suspensionActivity(m_process->throttler().backgroundActivity("Page suspension for back/forward cache"_s))
+    , m_suspensionActivity(m_process->throttler().backgroundActivity("Page suspension for back/forward cache"_s).moveToUniquePtr())
 #endif
 {
     allSuspendedPages().add(this);

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (252010 => 252011)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2019-11-04 21:21:53 UTC (rev 252010)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2019-11-04 21:36:24 UTC (rev 252011)
@@ -1935,7 +1935,7 @@
     if (isViewVisible()) {
         if (!m_isVisibleActivity || !m_isVisibleActivity->isValid()) {
             RELEASE_LOG_IF_ALLOWED(ProcessSuspension, "updateThrottleState: UIProcess is taking a foreground assertion because the view is visible");
-            m_isVisibleActivity = m_process->throttler().foregroundActivity("View is visible"_s);
+            m_isVisibleActivity = m_process->throttler().foregroundActivity("View is visible"_s).moveToUniquePtr();
         }
     } else if (m_isVisibleActivity) {
         RELEASE_LOG_IF_ALLOWED(ProcessSuspension, "updateThrottleState: UIProcess is releasing a foreground assertion because the view is no longer visible");
@@ -1946,7 +1946,7 @@
     if (isAudible) {
         if (!m_isAudibleActivity || !m_isAudibleActivity->isValid()) {
             RELEASE_LOG_IF_ALLOWED(ProcessSuspension, "updateThrottleState: UIProcess is taking a foreground assertion because we are playing audio");
-            m_isAudibleActivity = m_process->throttler().foregroundActivity("View is playing audio"_s);
+            m_isAudibleActivity = m_process->throttler().foregroundActivity("View is playing audio"_s).moveToUniquePtr();
         }
     } else if (m_isAudibleActivity) {
         RELEASE_LOG_IF_ALLOWED(ProcessSuspension, "updateThrottleState: UIProcess is releasing a foreground assertion because we are no longer playing audio");
@@ -1957,7 +1957,7 @@
     if (isCapturingMedia) {
         if (!m_isCapturingActivity || !m_isCapturingActivity->isValid()) {
             RELEASE_LOG_IF_ALLOWED(ProcessSuspension, "updateThrottleState: UIProcess is taking a foreground assertion because media capture is active");
-            m_isCapturingActivity = m_process->throttler().foregroundActivity("View is capturing media"_s);
+            m_isCapturingActivity = m_process->throttler().foregroundActivity("View is capturing media"_s).moveToUniquePtr();
         }
     } else if (m_isCapturingActivity) {
         RELEASE_LOG_IF_ALLOWED(ProcessSuspension, "updateThrottleState: UIProcess is releasing a foreground assertion because media capture is no longer active");
@@ -1967,7 +1967,7 @@
     if (m_alwaysRunsAtForegroundPriority) {
         if (!m_alwaysRunsAtForegroundPriorityActivity || !m_alwaysRunsAtForegroundPriorityActivity->isValid()) {
             RELEASE_LOG_IF_ALLOWED(ProcessSuspension, "updateThrottleState: UIProcess is taking a foreground assertion because m_alwaysRunsAtForegroundPriority is true");
-            m_alwaysRunsAtForegroundPriorityActivity = m_process->throttler().foregroundActivity("View always runs at foreground priority"_s);
+            m_alwaysRunsAtForegroundPriorityActivity = m_process->throttler().foregroundActivity("View always runs at foreground priority"_s).moveToUniquePtr();
         }
     } else if (m_alwaysRunsAtForegroundPriorityActivity) {
         RELEASE_LOG_IF_ALLOWED(ProcessSuspension, "updateThrottleState: UIProcess is releasing a foreground assertion because m_alwaysRunsAtForegroundPriority is no longer true");

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (252010 => 252011)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2019-11-04 21:21:53 UTC (rev 252010)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2019-11-04 21:36:24 UTC (rev 252011)
@@ -234,10 +234,8 @@
     , m_hiddenPageThrottlingAutoIncreasesCounter([this](RefCounterEvent) { m_hiddenPageThrottlingTimer.startOneShot(0_s); })
     , m_hiddenPageThrottlingTimer(RunLoop::main(), this, &WebProcessPool::updateHiddenPageThrottlingAutoIncreaseLimit)
     , m_serviceWorkerProcessesTerminationTimer(RunLoop::main(), this, &WebProcessPool::terminateServiceWorkerProcesses)
-#if PLATFORM(IOS_FAMILY)
     , m_foregroundWebProcessCounter([this](RefCounterEvent) { updateProcessAssertions(); })
     , m_backgroundWebProcessCounter([this](RefCounterEvent) { updateProcessAssertions(); })
-#endif
     , m_backForwardCache(makeUniqueRef<WebBackForwardCache>(*this))
     , m_webProcessCache(makeUniqueRef<WebProcessCache>(*this))
 {
@@ -632,10 +630,7 @@
     networkProcess->send(Messages::NetworkProcess::SetQOS(networkProcessLatencyQOS(), networkProcessThroughputQOS()), 0);
 #endif
 
-    if (m_didNetworkProcessCrash) {
-        m_didNetworkProcessCrash = false;
-        reinstateNetworkProcessAssertionState(*networkProcess);
-    }
+    networkProcess->updateProcessAssertion();
 
     if (withWebsiteDataStore) {
         networkProcess->addSession(makeRef(*withWebsiteDataStore));
@@ -656,7 +651,6 @@
 {
     ASSERT(m_networkProcess);
     ASSERT(&networkProcessProxy == m_networkProcess.get());
-    m_didNetworkProcessCrash = true;
 
     for (auto& supplement : m_supplements.values())
         supplement->processDidClose(&networkProcessProxy);
@@ -736,7 +730,6 @@
 
         RELEASE_LOG_IF(sessionID.isAlwaysOnLoggingAllowed(), ServiceWorker, "WebProcessPool::establishWorkerContextConnectionToNetworkProcess creating a new service worker process %p, process identifier %d", serviceWorkerProcessProxy, serviceWorkerProcessProxy->processIdentifier());
 
-        updateProcessAssertions();
         initializeNewWebProcess(newProcessProxy, websiteDataStore);
         m_processes.append(WTFMove(newProcessProxy));
     }
@@ -1130,7 +1123,6 @@
         auto iterator = m_serviceWorkerProcesses.find(RegistrableDomainWithSessionID { process->registrableDomain(), process->websiteDataStore().sessionID() });
         if (iterator != m_serviceWorkerProcesses.end() && iterator->value == process)
             m_serviceWorkerProcesses.remove(iterator);
-        updateProcessAssertions();
     }
 #endif
 
@@ -1709,7 +1701,6 @@
     
     m_networkProcess->terminate();
     m_networkProcess = nullptr;
-    m_didNetworkProcessCrash = true;
 }
 
 void WebProcessPool::sendNetworkProcessWillSuspendImminentlyForTesting()
@@ -2045,74 +2036,13 @@
 
 void WebProcessPool::updateProcessAssertions()
 {
-#if PLATFORM(IOS_FAMILY)
 #if ENABLE(SERVICE_WORKER)
-    auto updateServiceWorkerProcessAssertion = [&] {
-        if (!m_serviceWorkerProcesses.isEmpty() && m_foregroundWebProcessCounter.value()) {
-            // FIXME: We can do better than this once we have process per origin.
-            for (auto* serviceWorkerProcess : m_serviceWorkerProcesses.values()) {
-                auto registrableDomain = serviceWorkerProcess->registrableDomain();
-                if (!m_foregroundActivitiesForServiceWorkerProcesses.contains(registrableDomain))
-                    m_foregroundActivitiesForServiceWorkerProcesses.add(WTFMove(registrableDomain), serviceWorkerProcess->throttler().foregroundActivity("Service Worker for visible view(s)"_s));
-            }
-            m_backgroundActivitiesForServiceWorkerProcesses.clear();
-            return;
-        }
-        if (!m_serviceWorkerProcesses.isEmpty() && m_backgroundWebProcessCounter.value()) {
-            // FIXME: We can do better than this once we have process per origin.
-            for (auto* serviceWorkerProcess : m_serviceWorkerProcesses.values()) {
-                auto registrableDomain = serviceWorkerProcess->registrableDomain();
-                if (!m_backgroundActivitiesForServiceWorkerProcesses.contains(registrableDomain))
-                    m_backgroundActivitiesForServiceWorkerProcesses.add(WTFMove(registrableDomain), serviceWorkerProcess->throttler().backgroundActivity("Service Worker for background view(s)"_s));
-            }
-            m_foregroundActivitiesForServiceWorkerProcesses.clear();
-            return;
-        }
-        m_foregroundActivitiesForServiceWorkerProcesses.clear();
-        m_backgroundActivitiesForServiceWorkerProcesses.clear();
-    };
-    updateServiceWorkerProcessAssertion();
+    for (auto* serviceWorkerProcess : m_serviceWorkerProcesses.values())
+        serviceWorkerProcess->updateServiceWorkerProcessAssertion();
 #endif
-
-    auto updateNetworkProcessAssertion = [&] {
-        auto& networkProcess = ensureNetworkProcess();
-
-        if (m_foregroundWebProcessCounter.value()) {
-            if (!m_foregroundActivityForNetworkProcess) {
-                m_foregroundActivityForNetworkProcess = networkProcess.throttler().foregroundActivity("Networking for foreground view(s)"_s);
-                networkProcess.sendProcessDidTransitionToForeground();
-            }
-            m_backgroundActivityForNetworkProcess = nullptr;
-            return;
-        }
-        if (m_backgroundWebProcessCounter.value()) {
-            if (!m_backgroundActivityForNetworkProcess) {
-                m_backgroundActivityForNetworkProcess = networkProcess.throttler().backgroundActivity("Networking for foreground background view(s)"_s);
-                networkProcess.sendProcessDidTransitionToBackground();
-            }
-            m_foregroundActivityForNetworkProcess = nullptr;
-            return;
-        }
-        m_foregroundActivityForNetworkProcess = nullptr;
-        m_backgroundActivityForNetworkProcess = nullptr;
-    };
-    updateNetworkProcessAssertion();
-#endif
+    ensureNetworkProcess().updateProcessAssertion();
 }
 
-void WebProcessPool::reinstateNetworkProcessAssertionState(NetworkProcessProxy& newNetworkProcessProxy)
-{
-#if PLATFORM(IOS_FAMILY)
-    // The network process crashed; take new activities for the new network process.
-    if (m_backgroundActivityForNetworkProcess)
-        m_backgroundActivityForNetworkProcess = newNetworkProcessProxy.throttler().backgroundActivity("Networking for background view(s)"_s);
-    else if (m_foregroundActivityForNetworkProcess)
-        m_foregroundActivityForNetworkProcess = newNetworkProcessProxy.throttler().foregroundActivity("Networking for foreground view(s)"_s);
-#else
-    UNUSED_PARAM(newNetworkProcessProxy);
-#endif
-}
-
 bool WebProcessPool::isServiceWorkerPageID(WebPageProxyIdentifier pageID) const
 {
 #if ENABLE(SERVICE_WORKER)

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.h (252010 => 252011)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.h	2019-11-04 21:21:53 UTC (rev 252010)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.h	2019-11-04 21:36:24 UTC (rev 252011)
@@ -472,10 +472,10 @@
     static uint64_t registerProcessPoolCreationListener(Function<void(WebProcessPool&)>&&);
     static void unregisterProcessPoolCreationListener(uint64_t identifier);
 
-#if PLATFORM(IOS_FAMILY)
     ForegroundWebProcessToken foregroundWebProcessToken() const { return ForegroundWebProcessToken(m_foregroundWebProcessCounter.count()); }
     BackgroundWebProcessToken backgroundWebProcessToken() const { return BackgroundWebProcessToken(m_backgroundWebProcessCounter.count()); }
-#endif
+    bool hasForegroundWebProcesses() const { return m_foregroundWebProcessCounter.value(); }
+    bool hasBackgroundWebProcesses() const { return m_backgroundWebProcessCounter.value(); }
 
     void processForNavigation(WebPageProxy&, const API::Navigation&, Ref<WebProcessProxy>&& sourceProcess, const URL& sourceURL, ProcessSwapRequestedByClient, Ref<WebsiteDataStore>&&, CompletionHandler<void(Ref<WebProcessProxy>&&, SuspendedPageProxy*, const String&)>&&);
 
@@ -554,7 +554,6 @@
     void processStoppedUsingGamepads(WebProcessProxy&);
 #endif
 
-    void reinstateNetworkProcessAssertionState(NetworkProcessProxy&);
     void updateProcessAssertions();
 
     // IPC::MessageReceiver.
@@ -696,7 +695,6 @@
 
     bool m_processTerminationEnabled { true };
 
-    bool m_didNetworkProcessCrash { false };
     std::unique_ptr<NetworkProcessProxy> m_networkProcess;
 
     HashMap<uint64_t, RefPtr<DictionaryCallback>> m_dictionaryCallbacks;
@@ -759,16 +757,8 @@
     HashMap<PAL::SessionID, HashSet<WebPageProxyIdentifier>> m_sessionToPageIDsMap;
     RunLoop::Timer<WebProcessPool> m_serviceWorkerProcessesTerminationTimer;
 
-#if PLATFORM(IOS_FAMILY)
     ForegroundWebProcessCounter m_foregroundWebProcessCounter;
     BackgroundWebProcessCounter m_backgroundWebProcessCounter;
-    std::unique_ptr<ProcessThrottler::ForegroundActivity> m_foregroundActivityForNetworkProcess;
-    std::unique_ptr<ProcessThrottler::BackgroundActivity> m_backgroundActivityForNetworkProcess;
-#if ENABLE(SERVICE_WORKER)
-    HashMap<WebCore::RegistrableDomain, std::unique_ptr<ProcessThrottler::ForegroundActivity>> m_foregroundActivitiesForServiceWorkerProcesses;
-    HashMap<WebCore::RegistrableDomain, std::unique_ptr<ProcessThrottler::BackgroundActivity>> m_backgroundActivitiesForServiceWorkerProcesses;
-#endif
-#endif
 
     UniqueRef<WebBackForwardCache> m_backForwardCache;
 

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp (252010 => 252011)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2019-11-04 21:21:53 UTC (rev 252010)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2019-11-04 21:36:24 UTC (rev 252011)
@@ -1232,10 +1232,9 @@
 
 void WebProcessProxy::didSetAssertionState(AssertionState state)
 {
-#if PLATFORM(IOS_FAMILY)
     RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertionState(%u)", this, state);
 
-    if (isRunningServiceWorkers() && !pageCount()) {
+    if (isStandaloneServiceWorkerProcess()) {
         RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertionState() release all assertions for network process because this is a service worker process without page", this);
         m_foregroundToken = nullptr;
         m_backgroundToken = nullptr;
@@ -1249,8 +1248,10 @@
         RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertionState(Suspended) release all assertions for network process", this);
         m_foregroundToken = nullptr;
         m_backgroundToken = nullptr;
+#if PLATFORM(IOS_FAMILY)
         for (auto& page : m_pageMap.values())
             page->processWillBecomeSuspended();
+#endif
         break;
 
     case AssertionState::Background:
@@ -1263,8 +1264,10 @@
         RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertionState(Foreground) taking foreground assertion for network process", this);
         m_foregroundToken = processPool().foregroundWebProcessToken();
         m_backgroundToken = nullptr;
+#if PLATFORM(IOS_FAMILY)
         for (auto& page : m_pageMap.values())
             page->processWillBecomeForeground();
+#endif
         break;
     
     case AssertionState::UnboundedNetworking:
@@ -1272,9 +1275,6 @@
     }
 
     ASSERT(!m_backgroundToken || !m_foregroundToken);
-#else
-    UNUSED_PARAM(state);
-#endif
 }
 
 void WebProcessProxy::webPageMediaStateDidChange(WebPageProxy&)
@@ -1299,7 +1299,7 @@
     }
     if (!m_activityForHoldingLockedFiles) {
         RELEASE_LOG(ProcessSuspension, "UIProcess is taking a background assertion because the WebContent process is holding locked files");
-        m_activityForHoldingLockedFiles = m_throttler.backgroundActivity("Holding locked files"_s);
+        m_activityForHoldingLockedFiles = m_throttler.backgroundActivity("Holding locked files"_s).moveToUniquePtr();
     }
 }
 
@@ -1557,8 +1557,29 @@
     ASSERT(m_serviceWorkerInformation);
     send(Messages::WebSWContextManagerConnection::UpdatePreferencesStore { store }, 0);
 }
-#endif
 
+void WebProcessProxy::updateServiceWorkerProcessAssertion()
+{
+    RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::updateServiceWorkerProcessAssertion() PID: %d", this, processIdentifier());
+    ASSERT(m_serviceWorkerInformation);
+    if (!m_serviceWorkerInformation)
+        return;
+
+    // FIXME: We could do better if we knew which WebContent processes needed this service worker process.
+    if (processPool().hasForegroundWebProcesses()) {
+        if (!ProcessThrottler::isValidForegroundActivity(m_serviceWorkerInformation->activity))
+            m_serviceWorkerInformation->activity = m_throttler.foregroundActivity("Service Worker for foreground view(s)"_s);
+        return;
+    }
+    if (processPool().hasBackgroundWebProcesses()) {
+        if (!ProcessThrottler::isValidBackgroundActivity(m_serviceWorkerInformation->activity))
+            m_serviceWorkerInformation->activity = m_throttler.backgroundActivity("Service Worker for background view(s)"_s);
+        return;
+    }
+    m_serviceWorkerInformation->activity = nullptr;
+}
+#endif // ENABLE(SERVICE_WORKER)
+
 void WebProcessProxy::disableServiceWorkers()
 {
     if (!m_serviceWorkerInformation)
@@ -1605,7 +1626,9 @@
             contentRuleListsFromIdentifier(userContentControllerIdentifier),
 #endif
         },
+        nullptr,
     };
+    updateServiceWorkerProcessAssertion();
 }
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.h (252010 => 252011)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.h	2019-11-04 21:21:53 UTC (rev 252010)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.h	2019-11-04 21:36:24 UTC (rev 252011)
@@ -91,7 +91,6 @@
 struct WebPreferencesStore;
 struct WebsiteData;
 
-#if PLATFORM(IOS_FAMILY)
 enum ForegroundWebProcessCounterType { };
 typedef RefCounter<ForegroundWebProcessCounterType> ForegroundWebProcessCounter;
 typedef ForegroundWebProcessCounter::Token ForegroundWebProcessToken;
@@ -98,7 +97,6 @@
 enum BackgroundWebProcessCounterType { };
 typedef RefCounter<BackgroundWebProcessCounterType> BackgroundWebProcessCounter;
 typedef BackgroundWebProcessCounter::Token BackgroundWebProcessToken;
-#endif
 
 class WebProcessProxy : public AuxiliaryProcessProxy, public ResponsivenessTimer::Client, public ThreadSafeRefCounted<WebProcessProxy>, public CanMakeWeakPtr<WebProcessProxy>, private ProcessThrottlerClient {
 public:
@@ -163,6 +161,7 @@
     void activePagesDomainsForTesting(CompletionHandler<void(Vector<String>&&)>&&); // This is what is reported to ActivityMonitor.
 
     bool isRunningServiceWorkers() const { return !!m_serviceWorkerInformation; }
+    bool isStandaloneServiceWorkerProcess() const { return isRunningServiceWorkers() && !pageCount(); }
 
     void didCreateWebPageInProcess(WebCore::PageIdentifier);
 
@@ -339,6 +338,7 @@
     void setServiceWorkerUserAgent(const String&);
     void updateServiceWorkerPreferencesStore(const WebPreferencesStore&);
     bool hasServiceWorkerPageProxy(WebPageProxyIdentifier pageProxyID) { return m_serviceWorkerInformation && m_serviceWorkerInformation->serviceWorkerPageProxyID == pageProxyID; }
+    void updateServiceWorkerProcessAssertion();
 #endif
 
 protected:
@@ -483,9 +483,9 @@
     int m_numberOfTimesSuddenTerminationWasDisabled;
     ProcessThrottler m_throttler;
     std::unique_ptr<ProcessThrottler::BackgroundActivity> m_activityForHoldingLockedFiles;
-#if PLATFORM(IOS_FAMILY)
     ForegroundWebProcessToken m_foregroundToken;
     BackgroundWebProcessToken m_backgroundToken;
+#if PLATFORM(IOS_FAMILY)
     bool m_hasSentMessageToUnblockAccessibilityServer { false };
     std::unique_ptr<WebCore::DeferrableOneShotTimer> m_unexpectedActivityTimer;
 #endif
@@ -526,6 +526,7 @@
         WebPageProxyIdentifier serviceWorkerPageProxyID;
         WebCore::PageIdentifier serviceWorkerPageID;
         ServiceWorkerInitializationData initializationData;
+        ProcessThrottler::ActivityVariant activity;
     };
     Optional<ServiceWorkerInformation> m_serviceWorkerInformation;
 };
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to