[iOS] [WK2] Improve process assertion-related logging to help identify causes of...
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Oct 2019 17:31:39 +0000 (17:31 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Oct 2019 17:31:39 +0000 (17:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=203438

Reviewed by Antti Koivisto.

Improve process assertion-related logging to help identify causes of leaked assertions. Previously,
whenever our code needed to prevent suspension of a child process due to some kind of activity, it
would simply grab a "token" from the child process' ProcessThrottler. This, in-turn, would cause
the ProcessThrottler to take the right kind of ProcessAssertion or release it when nobody holds
any tokens any more.

We frequently have issues where the UIProcess keeps its assertions around for too long after getting
backgrounding. This causes the assertions to get invalidated and the UIProcess will usually suspend
(albeit with a delay, which is bad for power). Sometimes though, we get killed because our invalidation
handler does not get a chance to release the assertion in time.

Finding out why we're keeping around assertions is currently very difficult because we cannot easily
see in the logs who is still holding ProcessThrottler tokens. To make such debugging easier, clients
now notify the ProcessThrottler when they start some activity and provide a user-readable description
of the activity. The client then gets a ForegroundActivity or BackgroundActivity object instead of
simply a token. As a result, we are now able to log when a given activity that prevents suspension
begins and ends, with a user-friendly string. Also, when the assertion gets invalidated, it will
invalidate all these pending activities and we'll see in the logs the name of the activities that
were still going on upon invalidation.

* Shared/API/Cocoa/RemoteObjectRegistry.h:
(WebKit::RemoteObjectRegistry::backgroundActivity):
* Shared/API/Cocoa/RemoteObjectRegistry.mm:
(WebKit::RemoteObjectRegistry::sendInvocation):
* UIProcess/Cocoa/DownloadClient.h:
* UIProcess/Cocoa/DownloadClient.mm:
(WebKit::DownloadClient::takeActivityToken):
(WebKit::DownloadClient::releaseActivityTokenIfNecessary):
* UIProcess/Cocoa/NavigationState.h:
* UIProcess/Cocoa/NavigationState.mm:
(WebKit::NavigationState::NavigationState):
(WebKit::NavigationState::releaseNetworkActivity):
(WebKit::NavigationState::didChangeIsLoading):
(WebKit::NavigationState::didSwapWebProcesses):
* UIProcess/Cocoa/UIRemoteObjectRegistry.cpp:
(WebKit::UIRemoteObjectRegistry::backgroundActivity):
* UIProcess/Cocoa/UIRemoteObjectRegistry.h:
* UIProcess/Cocoa/WebProcessProxyCocoa.mm:
(WebKit::WebProcessProxy::processWasResumed):
* UIProcess/GenericCallback.h:
(WebKit::CallbackBase::CallbackBase):
(WebKit::GenericCallback::create):
(WebKit::GenericCallback::GenericCallback):
(WebKit::CallbackMap::put):
* UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::fetchWebsiteData):
(WebKit::NetworkProcessProxy::deleteWebsiteData):
(WebKit::NetworkProcessProxy::deleteWebsiteDataForOrigins):
(WebKit::NetworkProcessProxy::didClose):
(WebKit::NetworkProcessProxy::setIsHoldingLockedFiles):
(WebKit::NetworkProcessProxy::syncAllCookies):
(WebKit::NetworkProcessProxy::didSyncAllCookies):
* UIProcess/Network/NetworkProcessProxy.h:
* UIProcess/ProcessThrottler.cpp:
(WebKit::ProcessThrottler::ProcessThrottler):
(WebKit::ProcessThrottler::~ProcessThrottler):
(WebKit::ProcessThrottler::addActivity):
(WebKit::ProcessThrottler::removeActivity):
(WebKit::ProcessThrottler::invalidateAllActivities):
(WebKit::ProcessThrottler::expectedAssertionState):
(WebKit::ProcessThrottler::setAssertionState):
(WebKit::ProcessThrottler::uiAssertionWillExpireImminently):
* UIProcess/ProcessThrottler.h:
(WebKit::ProcessThrottler::Activity::Activity):
(WebKit::ProcessThrottler::Activity::~Activity):
(WebKit::ProcessThrottler::Activity::isValid const):
(WebKit::ProcessThrottler::Activity::invalidate):
(WebKit::ProcessThrottler::shouldBeRunnable const):
(WebKit::ProcessThrottler::foregroundActivity):
(WebKit::ProcessThrottler::backgroundActivity):
* UIProcess/ProvisionalPageProxy.cpp:
(WebKit::ProvisionalPageProxy::ProvisionalPageProxy):
* UIProcess/ProvisionalPageProxy.h:
* UIProcess/RemoteLayerTree/RemoteLayerTreeDrawingAreaProxy.mm:
(WebKit::RemoteLayerTreeDrawingAreaProxy::dispatchAfterEnsuringDrawing):
* UIProcess/SuspendedPageProxy.cpp:
(WebKit::SuspendedPageProxy::SuspendedPageProxy):
(WebKit::SuspendedPageProxy::didProcessRequestToSuspend):
* UIProcess/SuspendedPageProxy.h:
* UIProcess/WebBackForwardCacheEntry.cpp:
(WebKit::WebBackForwardCacheEntry::~WebBackForwardCacheEntry):
* UIProcess/WebCookieManagerProxy.cpp:
(WebKit::WebCookieManagerProxy::getHostnamesWithCookies):
(WebKit::WebCookieManagerProxy::deleteCookie):
(WebKit::WebCookieManagerProxy::deleteAllCookiesModifiedSince):
(WebKit::WebCookieManagerProxy::setCookies):
(WebKit::WebCookieManagerProxy::getAllCookies):
(WebKit::WebCookieManagerProxy::getCookies):
(WebKit::WebCookieManagerProxy::setHTTPCookieAcceptPolicy):
(WebKit::WebCookieManagerProxy::getHTTPCookieAcceptPolicy):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::close):
(WebKit::WebPageProxy::updateThrottleState):
(WebKit::WebPageProxy::waitForDidUpdateActivityState):
(WebKit::WebPageProxy::setInitialFocus):
(WebKit::WebPageProxy::validateCommand):
(WebKit::WebPageProxy::executeEditCommand):
(WebKit::WebPageProxy::requestFontAttributesAtSelectionStart):
(WebKit::WebPageProxy::replaceMatches):
(WebKit::WebPageProxy::runJavaScriptInMainFrameScriptWorld):
(WebKit::WebPageProxy::runJavaScriptInFrame):
(WebKit::WebPageProxy::getRenderTreeExternalRepresentation):
(WebKit::WebPageProxy::getSourceForFrame):
(WebKit::WebPageProxy::getContentsAsString):
(WebKit::WebPageProxy::getBytecodeProfile):
(WebKit::WebPageProxy::getSamplingProfilerOutput):
(WebKit::WebPageProxy::getContentsAsMHTMLData):
(WebKit::WebPageProxy::getSelectionOrContentsAsString):
(WebKit::WebPageProxy::getSelectionAsWebArchiveData):
(WebKit::WebPageProxy::getMainResourceDataOfFrame):
(WebKit::WebPageProxy::getResourceDataFromFrame):
(WebKit::WebPageProxy::getWebArchiveOfFrame):
(WebKit::WebPageProxy::forceRepaint):
(WebKit::WebPageProxy::resetStateAfterProcessExited):
(WebKit::WebPageProxy::drawToPDF):
(WebKit::WebPageProxy::getMarkedRangeAsync):
(WebKit::WebPageProxy::getSelectedRangeAsync):
(WebKit::WebPageProxy::characterIndexForPointAsync):
(WebKit::WebPageProxy::firstRectForCharacterRangeAsync):
(WebKit::WebPageProxy::takeSnapshot):
(WebKit::WebPageProxy::installActivityStateChangeCompletionHandler):
(WebKit::WebPageProxy::getLoadDecisionForIcon):
(WebKit::WebPageProxy::insertAttachment):
(WebKit::WebPageProxy::updateAttachmentAttributes):
(WebKit::WebPageProxy::getApplicationManifest):
* UIProcess/WebPageProxy.h:
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::initializeNewWebProcess):
(WebKit::WebProcessPool::updateProcessAssertions):
(WebKit::WebProcessPool::reinstateNetworkProcessAssertionState):
* UIProcess/WebProcessPool.h:
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::shutDown):
(WebKit::WebProcessProxy::fetchWebsiteData):
(WebKit::WebProcessProxy::deleteWebsiteData):
(WebKit::WebProcessProxy::deleteWebsiteDataForOrigins):
(WebKit::WebProcessProxy::setIsHoldingLockedFiles):
(WebKit::WebProcessProxy::startBackgroundActivityForFullscreenInput):
(WebKit::WebProcessProxy::endBackgroundActivityForFullscreenInput):
* UIProcess/WebProcessProxy.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView presentViewControllerForCurrentFocusedElement]):
(-[WKContentView dismissAllInputViewControllers:]):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::requestFocusedElementInformation):
(WebKit::WebPageProxy::selectWithGesture):
(WebKit::WebPageProxy::updateSelectionWithTouches):
(WebKit::WebPageProxy::applyAutocorrection):
(WebKit::WebPageProxy::selectTextWithGranularityAtPoint):
(WebKit::WebPageProxy::selectPositionAtBoundaryWithDirection):
(WebKit::WebPageProxy::moveSelectionAtBoundaryWithDirection):
(WebKit::WebPageProxy::selectPositionAtPoint):
(WebKit::WebPageProxy::beginSelectionInDirection):
(WebKit::WebPageProxy::updateSelectionWithExtentPoint):
(WebKit::WebPageProxy::updateSelectionWithExtentPointAndBoundary):
(WebKit::WebPageProxy::requestDictationContext):
(WebKit::WebPageProxy::getSelectionContext):
(WebKit::WebPageProxy::selectWithTwoTouches):
(WebKit::WebPageProxy::applicationDidEnterBackground):
(WebKit::WebPageProxy::requestRectsForGranularityWithSelectionOffset):
(WebKit::WebPageProxy::requestRectsAtSelectionOffsetWithText):
(WebKit::WebPageProxy::moveSelectionByOffset):
(WebKit::WebPageProxy::focusNextFocusedElement):
(WebKit::WebPageProxy::computePagesForPrintingAndDrawToPDF):

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

31 files changed:
Source/WebKit/ChangeLog
Source/WebKit/Shared/API/Cocoa/RemoteObjectRegistry.h
Source/WebKit/Shared/API/Cocoa/RemoteObjectRegistry.mm
Source/WebKit/UIProcess/Cocoa/DownloadClient.h
Source/WebKit/UIProcess/Cocoa/DownloadClient.mm
Source/WebKit/UIProcess/Cocoa/NavigationState.h
Source/WebKit/UIProcess/Cocoa/NavigationState.mm
Source/WebKit/UIProcess/Cocoa/UIRemoteObjectRegistry.cpp
Source/WebKit/UIProcess/Cocoa/UIRemoteObjectRegistry.h
Source/WebKit/UIProcess/Cocoa/WebProcessProxyCocoa.mm
Source/WebKit/UIProcess/GenericCallback.h
Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp
Source/WebKit/UIProcess/Network/NetworkProcessProxy.h
Source/WebKit/UIProcess/ProcessThrottler.cpp
Source/WebKit/UIProcess/ProcessThrottler.h
Source/WebKit/UIProcess/ProvisionalPageProxy.cpp
Source/WebKit/UIProcess/ProvisionalPageProxy.h
Source/WebKit/UIProcess/RemoteLayerTree/RemoteLayerTreeDrawingAreaProxy.mm
Source/WebKit/UIProcess/SuspendedPageProxy.cpp
Source/WebKit/UIProcess/SuspendedPageProxy.h
Source/WebKit/UIProcess/WebBackForwardCacheEntry.cpp
Source/WebKit/UIProcess/WebCookieManagerProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/WebProcessPool.cpp
Source/WebKit/UIProcess/WebProcessPool.h
Source/WebKit/UIProcess/WebProcessProxy.cpp
Source/WebKit/UIProcess/WebProcessProxy.h
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm
Source/WebKit/UIProcess/mac/WebPageProxyMac.mm

index d05a4f6..80a0b0b 100644 (file)
@@ -1,3 +1,175 @@
+2019-10-30  Chris Dumez  <cdumez@apple.com>
+
+        [iOS] [WK2] Improve process assertion-related logging to help identify causes of leaked assertions
+        https://bugs.webkit.org/show_bug.cgi?id=203438
+
+        Reviewed by Antti Koivisto.
+
+        Improve process assertion-related logging to help identify causes of leaked assertions. Previously,
+        whenever our code needed to prevent suspension of a child process due to some kind of activity, it
+        would simply grab a "token" from the child process' ProcessThrottler. This, in-turn, would cause
+        the ProcessThrottler to take the right kind of ProcessAssertion or release it when nobody holds
+        any tokens any more.
+
+        We frequently have issues where the UIProcess keeps its assertions around for too long after getting
+        backgrounding. This causes the assertions to get invalidated and the UIProcess will usually suspend
+        (albeit with a delay, which is bad for power). Sometimes though, we get killed because our invalidation
+        handler does not get a chance to release the assertion in time.
+
+        Finding out why we're keeping around assertions is currently very difficult because we cannot easily
+        see in the logs who is still holding ProcessThrottler tokens. To make such debugging easier, clients
+        now notify the ProcessThrottler when they start some activity and provide a user-readable description
+        of the activity. The client then gets a ForegroundActivity or BackgroundActivity object instead of
+        simply a token. As a result, we are now able to log when a given activity that prevents suspension
+        begins and ends, with a user-friendly string. Also, when the assertion gets invalidated, it will
+        invalidate all these pending activities and we'll see in the logs the name of the activities that
+        were still going on upon invalidation.
+
+        * Shared/API/Cocoa/RemoteObjectRegistry.h:
+        (WebKit::RemoteObjectRegistry::backgroundActivity):
+        * Shared/API/Cocoa/RemoteObjectRegistry.mm:
+        (WebKit::RemoteObjectRegistry::sendInvocation):
+        * UIProcess/Cocoa/DownloadClient.h:
+        * UIProcess/Cocoa/DownloadClient.mm:
+        (WebKit::DownloadClient::takeActivityToken):
+        (WebKit::DownloadClient::releaseActivityTokenIfNecessary):
+        * UIProcess/Cocoa/NavigationState.h:
+        * UIProcess/Cocoa/NavigationState.mm:
+        (WebKit::NavigationState::NavigationState):
+        (WebKit::NavigationState::releaseNetworkActivity):
+        (WebKit::NavigationState::didChangeIsLoading):
+        (WebKit::NavigationState::didSwapWebProcesses):
+        * UIProcess/Cocoa/UIRemoteObjectRegistry.cpp:
+        (WebKit::UIRemoteObjectRegistry::backgroundActivity):
+        * UIProcess/Cocoa/UIRemoteObjectRegistry.h:
+        * UIProcess/Cocoa/WebProcessProxyCocoa.mm:
+        (WebKit::WebProcessProxy::processWasResumed):
+        * UIProcess/GenericCallback.h:
+        (WebKit::CallbackBase::CallbackBase):
+        (WebKit::GenericCallback::create):
+        (WebKit::GenericCallback::GenericCallback):
+        (WebKit::CallbackMap::put):
+        * UIProcess/Network/NetworkProcessProxy.cpp:
+        (WebKit::NetworkProcessProxy::fetchWebsiteData):
+        (WebKit::NetworkProcessProxy::deleteWebsiteData):
+        (WebKit::NetworkProcessProxy::deleteWebsiteDataForOrigins):
+        (WebKit::NetworkProcessProxy::didClose):
+        (WebKit::NetworkProcessProxy::setIsHoldingLockedFiles):
+        (WebKit::NetworkProcessProxy::syncAllCookies):
+        (WebKit::NetworkProcessProxy::didSyncAllCookies):
+        * UIProcess/Network/NetworkProcessProxy.h:
+        * UIProcess/ProcessThrottler.cpp:
+        (WebKit::ProcessThrottler::ProcessThrottler):
+        (WebKit::ProcessThrottler::~ProcessThrottler):
+        (WebKit::ProcessThrottler::addActivity):
+        (WebKit::ProcessThrottler::removeActivity):
+        (WebKit::ProcessThrottler::invalidateAllActivities):
+        (WebKit::ProcessThrottler::expectedAssertionState):
+        (WebKit::ProcessThrottler::setAssertionState):
+        (WebKit::ProcessThrottler::uiAssertionWillExpireImminently):
+        * UIProcess/ProcessThrottler.h:
+        (WebKit::ProcessThrottler::Activity::Activity):
+        (WebKit::ProcessThrottler::Activity::~Activity):
+        (WebKit::ProcessThrottler::Activity::isValid const):
+        (WebKit::ProcessThrottler::Activity::invalidate):
+        (WebKit::ProcessThrottler::shouldBeRunnable const):
+        (WebKit::ProcessThrottler::foregroundActivity):
+        (WebKit::ProcessThrottler::backgroundActivity):
+        * UIProcess/ProvisionalPageProxy.cpp:
+        (WebKit::ProvisionalPageProxy::ProvisionalPageProxy):
+        * UIProcess/ProvisionalPageProxy.h:
+        * UIProcess/RemoteLayerTree/RemoteLayerTreeDrawingAreaProxy.mm:
+        (WebKit::RemoteLayerTreeDrawingAreaProxy::dispatchAfterEnsuringDrawing):
+        * UIProcess/SuspendedPageProxy.cpp:
+        (WebKit::SuspendedPageProxy::SuspendedPageProxy):
+        (WebKit::SuspendedPageProxy::didProcessRequestToSuspend):
+        * UIProcess/SuspendedPageProxy.h:
+        * UIProcess/WebBackForwardCacheEntry.cpp:
+        (WebKit::WebBackForwardCacheEntry::~WebBackForwardCacheEntry):
+        * UIProcess/WebCookieManagerProxy.cpp:
+        (WebKit::WebCookieManagerProxy::getHostnamesWithCookies):
+        (WebKit::WebCookieManagerProxy::deleteCookie):
+        (WebKit::WebCookieManagerProxy::deleteAllCookiesModifiedSince):
+        (WebKit::WebCookieManagerProxy::setCookies):
+        (WebKit::WebCookieManagerProxy::getAllCookies):
+        (WebKit::WebCookieManagerProxy::getCookies):
+        (WebKit::WebCookieManagerProxy::setHTTPCookieAcceptPolicy):
+        (WebKit::WebCookieManagerProxy::getHTTPCookieAcceptPolicy):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::close):
+        (WebKit::WebPageProxy::updateThrottleState):
+        (WebKit::WebPageProxy::waitForDidUpdateActivityState):
+        (WebKit::WebPageProxy::setInitialFocus):
+        (WebKit::WebPageProxy::validateCommand):
+        (WebKit::WebPageProxy::executeEditCommand):
+        (WebKit::WebPageProxy::requestFontAttributesAtSelectionStart):
+        (WebKit::WebPageProxy::replaceMatches):
+        (WebKit::WebPageProxy::runJavaScriptInMainFrameScriptWorld):
+        (WebKit::WebPageProxy::runJavaScriptInFrame):
+        (WebKit::WebPageProxy::getRenderTreeExternalRepresentation):
+        (WebKit::WebPageProxy::getSourceForFrame):
+        (WebKit::WebPageProxy::getContentsAsString):
+        (WebKit::WebPageProxy::getBytecodeProfile):
+        (WebKit::WebPageProxy::getSamplingProfilerOutput):
+        (WebKit::WebPageProxy::getContentsAsMHTMLData):
+        (WebKit::WebPageProxy::getSelectionOrContentsAsString):
+        (WebKit::WebPageProxy::getSelectionAsWebArchiveData):
+        (WebKit::WebPageProxy::getMainResourceDataOfFrame):
+        (WebKit::WebPageProxy::getResourceDataFromFrame):
+        (WebKit::WebPageProxy::getWebArchiveOfFrame):
+        (WebKit::WebPageProxy::forceRepaint):
+        (WebKit::WebPageProxy::resetStateAfterProcessExited):
+        (WebKit::WebPageProxy::drawToPDF):
+        (WebKit::WebPageProxy::getMarkedRangeAsync):
+        (WebKit::WebPageProxy::getSelectedRangeAsync):
+        (WebKit::WebPageProxy::characterIndexForPointAsync):
+        (WebKit::WebPageProxy::firstRectForCharacterRangeAsync):
+        (WebKit::WebPageProxy::takeSnapshot):
+        (WebKit::WebPageProxy::installActivityStateChangeCompletionHandler):
+        (WebKit::WebPageProxy::getLoadDecisionForIcon):
+        (WebKit::WebPageProxy::insertAttachment):
+        (WebKit::WebPageProxy::updateAttachmentAttributes):
+        (WebKit::WebPageProxy::getApplicationManifest):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::initializeNewWebProcess):
+        (WebKit::WebProcessPool::updateProcessAssertions):
+        (WebKit::WebProcessPool::reinstateNetworkProcessAssertionState):
+        * UIProcess/WebProcessPool.h:
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::shutDown):
+        (WebKit::WebProcessProxy::fetchWebsiteData):
+        (WebKit::WebProcessProxy::deleteWebsiteData):
+        (WebKit::WebProcessProxy::deleteWebsiteDataForOrigins):
+        (WebKit::WebProcessProxy::setIsHoldingLockedFiles):
+        (WebKit::WebProcessProxy::startBackgroundActivityForFullscreenInput):
+        (WebKit::WebProcessProxy::endBackgroundActivityForFullscreenInput):
+        * UIProcess/WebProcessProxy.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView presentViewControllerForCurrentFocusedElement]):
+        (-[WKContentView dismissAllInputViewControllers:]):
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::requestFocusedElementInformation):
+        (WebKit::WebPageProxy::selectWithGesture):
+        (WebKit::WebPageProxy::updateSelectionWithTouches):
+        (WebKit::WebPageProxy::applyAutocorrection):
+        (WebKit::WebPageProxy::selectTextWithGranularityAtPoint):
+        (WebKit::WebPageProxy::selectPositionAtBoundaryWithDirection):
+        (WebKit::WebPageProxy::moveSelectionAtBoundaryWithDirection):
+        (WebKit::WebPageProxy::selectPositionAtPoint):
+        (WebKit::WebPageProxy::beginSelectionInDirection):
+        (WebKit::WebPageProxy::updateSelectionWithExtentPoint):
+        (WebKit::WebPageProxy::updateSelectionWithExtentPointAndBoundary):
+        (WebKit::WebPageProxy::requestDictationContext):
+        (WebKit::WebPageProxy::getSelectionContext):
+        (WebKit::WebPageProxy::selectWithTwoTouches):
+        (WebKit::WebPageProxy::applicationDidEnterBackground):
+        (WebKit::WebPageProxy::requestRectsForGranularityWithSelectionOffset):
+        (WebKit::WebPageProxy::requestRectsAtSelectionOffsetWithText):
+        (WebKit::WebPageProxy::moveSelectionByOffset):
+        (WebKit::WebPageProxy::focusNextFocusedElement):
+        (WebKit::WebPageProxy::computePagesForPrintingAndDrawToPDF):
+
 2019-10-30  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         REGRESSION(2.27.2): [GTK] Overview item remove button broken
index 84b470c..54cdc03 100644 (file)
@@ -56,7 +56,7 @@ protected:
     explicit RemoteObjectRegistry(_WKRemoteObjectRegistry *);
     
 private:
-    virtual ProcessThrottler::BackgroundActivityToken takeBackgroundActivityToken() { return nullptr; }
+    virtual std::unique_ptr<ProcessThrottler::BackgroundActivity> backgroundActivity(ASCIILiteral) { return nullptr; }
     virtual IPC::MessageSender& messageSender() = 0;
     virtual uint64_t messageDestinationID() = 0;
 
@@ -69,7 +69,7 @@ private:
     void releaseUnusedReplyBlock(uint64_t replyID);
 
     WeakObjCPtr<_WKRemoteObjectRegistry> m_remoteObjectRegistry;
-    HashMap<uint64_t, ProcessThrottler::BackgroundActivityToken> m_pendingReplies;
+    HashMap<uint64_t, std::unique_ptr<ProcessThrottler::BackgroundActivity>> m_pendingReplies;
 };
 
 } // namespace WebKit
index 30ec4e7..e48c928 100644 (file)
@@ -48,7 +48,7 @@ void RemoteObjectRegistry::sendInvocation(const RemoteObjectInvocation& invocati
 
     if (auto* replyInfo = invocation.replyInfo()) {
         ASSERT(!m_pendingReplies.contains(replyInfo->replyID));
-        m_pendingReplies.add(replyInfo->replyID, takeBackgroundActivityToken());
+        m_pendingReplies.add(replyInfo->replyID, backgroundActivity("RemoteObjectRegistry invocation"_s));
     }
 
     messageSender().send(Messages::RemoteObjectRegistry::InvokeMethod(invocation), messageDestinationID());
index 4555c6b..5d9b91c 100644 (file)
@@ -67,7 +67,7 @@ private:
     WeakObjCPtr<id <_WKDownloadDelegate>> m_delegate;
 
 #if PLATFORM(IOS_FAMILY) && USE(SYSTEM_PREVIEW)
-    ProcessThrottler::BackgroundActivityToken m_activityToken { nullptr };
+    std::unique_ptr<ProcessThrottler::BackgroundActivity> m_activity;
 #endif
 
     struct {
index 25663ad..651b701 100644 (file)
@@ -268,8 +268,8 @@ void DownloadClient::takeActivityToken(DownloadProxy& downloadProxy)
 #if PLATFORM(IOS_FAMILY)
     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_activityToken);
-        m_activityToken = webPage->process().throttler().backgroundActivityToken();
+        ASSERT(!m_activity);
+        m_activity = webPage->process().throttler().backgroundActivity("System preview download"_s);
     }
 #else
     UNUSED_PARAM(downloadProxy);
@@ -279,9 +279,9 @@ void DownloadClient::takeActivityToken(DownloadProxy& downloadProxy)
 void DownloadClient::releaseActivityTokenIfNecessary(DownloadProxy& downloadProxy)
 {
 #if PLATFORM(IOS_FAMILY)
-    if (m_activityToken) {
+    if (m_activity) {
         RELEASE_LOG_IF(downloadProxy.originatingPage()->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p UIProcess is releasing a background assertion because a system preview download completed", this);
-        m_activityToken = nullptr;
+        m_activity = nullptr;
     }
 #else
     UNUSED_PARAM(downloadProxy);
index 9785106..9463e51 100644 (file)
@@ -83,8 +83,8 @@ public:
     void didFirstPaint();
 
 #if PLATFORM(IOS_FAMILY)
-    enum class NetworkActivityTokenReleaseReason { LoadCompleted, ScreenLocked };
-    void releaseNetworkActivityToken(NetworkActivityTokenReleaseReason);
+    enum class NetworkActivityReleaseReason { LoadCompleted, ScreenLocked };
+    void releaseNetworkActivity(NetworkActivityReleaseReason);
 #endif
 
 private:
@@ -184,7 +184,7 @@ private:
     void didSwapWebProcesses() override;
 
 #if PLATFORM(IOS_FAMILY)
-    void releaseNetworkActivityTokenAfterLoadCompletion() { releaseNetworkActivityToken(NetworkActivityTokenReleaseReason::LoadCompleted); }
+    void releaseNetworkActivityAfterLoadCompletion() { releaseNetworkActivity(NetworkActivityReleaseReason::LoadCompleted); }
 #endif
 
     WKWebView *m_webView;
@@ -258,8 +258,8 @@ private:
     } m_historyDelegateMethods;
 
 #if PLATFORM(IOS_FAMILY)
-    ProcessThrottler::BackgroundActivityToken m_activityToken;
-    RunLoop::Timer<NavigationState> m_releaseActivityTimer;
+    std::unique_ptr<ProcessThrottler::BackgroundActivity> m_networkActivity;
+    RunLoop::Timer<NavigationState> m_releaseNetwrokActivityTimer;
 #endif
 };
 
index 9ada0d9..96f90d7 100644 (file)
@@ -98,7 +98,7 @@ NavigationState::NavigationState(WKWebView *webView)
     , m_navigationDelegateMethods()
     , m_historyDelegateMethods()
 #if PLATFORM(IOS_FAMILY)
-    , m_releaseActivityTimer(RunLoop::current(), this, &NavigationState::releaseNetworkActivityTokenAfterLoadCompletion)
+    , m_releaseNetwrokActivityTimer(RunLoop::current(), this, &NavigationState::releaseNetworkActivityAfterLoadCompletion)
 #endif
 {
     ASSERT(m_webView->_page);
@@ -1205,21 +1205,21 @@ void NavigationState::willChangeIsLoading()
 }
 
 #if PLATFORM(IOS_FAMILY)
-void NavigationState::releaseNetworkActivityToken(NetworkActivityTokenReleaseReason reason)
+void NavigationState::releaseNetworkActivity(NetworkActivityReleaseReason reason)
 {
-    if (!m_activityToken)
+    if (!m_networkActivity)
         return;
 
     switch (reason) {
-    case NetworkActivityTokenReleaseReason::LoadCompleted:
+    case NetworkActivityReleaseReason::LoadCompleted:
         RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p NavigationState is releasing background process assertion because a page load completed", this);
         break;
-    case NetworkActivityTokenReleaseReason::ScreenLocked:
+    case NetworkActivityReleaseReason::ScreenLocked:
         RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p NavigationState is releasing background process assertion because the screen was locked", this);
         break;
     }
-    m_activityToken = nullptr;
-    m_releaseActivityTimer.stop();
+    m_networkActivity = nullptr;
+    m_releaseNetwrokActivityTimer.stop();
 }
 #endif
 
@@ -1227,23 +1227,23 @@ void NavigationState::didChangeIsLoading()
 {
 #if PLATFORM(IOS_FAMILY)
     if (m_webView->_page->pageLoadState().isLoading()) {
-        // We do not take a network activity token if a load starts after the screen has been locked.
+        // We do not start a network activity if a load starts after the screen has been locked.
         if ([UIApp isSuspendedUnderLock])
             return;
 
-        if (m_releaseActivityTimer.isActive()) {
+        if (m_releaseNetwrokActivityTimer.isActive()) {
             RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - NavigationState keeps its process network assertion because a new page load started", this);
-            m_releaseActivityTimer.stop();
+            m_releaseNetwrokActivityTimer.stop();
         }
-        if (!m_activityToken) {
+        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_activityToken = m_webView->_page->process().throttler().backgroundActivityToken();
+            m_networkActivity = m_webView->_page->process().throttler().backgroundActivity("Page Load"_s);
         }
-    } else if (m_activityToken) {
+    } 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
         // before suspending the WebContent process <rdar://problem/27910964>.
         RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - NavigationState will release its process network assertion soon because the page load completed", this);
-        m_releaseActivityTimer.startOneShot(3_s);
+        m_releaseNetwrokActivityTimer.startOneShot(3_s);
     }
 #endif
 
@@ -1346,8 +1346,8 @@ void NavigationState::didSwapWebProcesses()
 {
 #if PLATFORM(IOS_FAMILY)
     // Transfer our background assertion from the old process to the new one.
-    if (m_activityToken)
-        m_activityToken = m_webView->_page->process().throttler().backgroundActivityToken();
+    if (m_networkActivity)
+        m_networkActivity = m_webView->_page->process().throttler().backgroundActivity("Page Load"_s);
 #endif
 }
 
index 20cd53c..497ab72 100644 (file)
@@ -31,9 +31,9 @@
 
 namespace WebKit {
 
-ProcessThrottler::BackgroundActivityToken UIRemoteObjectRegistry::takeBackgroundActivityToken()
+std::unique_ptr<ProcessThrottler::BackgroundActivity> UIRemoteObjectRegistry::backgroundActivity(ASCIILiteral name)
 {
-    return m_page.process().throttler().backgroundActivityToken();
+    return m_page.process().throttler().backgroundActivity(name);
 }
 
 UIRemoteObjectRegistry::UIRemoteObjectRegistry(_WKRemoteObjectRegistry *remoteObjectRegistry, WebPageProxy& page)
index c40b453..d638827 100644 (file)
@@ -40,7 +40,7 @@ public:
 private:
     IPC::MessageSender& messageSender() final;
     uint64_t messageDestinationID() final;
-    ProcessThrottler::BackgroundActivityToken takeBackgroundActivityToken() final;
+    std::unique_ptr<ProcessThrottler::BackgroundActivity> backgroundActivity(ASCIILiteral) final;
 
     WebPageProxy& m_page;
 };
index 83435f9..fe8194f 100644 (file)
@@ -205,7 +205,7 @@ void WebProcessProxy::processWasResumed()
     // The WebProcess was awakened by something other than the UIProcess. Take out an assertion for a
     // limited duration to allow whatever task needs to be accomplished time to complete.
     RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::processWasResumed() Process was unexpectedly resumed, starting background activity", this);
-    auto backgroundActivityTimeoutHandler = [activityToken = m_throttler.backgroundActivityToken(), weakThis = makeWeakPtr(this)] {
+    auto backgroundActivityTimeoutHandler = [activity = m_throttler.backgroundActivity("WebProcess was unexpectedly resumed"_s), weakThis = makeWeakPtr(this)] {
         RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::processWasResumed() - lambda, background activity timed out", weakThis.get());
     };
     m_unexpectedActivityTimer = makeUnique<WebCore::DeferrableOneShotTimer>(WTFMove(backgroundActivityTimeoutHandler), unexpectedActivityDuration);
index b277920..a935cfe 100644 (file)
@@ -69,17 +69,17 @@ protected:
     struct TypeTag { };
     typedef const TypeTag* Type;
 
-    explicit CallbackBase(Type type, const ProcessThrottler::BackgroundActivityToken& activityToken)
+    explicit CallbackBase(Type type, std::unique_ptr<ProcessThrottler::BackgroundActivity>&& activity)
         : m_type(type)
         , m_callbackID(CallbackID::generateID())
-        , m_activityToken(activityToken)
+        , m_activity(WTFMove(activity))
     {
     }
 
 private:
     Type m_type;
     CallbackID m_callbackID;
-    ProcessThrottler::BackgroundActivityToken m_activityToken;
+    std::unique_ptr<ProcessThrottler::BackgroundActivity> m_activity;
 };
 
 template<typename... T>
@@ -87,9 +87,9 @@ class GenericCallback : public CallbackBase {
 public:
     typedef Function<void (T..., Error)> CallbackFunction;
 
-    static Ref<GenericCallback> create(CallbackFunction&& callback, const ProcessThrottler::BackgroundActivityToken& activityToken = nullptr)
+    static Ref<GenericCallback> create(CallbackFunction&& callback, std::unique_ptr<ProcessThrottler::BackgroundActivity>&& activity = nullptr)
     {
-        return adoptRef(*new GenericCallback(WTFMove(callback), activityToken));
+        return adoptRef(*new GenericCallback(WTFMove(callback), WTFMove(activity)));
     }
 
     virtual ~GenericCallback()
@@ -126,8 +126,8 @@ public:
     }
 
 private:
-    GenericCallback(CallbackFunction&& callback, const ProcessThrottler::BackgroundActivityToken& activityToken)
-        : CallbackBase(type(), activityToken)
+    GenericCallback(CallbackFunction&& callback, std::unique_ptr<ProcessThrottler::BackgroundActivity>&& activity)
+        : CallbackBase(type(), WTFMove(activity))
         , m_callback(WTFMove(callback))
     {
     }
@@ -189,9 +189,9 @@ public:
     };
 
     template<typename... T>
-    CallbackID put(Function<void(T...)>&& function, const ProcessThrottler::BackgroundActivityToken& activityToken)
+    CallbackID put(Function<void(T...)>&& function, std::unique_ptr<ProcessThrottler::BackgroundActivity>&& activity)
     {
-        auto callback = GenericCallbackType<sizeof...(T), T...>::type::create(WTFMove(function), activityToken);
+        auto callback = GenericCallbackType<sizeof...(T), T...>::type::create(WTFMove(function), WTFMove(activity));
         return put(WTFMove(callback));
     }
 
index af5c552..60e2cb2 100644 (file)
@@ -196,7 +196,7 @@ void NetworkProcessProxy::fetchWebsiteData(PAL::SessionID sessionID, OptionSet<W
     uint64_t callbackID = generateCallbackID();
     RELEASE_LOG_IF(sessionID.isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - NetworkProcessProxy is taking a background assertion because the Network process is fetching Website data", this);
 
-    m_pendingFetchWebsiteDataCallbacks.add(callbackID, [this, token = throttler().backgroundActivityToken(), completionHandler = WTFMove(completionHandler), sessionID] (WebsiteData websiteData) mutable {
+    m_pendingFetchWebsiteDataCallbacks.add(callbackID, [this, activity = throttler().backgroundActivity("NetworkProcessProxy::fetchWebsiteData"_s), completionHandler = WTFMove(completionHandler), sessionID] (WebsiteData websiteData) mutable {
 #if RELEASE_LOG_DISABLED
         UNUSED_PARAM(this);
         UNUSED_PARAM(sessionID);
@@ -213,7 +213,7 @@ void NetworkProcessProxy::deleteWebsiteData(PAL::SessionID sessionID, OptionSet<
     auto callbackID = generateCallbackID();
     RELEASE_LOG_IF(sessionID.isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - NetworkProcessProxy is taking a background assertion because the Network process is deleting Website data", this);
 
-    m_pendingDeleteWebsiteDataCallbacks.add(callbackID, [this, token = throttler().backgroundActivityToken(), completionHandler = WTFMove(completionHandler), sessionID] () mutable {
+    m_pendingDeleteWebsiteDataCallbacks.add(callbackID, [this, activity = throttler().backgroundActivity("NetworkProcessProxy::deleteWebsiteData"_s), completionHandler = WTFMove(completionHandler), sessionID] () mutable {
 #if RELEASE_LOG_DISABLED
         UNUSED_PARAM(this);
         UNUSED_PARAM(sessionID);
@@ -231,7 +231,7 @@ void NetworkProcessProxy::deleteWebsiteDataForOrigins(PAL::SessionID sessionID,
     uint64_t callbackID = generateCallbackID();
     RELEASE_LOG_IF(sessionID.isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - NetworkProcessProxy is taking a background assertion because the Network process is deleting Website data for several origins", this);
 
-    m_pendingDeleteWebsiteDataForOriginsCallbacks.add(callbackID, [this, token = throttler().backgroundActivityToken(), completionHandler = WTFMove(completionHandler), sessionID] () mutable {
+    m_pendingDeleteWebsiteDataForOriginsCallbacks.add(callbackID, [this, activity = throttler().backgroundActivity("NetworkProcessProxy::deleteWebsiteDataForOrigins"_s), completionHandler = WTFMove(completionHandler), sessionID] () mutable {
 #if RELEASE_LOG_DISABLED
         UNUSED_PARAM(this);
         UNUSED_PARAM(sessionID);
@@ -302,9 +302,9 @@ void NetworkProcessProxy::didClose(IPC::Connection&)
     m_customProtocolManagerProxy.invalidate();
 #endif
 
-    m_tokenForHoldingLockedFiles = nullptr;
+    m_activityForHoldingLockedFiles = nullptr;
     
-    m_syncAllCookiesToken = nullptr;
+    m_syncAllCookiesActivity = nullptr;
     m_syncAllCookiesCounter = 0;
 
     // This will cause us to be deleted.
@@ -1093,12 +1093,12 @@ void NetworkProcessProxy::setIsHoldingLockedFiles(bool isHoldingLockedFiles)
 {
     if (!isHoldingLockedFiles) {
         RELEASE_LOG(ProcessSuspension, "UIProcess is releasing a background assertion because the Network process is no longer holding locked files");
-        m_tokenForHoldingLockedFiles = nullptr;
+        m_activityForHoldingLockedFiles = nullptr;
         return;
     }
-    if (!m_tokenForHoldingLockedFiles) {
+    if (!m_activityForHoldingLockedFiles) {
         RELEASE_LOG(ProcessSuspension, "UIProcess is taking a background assertion because the Network process is holding locked files");
-        m_tokenForHoldingLockedFiles = m_throttler.backgroundActivityToken();
+        m_activityForHoldingLockedFiles = m_throttler.backgroundActivity("Holding locked files"_s);
     }
 }
 
@@ -1107,11 +1107,11 @@ void NetworkProcessProxy::syncAllCookies()
     send(Messages::NetworkProcess::SyncAllCookies(), 0);
     
     ++m_syncAllCookiesCounter;
-    if (m_syncAllCookiesToken)
+    if (m_syncAllCookiesActivity)
         return;
     
     RELEASE_LOG(ProcessSuspension, "%p - NetworkProcessProxy is taking a background assertion because the Network process is syncing cookies", this);
-    m_syncAllCookiesToken = throttler().backgroundActivityToken();
+    m_syncAllCookiesActivity = throttler().backgroundActivity("Syncing cookies"_s);
 }
     
 void NetworkProcessProxy::didSyncAllCookies()
@@ -1121,7 +1121,7 @@ void NetworkProcessProxy::didSyncAllCookies()
     --m_syncAllCookiesCounter;
     if (!m_syncAllCookiesCounter) {
         RELEASE_LOG(ProcessSuspension, "%p - NetworkProcessProxy is releasing a background assertion because the Network process is done syncing cookies", this);
-        m_syncAllCookiesToken = nullptr;
+        m_syncAllCookiesActivity = nullptr;
     }
 }
 
index e10f0e0..47262eb 100644 (file)
@@ -277,8 +277,8 @@ private:
     LegacyCustomProtocolManagerProxy m_customProtocolManagerProxy;
 #endif
     ProcessThrottler m_throttler;
-    ProcessThrottler::BackgroundActivityToken m_tokenForHoldingLockedFiles;
-    ProcessThrottler::BackgroundActivityToken m_syncAllCookiesToken;
+    std::unique_ptr<ProcessThrottler::BackgroundActivity> m_activityForHoldingLockedFiles;
+    std::unique_ptr<ProcessThrottler::BackgroundActivity> m_syncAllCookiesActivity;
     
     unsigned m_syncAllCookiesCounter { 0 };
 
index cd699f0..2dd39bf 100644 (file)
@@ -43,17 +43,54 @@ static uint64_t generatePrepareToSuspendRequestID()
 ProcessThrottler::ProcessThrottler(ProcessThrottlerClient& process, bool shouldTakeUIBackgroundAssertion)
     : m_process(process)
     , m_prepareToSuspendTimeoutTimer(RunLoop::main(), this, &ProcessThrottler::prepareToSuspendTimeoutTimerFired)
-    , m_foregroundCounter([this](RefCounterEvent) { updateAssertionIfNeeded(); })
-    , m_backgroundCounter([this](RefCounterEvent) { updateAssertionIfNeeded(); })
     , m_shouldTakeUIBackgroundAssertion(shouldTakeUIBackgroundAssertion)
 {
 }
+
+ProcessThrottler::~ProcessThrottler()
+{
+    invalidateAllActivities();
+}
+
+void ProcessThrottler::addActivity(ForegroundActivity& activity)
+{
+    m_foregroundActivities.add(&activity);
+    updateAssertionIfNeeded();
+}
+
+void ProcessThrottler::addActivity(BackgroundActivity& activity)
+{
+    m_backgroundActivities.add(&activity);
+    updateAssertionIfNeeded();
+}
+
+void ProcessThrottler::removeActivity(ForegroundActivity& activity)
+{
+    m_foregroundActivities.remove(&activity);
+    updateAssertionIfNeeded();
+}
+
+void ProcessThrottler::removeActivity(BackgroundActivity& activity)
+{
+    m_backgroundActivities.remove(&activity);
+    updateAssertionIfNeeded();
+}
+
+void ProcessThrottler::invalidateAllActivities()
+{
+    RELEASE_LOG(ProcessSuspension, "[PID: %d] %p - ProcessThrottler::invalidateAllActivities() BEGIN", m_processIdentifier, this);
+    while (!m_foregroundActivities.isEmpty())
+        (*m_foregroundActivities.begin())->invalidate();
+    while (!m_backgroundActivities.isEmpty())
+        (*m_backgroundActivities.begin())->invalidate();
+    RELEASE_LOG(ProcessSuspension, "[PID: %d] %p - ProcessThrottler::invalidateAllActivities() END", m_processIdentifier, this);
+}
     
 AssertionState ProcessThrottler::expectedAssertionState()
 {
-    if (m_foregroundCounter.value())
+    if (!m_foregroundActivities.isEmpty())
         return AssertionState::Foreground;
-    if (m_backgroundCounter.value())
+    if (!m_backgroundActivities.isEmpty())
         return AssertionState::Background;
     return AssertionState::Suspended;
 }
@@ -69,7 +106,7 @@ void ProcessThrottler::setAssertionState(AssertionState newState)
     if (m_assertion->state() == newState)
         return;
 
-    RELEASE_LOG(ProcessSuspension, "[PID: %d] %p - ProcessThrottler::setAssertionState() Updating process assertion state to %u (foregroundActivities: %lu, backgroundActivities: %lu)", m_processIdentifier, this, newState, m_foregroundCounter.value(), m_backgroundCounter.value());
+    RELEASE_LOG(ProcessSuspension, "[PID: %d] %p - ProcessThrottler::setAssertionState() Updating process assertion state to %u (foregroundActivities: %u, backgroundActivities: %u)", m_processIdentifier, this, newState, m_foregroundActivities.size(), m_backgroundActivities.size());
     m_assertion->setState(newState);
     m_process.didSetAssertionState(newState);
 }
@@ -164,6 +201,7 @@ void ProcessThrottler::uiAssertionWillExpireImminently()
 {
     RELEASE_LOG(ProcessSuspension, "[PID: %d] %p - ProcessThrottler::uiAssertionWillExpireImminently()", m_processIdentifier, this);
     sendPrepareToSuspendIPC(IsSuspensionImminent::Yes);
+    invalidateAllActivities();
     m_prepareToSuspendTimeoutTimer.stop();
 }
 
index 976228b..ea73c0f 100644 (file)
@@ -26,8 +26,8 @@
 #ifndef ProcessThrottler_h
 #define ProcessThrottler_h
 
+#include "Logging.h"
 #include "ProcessAssertion.h"
-
 #include <wtf/ProcessID.h>
 #include <wtf/RefCounter.h>
 #include <wtf/RunLoop.h>
@@ -47,20 +47,52 @@ class ProcessThrottlerClient;
 
 class ProcessThrottler : public CanMakeWeakPtr<ProcessThrottler>, private ProcessAssertion::Client {
 public:
-    enum ForegroundActivityCounterType { };
-    typedef RefCounter<ForegroundActivityCounterType> ForegroundActivityCounter;
-    typedef ForegroundActivityCounter::Token ForegroundActivityToken;
-    enum BackgroundActivityCounterType { };
-    typedef RefCounter<BackgroundActivityCounterType> BackgroundActivityCounter;
-    typedef BackgroundActivityCounter::Token BackgroundActivityToken;
-
     ProcessThrottler(ProcessThrottlerClient&, bool shouldTakeUIBackgroundAssertion);
-
-    ForegroundActivityToken foregroundActivityToken() const;
-    BackgroundActivityToken backgroundActivityToken() const;
+    ~ProcessThrottler();
+
+    enum class ActivityType { Background, Foreground };
+    template<ActivityType type> class Activity {
+        WTF_MAKE_FAST_ALLOCATED;
+    public:
+        Activity(ProcessThrottler& throttler, ASCIILiteral name)
+            : m_throttler(&throttler)
+            , m_name(name)
+        {
+            throttler.addActivity(*this);
+            RELEASE_LOG(ProcessSuspension, "[PID: %d] %p - ProcessThrottler Starting %{public}s activity %p / '%{public}s'", m_throttler->m_processIdentifier, m_throttler, type == ActivityType::Foreground ? "foreground" : "background", this, m_name.characters());
+        }
+
+        ~Activity()
+        {
+            if (isValid())
+                invalidate();
+        }
+
+        bool isValid() const { return !!m_throttler; }
+
+    private:
+        friend class ProcessThrottler;
+
+        void invalidate()
+        {
+            ASSERT(!m_throttler);
+            RELEASE_LOG(ProcessSuspension, "[PID: %d] %p - ProcessThrottler Ending %{public}s activity %p / '%{public}s'", m_throttler->m_processIdentifier, m_throttler, type == ActivityType::Foreground ? "foreground" : "background", this, m_name.characters());
+            m_throttler->removeActivity(*this);
+            m_throttler = nullptr;
+        }
+
+        ProcessThrottler* m_throttler { nullptr };
+        ASCIILiteral m_name;
+    };
+
+    using ForegroundActivity = Activity<ActivityType::Foreground>;
+    std::unique_ptr<ForegroundActivity> foregroundActivity(ASCIILiteral name);
+
+    using BackgroundActivity = Activity<ActivityType::Background>;
+    std::unique_ptr<BackgroundActivity> backgroundActivity(ASCIILiteral name);
     
     void didConnectToProcess(ProcessID);
-    bool shouldBeRunnable() const { return m_foregroundCounter.value() || m_backgroundCounter.value(); }
+    bool shouldBeRunnable() const { return m_foregroundActivities.size() || m_backgroundActivities.size(); }
 
 private:
     AssertionState expectedAssertionState();
@@ -71,6 +103,12 @@ private:
     void sendPrepareToSuspendIPC(IsSuspensionImminent);
     void processReadyToSuspend();
 
+    void addActivity(ForegroundActivity&);
+    void addActivity(BackgroundActivity&);
+    void removeActivity(ForegroundActivity&);
+    void removeActivity(BackgroundActivity&);
+    void invalidateAllActivities();
+
     // ProcessAssertionClient
     void uiAssertionWillExpireImminently() override;
 
@@ -80,22 +118,22 @@ private:
     ProcessID m_processIdentifier { 0 };
     std::unique_ptr<ProcessAssertion> m_assertion;
     RunLoop::Timer<ProcessThrottler> m_prepareToSuspendTimeoutTimer;
-    ForegroundActivityCounter m_foregroundCounter;
-    BackgroundActivityCounter m_backgroundCounter;
+    HashSet<ForegroundActivity*> m_foregroundActivities;
+    HashSet<BackgroundActivity*> m_backgroundActivities;
     Optional<uint64_t> m_pendingRequestToSuspendID;
     bool m_shouldTakeUIBackgroundAssertion;
 };
 
-inline ProcessThrottler::ForegroundActivityToken ProcessThrottler::foregroundActivityToken() const
+inline auto ProcessThrottler::foregroundActivity(ASCIILiteral name) -> std::unique_ptr<ForegroundActivity>
 {
-    return ForegroundActivityToken(m_foregroundCounter.count());
+    return makeUnique<ForegroundActivity>(*this, name);
 }
 
-inline ProcessThrottler::BackgroundActivityToken ProcessThrottler::backgroundActivityToken() const
+inline auto ProcessThrottler::backgroundActivity(ASCIILiteral name) -> std::unique_ptr<BackgroundActivity>
 {
-    return BackgroundActivityToken(m_backgroundCounter.count());
-}
-    
+    return makeUnique<BackgroundActivity>(*this, name);
 }
 
+} // namespace WebKit
+
 #endif // ProcessThrottler_h
index 0b804fa..62f5815 100644 (file)
@@ -63,7 +63,7 @@ ProvisionalPageProxy::ProvisionalPageProxy(WebPageProxy& page, Ref<WebProcessPro
     , m_request(request)
     , m_processSwapRequestedByClient(processSwapRequestedByClient)
 #if PLATFORM(IOS_FAMILY)
-    , m_suspensionToken(m_process->throttler().foregroundActivityToken())
+    , m_provisionalLoadActivity(m_process->throttler().foregroundActivity("Provisional Load"_s))
 #endif
 {
     RELEASE_LOG_IF_ALLOWED(ProcessSwapping, "ProvisionalPageProxy: pageProxyID=%" PRIu64 " webPageID=%" PRIu64 " navigationID=%" PRIu64 " suspendedPage: %p", m_page.identifier().toUInt64(), m_webPageID.toUInt64(), navigationID, suspendedPage.get());
index 9f87121..b14cdc3 100644 (file)
@@ -143,7 +143,7 @@ private:
     Vector<uint8_t> m_accessibilityToken;
 #endif
 #if PLATFORM(IOS_FAMILY)
-    ProcessThrottler::ForegroundActivityToken m_suspensionToken;
+    std::unique_ptr<ProcessThrottler::ForegroundActivity> m_provisionalLoadActivity;
 #endif
 };
 
index 728d8b0..b7b0469 100644 (file)
@@ -471,7 +471,7 @@ void RemoteLayerTreeDrawingAreaProxy::dispatchAfterEnsuringDrawing(WTF::Function
         return;
     }
 
-    send(Messages::DrawingArea::AddTransactionCallbackID(m_callbacks.put(WTFMove(callbackFunction), process().throttler().backgroundActivityToken())));
+    send(Messages::DrawingArea::AddTransactionCallbackID(m_callbacks.put(WTFMove(callbackFunction), process().throttler().backgroundActivity("RemoteLayerTreeDrawingAreaProxy::dispatchAfterEnsuringDrawing"_s))));
 }
 
 void RemoteLayerTreeDrawingAreaProxy::hideContentUntilPendingUpdate()
index 7f89cee..eabef9a 100644 (file)
@@ -102,7 +102,7 @@ SuspendedPageProxy::SuspendedPageProxy(WebPageProxy& page, Ref<WebProcessProxy>&
     , m_shouldDelayClosingUntilEnteringAcceleratedCompositingMode(shouldDelayClosingUntilEnteringAcceleratedCompositingMode)
     , m_suspensionTimeoutTimer(RunLoop::main(), this, &SuspendedPageProxy::suspensionTimedOut)
 #if PLATFORM(IOS_FAMILY)
-    , m_suspensionToken(m_process->throttler().backgroundActivityToken())
+    , m_suspensionActivity(m_process->throttler().backgroundActivity("Page suspension for back/forward cache"_s))
 #endif
 {
     allSuspendedPages().add(this);
@@ -218,7 +218,7 @@ void SuspendedPageProxy::didProcessRequestToSuspend(SuspensionState newSuspensio
     m_suspensionTimeoutTimer.stop();
 
 #if PLATFORM(IOS_FAMILY)
-    m_suspensionToken = nullptr;
+    m_suspensionActivity = nullptr;
 #endif
 
     m_process->removeMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_webPageID);
index ee2c6a3..702e962 100644 (file)
@@ -97,7 +97,7 @@ private:
     CompletionHandler<void(SuspendedPageProxy*)> m_readyToUnsuspendHandler;
     RunLoop::Timer<SuspendedPageProxy> m_suspensionTimeoutTimer;
 #if PLATFORM(IOS_FAMILY)
-    ProcessThrottler::BackgroundActivityToken m_suspensionToken;
+    std::unique_ptr<ProcessThrottler::BackgroundActivity> m_suspensionActivity;
 #endif
 };
 
index 59fbed5..ae56e53 100644 (file)
@@ -50,7 +50,7 @@ WebBackForwardCacheEntry::~WebBackForwardCacheEntry()
 {
     if (m_backForwardItemID && !m_suspendedPage) {
         auto& process = this->process();
-        process.sendWithAsyncReply(Messages::WebProcess::ClearCachedPage(m_backForwardItemID), [token = process.throttler().backgroundActivityToken()] { });
+        process.sendWithAsyncReply(Messages::WebProcess::ClearCachedPage(m_backForwardItemID), [activity = process.throttler().backgroundActivity("Clearing back/forward cache entry"_s)] { });
     }
 }
 
index 1b3e155..dc2cd69 100644 (file)
@@ -102,7 +102,7 @@ void WebCookieManagerProxy::derefWebContextSupplement()
 void WebCookieManagerProxy::getHostnamesWithCookies(PAL::SessionID sessionID, CompletionHandler<void(Vector<String>&&)>&& callbackFunction)
 {
     auto& networkProcess = processPool()->ensureNetworkProcess();
-    networkProcess.sendWithAsyncReply(Messages::WebCookieManager::GetHostnamesWithCookies(sessionID), [callbackFunction = WTFMove(callbackFunction), token = networkProcess.throttler().backgroundActivityToken()](Vector<String>&& hostnames) mutable {
+    networkProcess.sendWithAsyncReply(Messages::WebCookieManager::GetHostnamesWithCookies(sessionID), [callbackFunction = WTFMove(callbackFunction), activity = networkProcess.throttler().backgroundActivity("WebCookieManagerProxy::getHostnamesWithCookies"_s)](Vector<String>&& hostnames) mutable {
         callbackFunction(WTFMove(hostnames));
     });
 }
@@ -120,7 +120,7 @@ void WebCookieManagerProxy::deleteAllCookies(PAL::SessionID sessionID)
 void WebCookieManagerProxy::deleteCookie(PAL::SessionID sessionID, const Cookie& cookie, CompletionHandler<void()>&& callbackFunction)
 {
     auto& networkProcess = processPool()->ensureNetworkProcess();
-    networkProcess.sendWithAsyncReply(Messages::WebCookieManager::DeleteCookie(sessionID, cookie), [callbackFunction = WTFMove(callbackFunction), token = networkProcess.throttler().backgroundActivityToken()]() mutable {
+    networkProcess.sendWithAsyncReply(Messages::WebCookieManager::DeleteCookie(sessionID, cookie), [callbackFunction = WTFMove(callbackFunction), activity = networkProcess.throttler().backgroundActivity("WebCookieManagerProxy::deleteCookie"_s)]() mutable {
         callbackFunction();
     });
 }
@@ -128,7 +128,7 @@ void WebCookieManagerProxy::deleteCookie(PAL::SessionID sessionID, const Cookie&
 void WebCookieManagerProxy::deleteAllCookiesModifiedSince(PAL::SessionID sessionID, WallTime time, CompletionHandler<void()>&& callbackFunction)
 {
     auto& networkProcess = processPool()->ensureNetworkProcess();
-    networkProcess.sendWithAsyncReply(Messages::WebCookieManager::DeleteAllCookiesModifiedSince(sessionID, time), [callbackFunction = WTFMove(callbackFunction), token = networkProcess.throttler().backgroundActivityToken()]() mutable {
+    networkProcess.sendWithAsyncReply(Messages::WebCookieManager::DeleteAllCookiesModifiedSince(sessionID, time), [callbackFunction = WTFMove(callbackFunction), activity = networkProcess.throttler().backgroundActivity("WebCookieManagerProxy::deleteAllCookiesModifiedSince"_s)]() mutable {
         callbackFunction();
     });
 }
@@ -136,7 +136,7 @@ void WebCookieManagerProxy::deleteAllCookiesModifiedSince(PAL::SessionID session
 void WebCookieManagerProxy::setCookies(PAL::SessionID sessionID, const Vector<Cookie>& cookies, CompletionHandler<void()>&& callbackFunction)
 {
     auto& networkProcess = processPool()->ensureNetworkProcess();
-    networkProcess.sendWithAsyncReply(Messages::WebCookieManager::SetCookie(sessionID, cookies), [callbackFunction = WTFMove(callbackFunction), token = networkProcess.throttler().backgroundActivityToken()]() mutable {
+    networkProcess.sendWithAsyncReply(Messages::WebCookieManager::SetCookie(sessionID, cookies), [callbackFunction = WTFMove(callbackFunction), activity = networkProcess.throttler().backgroundActivity("WebCookieManagerProxy::setCookies"_s)]() mutable {
         callbackFunction();
     });
 }
@@ -144,7 +144,7 @@ void WebCookieManagerProxy::setCookies(PAL::SessionID sessionID, const Vector<Co
 void WebCookieManagerProxy::setCookies(PAL::SessionID sessionID, const Vector<Cookie>& cookies, const URL& url, const URL& mainDocumentURL, CompletionHandler<void()>&& callbackFunction)
 {
     auto& networkProcess = processPool()->ensureNetworkProcess();
-    networkProcess.sendWithAsyncReply(Messages::WebCookieManager::SetCookies(sessionID, cookies, url, mainDocumentURL), [callbackFunction = WTFMove(callbackFunction), token = networkProcess.throttler().backgroundActivityToken()]() mutable {
+    networkProcess.sendWithAsyncReply(Messages::WebCookieManager::SetCookies(sessionID, cookies, url, mainDocumentURL), [callbackFunction = WTFMove(callbackFunction), activity = networkProcess.throttler().backgroundActivity("WebCookieManagerProxy::setCookies"_s)]() mutable {
         callbackFunction();
     });
 }
@@ -152,7 +152,7 @@ void WebCookieManagerProxy::setCookies(PAL::SessionID sessionID, const Vector<Co
 void WebCookieManagerProxy::getAllCookies(PAL::SessionID sessionID, CompletionHandler<void(Vector<Cookie>&&)>&& callbackFunction)
 {
     auto& networkProcess = processPool()->ensureNetworkProcess();
-    networkProcess.sendWithAsyncReply(Messages::WebCookieManager::GetAllCookies(sessionID), [callbackFunction = WTFMove(callbackFunction), token = networkProcess.throttler().backgroundActivityToken()](Vector<Cookie>&& cookies) mutable {
+    networkProcess.sendWithAsyncReply(Messages::WebCookieManager::GetAllCookies(sessionID), [callbackFunction = WTFMove(callbackFunction), activity = networkProcess.throttler().backgroundActivity("WebCookieManagerProxy::getAllCookies"_s)](Vector<Cookie>&& cookies) mutable {
         callbackFunction(WTFMove(cookies));
     });
 }
@@ -160,7 +160,7 @@ void WebCookieManagerProxy::getAllCookies(PAL::SessionID sessionID, CompletionHa
 void WebCookieManagerProxy::getCookies(PAL::SessionID sessionID, const URL& url, CompletionHandler<void(Vector<Cookie>&&)>&& callbackFunction)
 {
     auto& networkProcess = processPool()->ensureNetworkProcess();
-    networkProcess.sendWithAsyncReply(Messages::WebCookieManager::GetCookies(sessionID, url), [callbackFunction = WTFMove(callbackFunction), token = networkProcess.throttler().backgroundActivityToken()](Vector<Cookie>&& cookies) mutable {
+    networkProcess.sendWithAsyncReply(Messages::WebCookieManager::GetCookies(sessionID, url), [callbackFunction = WTFMove(callbackFunction), activity = networkProcess.throttler().backgroundActivity("WebCookieManagerProxy::getCookies"_s)](Vector<Cookie>&& cookies) mutable {
         callbackFunction(WTFMove(cookies));
     });
 }
@@ -232,7 +232,7 @@ void WebCookieManagerProxy::setHTTPCookieAcceptPolicy(PAL::SessionID, HTTPCookie
 #endif
 
     auto& networkProcess = processPool()->ensureNetworkProcess();
-    networkProcess.sendWithAsyncReply(Messages::WebCookieManager::SetHTTPCookieAcceptPolicy(policy), [callbackFunction = WTFMove(callbackFunction), token = networkProcess.throttler().backgroundActivityToken()]() mutable {
+    networkProcess.sendWithAsyncReply(Messages::WebCookieManager::SetHTTPCookieAcceptPolicy(policy), [callbackFunction = WTFMove(callbackFunction), activity = networkProcess.throttler().backgroundActivity("WebCookieManagerProxy::setHTTPCookieAcceptPolicy"_s)]() mutable {
         callbackFunction();
     });
 }
@@ -240,7 +240,7 @@ void WebCookieManagerProxy::setHTTPCookieAcceptPolicy(PAL::SessionID, HTTPCookie
 void WebCookieManagerProxy::getHTTPCookieAcceptPolicy(PAL::SessionID, CompletionHandler<void(HTTPCookieAcceptPolicy)>&& callbackFunction)
 {
     auto& networkProcess = processPool()->ensureNetworkProcess();
-    networkProcess.sendWithAsyncReply(Messages::WebCookieManager::GetHTTPCookieAcceptPolicy(), [callbackFunction = WTFMove(callbackFunction), token = networkProcess.throttler().backgroundActivityToken()](HTTPCookieAcceptPolicy policy) mutable {
+    networkProcess.sendWithAsyncReply(Messages::WebCookieManager::GetHTTPCookieAcceptPolicy(), [callbackFunction = WTFMove(callbackFunction), activity = networkProcess.throttler().backgroundActivity("WebCookieManagerProxy::getHTTPCookieAcceptPolicy"_s)](HTTPCookieAcceptPolicy policy) mutable {
         callbackFunction(policy);
     });
 }
index 193f1c7..7088bd1 100644 (file)
@@ -1055,7 +1055,10 @@ void WebPageProxy::close()
 
 #if PLATFORM(IOS_FAMILY)
     // Make sure we don't hold a process assertion after getting closed.
-    m_activityToken = nullptr;
+    m_isVisibleActivity = nullptr;
+    m_isAudibleActivity = nullptr;
+    m_isCapturingActivity = nullptr;
+    m_alwaysRunsAtForegroundPriorityActivity = nullptr;
 #endif
 
     stopAllURLSchemeTasks();
@@ -1929,23 +1932,46 @@ void WebPageProxy::updateThrottleState()
         m_pageIsUserObservableCount = m_process->processPool().userObservablePageCount();
 
 #if PLATFORM(IOS_FAMILY)
-    bool isCapturingMedia = m_activityState.contains(ActivityState::IsCapturingMedia);
-    bool isAudible = m_activityState.contains(ActivityState::IsAudible);
-    if (!isViewVisible() && !m_alwaysRunsAtForegroundPriority && !isCapturingMedia && !isAudible) {
-        if (m_activityToken) {
-            RELEASE_LOG_IF_ALLOWED(ProcessSuspension, "updateThrottleState: UIProcess is releasing a foreground assertion because the view is no longer visible");
-            m_activityToken = nullptr;
-        }
-    } else if (!m_activityToken) {
-        if (isViewVisible())
+    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");
-        else if (isAudible)
+            m_isVisibleActivity = m_process->throttler().foregroundActivity("View is visible"_s);
+        }
+    } else if (m_isVisibleActivity) {
+        RELEASE_LOG_IF_ALLOWED(ProcessSuspension, "updateThrottleState: UIProcess is releasing a foreground assertion because the view is no longer visible");
+        m_isVisibleActivity = nullptr;
+    }
+
+    bool isAudible = m_activityState.contains(ActivityState::IsAudible);
+    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");
-        else if (isCapturingMedia)
+            m_isAudibleActivity = m_process->throttler().foregroundActivity("View is playing audio"_s);
+        }
+    } else if (m_isAudibleActivity) {
+        RELEASE_LOG_IF_ALLOWED(ProcessSuspension, "updateThrottleState: UIProcess is releasing a foreground assertion because we are no longer playing audio");
+        m_isAudibleActivity = nullptr;
+    }
+
+    bool isCapturingMedia = m_activityState.contains(ActivityState::IsCapturingMedia);
+    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");
-        else
-            RELEASE_LOG_IF_ALLOWED(ProcessSuspension, "updateThrottleState: UIProcess is taking a foreground assertion even though the view is not visible because m_alwaysRunsAtForegroundPriority is true");
-        m_activityToken = m_process->throttler().foregroundActivityToken();
+            m_isCapturingActivity = m_process->throttler().foregroundActivity("View is capturing media"_s);
+        }
+    } else if (m_isCapturingActivity) {
+        RELEASE_LOG_IF_ALLOWED(ProcessSuspension, "updateThrottleState: UIProcess is releasing a foreground assertion because media capture is no longer active");
+        m_isCapturingActivity = nullptr;
+    }
+
+    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);
+        }
+    } else if (m_alwaysRunsAtForegroundPriorityActivity) {
+        RELEASE_LOG_IF_ALLOWED(ProcessSuspension, "updateThrottleState: UIProcess is releasing a foreground assertion because m_alwaysRunsAtForegroundPriority is no longer true");
+        m_alwaysRunsAtForegroundPriorityActivity = nullptr;
     }
 #endif
 }
@@ -1985,7 +2011,7 @@ void WebPageProxy::waitForDidUpdateActivityState(ActivityStateChangeID activityS
 #if PLATFORM(IOS_FAMILY)
     // Hail Mary check. Should not be possible (dispatchActivityStateChange should force async if not visible,
     // and if visible we should be holding an assertion) - but we should never block on a suspended process.
-    if (!m_activityToken) {
+    if (!m_isVisibleActivity) {
         ASSERT_NOT_REACHED();
         return;
     }
@@ -2008,7 +2034,7 @@ void WebPageProxy::setInitialFocus(bool forward, bool isKeyboardEventValid, cons
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::setInitialFocus"_s));
     m_process->send(Messages::WebPage::SetInitialFocus(forward, isKeyboardEventValid, keyboardEvent, callbackID), m_webPageID);
 }
 
@@ -2033,7 +2059,7 @@ void WebPageProxy::validateCommand(const String& commandName, WTF::Function<void
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::validateCommand"_s));
     m_process->send(Messages::WebPage::ValidateCommand(commandName, callbackID), m_webPageID);
 }
 
@@ -2131,7 +2157,7 @@ void WebPageProxy::executeEditCommand(const String& commandName, const String& a
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::executeEditCommand"_s));
     m_process->send(Messages::WebPage::ExecuteEditCommandWithCallback(commandName, argument, callbackID), m_webPageID);
 }
     
@@ -2155,7 +2181,7 @@ void WebPageProxy::requestFontAttributesAtSelectionStart(Function<void(const Web
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivity("WebPageProxy::requestFontAttributesAtSelectionStart"_s));
     m_process->send(Messages::WebPage::RequestFontAttributesAtSelectionStart(callbackID), m_webPageID);
 }
 
@@ -3713,7 +3739,7 @@ void WebPageProxy::replaceMatches(Vector<uint32_t>&& matchIndices, const String&
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivity("WebPageProxy::replaceMatches"_s));
     m_process->send(Messages::WebPage::ReplaceMatches(WTFMove(matchIndices), replacementText, selectionOnly, callbackID), m_webPageID);
 }
 
@@ -3738,14 +3764,14 @@ void WebPageProxy::runJavaScriptInMainFrameScriptWorld(const String& script, boo
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::runJavaScriptInMainFrameScriptWorld"_s));
     m_process->send(Messages::WebPage::RunJavaScriptInMainFrameScriptWorld(script, forceUserGesture, worldName, callbackID), m_webPageID);
 }
 
 void WebPageProxy::runJavaScriptInFrame(FrameIdentifier frameID, const String& script, bool forceUserGesture, WTF::Function<void(API::SerializedScriptValue*, bool hadException, const ExceptionDetails&, CallbackBase::Error)>&& callbackFunction)
 {
     ASSERT(mainFrame()->frameID() != frameID);
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::runJavaScriptInFrame"_s));
     m_process->send(Messages::WebPage::RunJavaScriptInFrame(frameID, script, forceUserGesture, callbackID), m_webPageID);
 }
 
@@ -3756,7 +3782,7 @@ void WebPageProxy::getRenderTreeExternalRepresentation(WTF::Function<void (const
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::getRenderTreeExternalRepresentation"_s));
     m_process->send(Messages::WebPage::GetRenderTreeExternalRepresentation(callbackID), m_webPageID);
 }
 
@@ -3767,7 +3793,7 @@ void WebPageProxy::getSourceForFrame(WebFrameProxy* frame, WTF::Function<void (c
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::getSourceForFrame"_s));
     m_loadDependentStringCallbackIDs.add(callbackID);
     m_process->send(Messages::WebPage::GetSourceForFrame(frame->frameID(), callbackID), m_webPageID);
 }
@@ -3779,7 +3805,7 @@ void WebPageProxy::getContentsAsString(WTF::Function<void (const String&, Callba
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::getContentsAsString"_s));
     m_loadDependentStringCallbackIDs.add(callbackID);
     m_process->send(Messages::WebPage::GetContentsAsString(callbackID), m_webPageID);
 }
@@ -3803,7 +3829,7 @@ void WebPageProxy::getBytecodeProfile(WTF::Function<void (const String&, Callbac
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::getBytecodeProfile"_s));
     m_loadDependentStringCallbackIDs.add(callbackID);
     m_process->send(Messages::WebPage::GetBytecodeProfile(callbackID), m_webPageID);
 }
@@ -3815,7 +3841,7 @@ void WebPageProxy::getSamplingProfilerOutput(WTF::Function<void (const String&,
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::getSamplingProfilerOutput"_s));
     m_loadDependentStringCallbackIDs.add(callbackID);
     m_process->send(Messages::WebPage::GetSamplingProfilerOutput(callbackID), m_webPageID);
 }
@@ -3828,7 +3854,7 @@ void WebPageProxy::getContentsAsMHTMLData(Function<void (API::Data*, CallbackBas
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::getContentsAsMHTMLData"_s));
     m_process->send(Messages::WebPage::GetContentsAsMHTMLData(callbackID), m_webPageID);
 }
 #endif
@@ -3840,7 +3866,7 @@ void WebPageProxy::getSelectionOrContentsAsString(WTF::Function<void (const Stri
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::getSelectionOrContentsAsString"_s));
     m_process->send(Messages::WebPage::GetSelectionOrContentsAsString(callbackID), m_webPageID);
 }
 
@@ -3851,7 +3877,7 @@ void WebPageProxy::getSelectionAsWebArchiveData(Function<void (API::Data*, Callb
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::getSelectionAsWebArchiveData"_s));
     m_process->send(Messages::WebPage::GetSelectionAsWebArchiveData(callbackID), m_webPageID);
 }
 
@@ -3862,7 +3888,7 @@ void WebPageProxy::getMainResourceDataOfFrame(WebFrameProxy* frame, Function<voi
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::getMainResourceDataOfFrame"_s));
     m_process->send(Messages::WebPage::GetMainResourceDataOfFrame(frame->frameID(), callbackID), m_webPageID);
 }
 
@@ -3873,7 +3899,7 @@ void WebPageProxy::getResourceDataFromFrame(WebFrameProxy* frame, API::URL* reso
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::getResourceDataFromFrame"_s));
     m_process->send(Messages::WebPage::GetResourceDataFromFrame(frame->frameID(), resourceURL->string(), callbackID), m_webPageID);
 }
 
@@ -3884,7 +3910,7 @@ void WebPageProxy::getWebArchiveOfFrame(WebFrameProxy* frame, Function<void (API
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::getWebArchiveOfFrame"_s));
     m_process->send(Messages::WebPage::GetWebArchiveOfFrame(frame->frameID(), callbackID), m_webPageID);
 }
 
@@ -3917,7 +3943,7 @@ void WebPageProxy::forceRepaint(RefPtr<VoidCallback>&& callback)
         });
     };
 
-    auto callbackID = m_callbacks.put(WTFMove(didForceRepaintCallback), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(didForceRepaintCallback), m_process->throttler().backgroundActivity("WebPageProxy::forceRepaint"_s));
     m_drawingArea->waitForBackingStoreUpdateOnNextPaint();
     m_process->send(Messages::WebPage::ForceRepaint(callbackID), m_webPageID);
 }
@@ -7209,7 +7235,11 @@ void WebPageProxy::resetStateAfterProcessExited(ProcessTerminationReason termina
 #if PLATFORM(IOS_FAMILY)
     m_waitingForPostLayoutEditorStateUpdateAfterFocusingElement = false;
     m_deferredElementDidFocusArguments = nullptr;
-    m_activityToken = nullptr;
+
+    m_isVisibleActivity = nullptr;
+    m_isAudibleActivity = nullptr;
+    m_isCapturingActivity = nullptr;
+    m_alwaysRunsAtForegroundPriorityActivity = nullptr;
 #endif
 
     m_pageIsUserObservableCount = nullptr;
@@ -7828,7 +7858,7 @@ void WebPageProxy::drawToPDF(FrameIdentifier frameID, const Optional<FloatRect>&
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivity("WebPageProxy::drawToPDF"_s));
     m_process->send(Messages::WebPage::DrawToPDF(frameID, rect, callbackID), m_webPageID);
 }
 
@@ -8160,7 +8190,7 @@ void WebPageProxy::getMarkedRangeAsync(WTF::Function<void (EditingRange, Callbac
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::getMarkedRangeAsync"_s));
     process().send(Messages::WebPage::GetMarkedRangeAsync(callbackID), m_webPageID);
 }
 
@@ -8171,7 +8201,7 @@ void WebPageProxy::getSelectedRangeAsync(WTF::Function<void (EditingRange, Callb
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::getSelectedRangeAsync"_s));
     process().send(Messages::WebPage::GetSelectedRangeAsync(callbackID), m_webPageID);
 }
 
@@ -8182,7 +8212,7 @@ void WebPageProxy::characterIndexForPointAsync(const WebCore::IntPoint& point, W
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::characterIndexForPointAsync"_s));
     process().send(Messages::WebPage::CharacterIndexForPointAsync(point, callbackID), m_webPageID);
 }
 
@@ -8193,7 +8223,7 @@ void WebPageProxy::firstRectForCharacterRangeAsync(const EditingRange& range, WT
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::firstRectForCharacterRangeAsync"_s));
     process().send(Messages::WebPage::FirstRectForCharacterRangeAsync(range, callbackID), m_webPageID);
 }
 
@@ -8237,7 +8267,7 @@ void WebPageProxy::takeSnapshot(IntRect rect, IntSize bitmapSize, SnapshotOption
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::takeSnapshot"_s));
     m_process->send(Messages::WebPage::TakeSnapshot(rect, bitmapSize, options, callbackID), m_webPageID);
 }
 
@@ -8513,7 +8543,7 @@ void WebPageProxy::installActivityStateChangeCompletionHandler(Function<void()>&
 
     auto voidCallback = VoidCallback::create([completionHandler = WTFMove(completionHandler)] (auto) {
         completionHandler();
-    }, m_process->throttler().backgroundActivityToken());
+    }, m_process->throttler().backgroundActivity("WebPageProxy::installActivityStateChangeCompletionHandler"_s));
     auto callbackID = m_callbacks.put(WTFMove(voidCallback));
     m_nextActivityStateChangeCallbacks.append(callbackID);
 }
@@ -8670,7 +8700,7 @@ void WebPageProxy::getLoadDecisionForIcon(const WebCore::LinkIcon& icon, Callbac
         }
 
         bool decision = (bool)callbackFunction;
-        auto newCallbackIdentifier = decision ? OptionalCallbackID(m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken())) : OptionalCallbackID();
+        auto newCallbackIdentifier = decision ? OptionalCallbackID(m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::getLoadDecisionForIcon"_s))) : OptionalCallbackID();
 
         m_process->send(Messages::WebPage::DidGetLoadDecisionForIcon(decision, loadIdentifier, newCallbackIdentifier), m_webPageID);
     });
@@ -8887,7 +8917,7 @@ void WebPageProxy::insertAttachment(Ref<API::Attachment>&& attachment, Function<
     }
 
     auto attachmentIdentifier = attachment->identifier();
-    auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivity("WebPageProxy::insertAttachment"_s));
     m_process->send(Messages::WebPage::InsertAttachment(attachmentIdentifier, attachment->fileSizeForDisplay(), attachment->fileName(), attachment->contentType(), callbackID), m_webPageID);
     m_attachmentIdentifierToAttachmentMap.set(attachmentIdentifier, WTFMove(attachment));
 }
@@ -8903,7 +8933,7 @@ void WebPageProxy::updateAttachmentAttributes(const API::Attachment& attachment,
     if (auto data = attachment.enclosingImageData())
         dataReference = { *data };
 
-    auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivity("WebPageProxy::updateAttachmentAttributes"_s));
     m_process->send(Messages::WebPage::UpdateAttachmentAttributes(attachment.identifier(), attachment.fileSizeForDisplay(), attachment.contentType(), attachment.fileName(), WTFMove(dataReference), callbackID), m_webPageID);
 }
 
@@ -9062,7 +9092,7 @@ void WebPageProxy::getApplicationManifest(Function<void(const Optional<WebCore::
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::getApplicationManifest"_s));
     m_loadDependentStringCallbackIDs.add(callbackID);
     m_process->send(Messages::WebPage::GetApplicationManifest(callbackID), m_webPageID);
 }
index 3ad2c6c..0d859ac 100644 (file)
@@ -2289,7 +2289,10 @@ private:
 #if PLATFORM(IOS_FAMILY)
     bool m_allowsMediaDocumentInlinePlayback { false };
     bool m_alwaysRunsAtForegroundPriority { false };
-    ProcessThrottler::ForegroundActivityToken m_activityToken;
+    std::unique_ptr<ProcessThrottler::ForegroundActivity> m_isVisibleActivity;
+    std::unique_ptr<ProcessThrottler::ForegroundActivity> m_isAudibleActivity;
+    std::unique_ptr<ProcessThrottler::ForegroundActivity> m_isCapturingActivity;
+    std::unique_ptr<ProcessThrottler::ForegroundActivity> m_alwaysRunsAtForegroundPriorityActivity;
 #endif
     bool m_initialCapitalizationEnabled { false };
     Optional<double> m_cpuLimit;
index 48ec4ce..23ac6e4 100644 (file)
@@ -916,12 +916,12 @@ WebProcessDataStoreParameters WebProcessPool::webProcessDataStoreParameters(WebP
 
 void WebProcessPool::initializeNewWebProcess(WebProcessProxy& process, WebsiteDataStore* websiteDataStore, WebProcessProxy::IsPrewarmed isPrewarmed)
 {
-    auto initializationActivityToken = process.throttler().backgroundActivityToken();
-    auto scopeExit = makeScopeExit([&process, initializationActivityToken] {
+    auto initializationActivity = process.throttler().backgroundActivity("WebProcess initialization"_s);
+    auto scopeExit = makeScopeExit([&process, initializationActivity = WTFMove(initializationActivity)]() mutable {
         // Round-trip to the Web Content process before releasing the
-        // initialization activity token, so that we're sure that all
+        // initialization activity, so that we're sure that all
         // messages sent from this function have been handled.
-        process.isResponsive([initializationActivityToken] (bool) { });
+        process.isResponsive([initializationActivity = WTFMove(initializationActivity)] (bool) { });
     });
 
     ensureNetworkProcess();
@@ -2047,24 +2047,24 @@ void WebProcessPool::updateProcessAssertions()
             // 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_foregroundTokensForServiceWorkerProcesses.contains(registrableDomain))
-                    m_foregroundTokensForServiceWorkerProcesses.add(WTFMove(registrableDomain), serviceWorkerProcess->throttler().foregroundActivityToken());
+                if (!m_foregroundActivitiesForServiceWorkerProcesses.contains(registrableDomain))
+                    m_foregroundActivitiesForServiceWorkerProcesses.add(WTFMove(registrableDomain), serviceWorkerProcess->throttler().foregroundActivity("Service Worker for visible view(s)"_s));
             }
-            m_backgroundTokensForServiceWorkerProcesses.clear();
+            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_backgroundTokensForServiceWorkerProcesses.contains(registrableDomain))
-                    m_backgroundTokensForServiceWorkerProcesses.add(WTFMove(registrableDomain), serviceWorkerProcess->throttler().backgroundActivityToken());
+                if (!m_backgroundActivitiesForServiceWorkerProcesses.contains(registrableDomain))
+                    m_backgroundActivitiesForServiceWorkerProcesses.add(WTFMove(registrableDomain), serviceWorkerProcess->throttler().backgroundActivity("Service Worker for background view(s)"_s));
             }
-            m_foregroundTokensForServiceWorkerProcesses.clear();
+            m_foregroundActivitiesForServiceWorkerProcesses.clear();
             return;
         }
-        m_foregroundTokensForServiceWorkerProcesses.clear();
-        m_backgroundTokensForServiceWorkerProcesses.clear();
+        m_foregroundActivitiesForServiceWorkerProcesses.clear();
+        m_backgroundActivitiesForServiceWorkerProcesses.clear();
     };
     updateServiceWorkerProcessAssertion();
 #endif
@@ -2073,23 +2073,23 @@ void WebProcessPool::updateProcessAssertions()
         auto& networkProcess = ensureNetworkProcess();
 
         if (m_foregroundWebProcessCounter.value()) {
-            if (!m_foregroundTokenForNetworkProcess) {
-                m_foregroundTokenForNetworkProcess = networkProcess.throttler().foregroundActivityToken();
+            if (!m_foregroundActivityForNetworkProcess) {
+                m_foregroundActivityForNetworkProcess = networkProcess.throttler().foregroundActivity("Networking for foreground view(s)"_s);
                 networkProcess.sendProcessDidTransitionToForeground();
             }
-            m_backgroundTokenForNetworkProcess = nullptr;
+            m_backgroundActivityForNetworkProcess = nullptr;
             return;
         }
         if (m_backgroundWebProcessCounter.value()) {
-            if (!m_backgroundTokenForNetworkProcess) {
-                m_backgroundTokenForNetworkProcess = networkProcess.throttler().backgroundActivityToken();
+            if (!m_backgroundActivityForNetworkProcess) {
+                m_backgroundActivityForNetworkProcess = networkProcess.throttler().backgroundActivity("Networking for foreground background view(s)"_s);
                 networkProcess.sendProcessDidTransitionToBackground();
             }
-            m_foregroundTokenForNetworkProcess = nullptr;
+            m_foregroundActivityForNetworkProcess = nullptr;
             return;
         }
-        m_foregroundTokenForNetworkProcess = nullptr;
-        m_backgroundTokenForNetworkProcess = nullptr;
+        m_foregroundActivityForNetworkProcess = nullptr;
+        m_backgroundActivityForNetworkProcess = nullptr;
     };
     updateNetworkProcessAssertion();
 #endif
@@ -2098,11 +2098,11 @@ void WebProcessPool::updateProcessAssertions()
 void WebProcessPool::reinstateNetworkProcessAssertionState(NetworkProcessProxy& newNetworkProcessProxy)
 {
 #if PLATFORM(IOS_FAMILY)
-    // The network process crashed; take new tokens for the new network process.
-    if (m_backgroundTokenForNetworkProcess)
-        m_backgroundTokenForNetworkProcess = newNetworkProcessProxy.throttler().backgroundActivityToken();
-    else if (m_foregroundTokenForNetworkProcess)
-        m_foregroundTokenForNetworkProcess = newNetworkProcessProxy.throttler().foregroundActivityToken();
+    // 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
index 04ccc96..8da0b17 100644 (file)
@@ -760,11 +760,11 @@ private:
 #if PLATFORM(IOS_FAMILY)
     ForegroundWebProcessCounter m_foregroundWebProcessCounter;
     BackgroundWebProcessCounter m_backgroundWebProcessCounter;
-    ProcessThrottler::ForegroundActivityToken m_foregroundTokenForNetworkProcess;
-    ProcessThrottler::BackgroundActivityToken m_backgroundTokenForNetworkProcess;
+    std::unique_ptr<ProcessThrottler::ForegroundActivity> m_foregroundActivityForNetworkProcess;
+    std::unique_ptr<ProcessThrottler::BackgroundActivity> m_backgroundActivityForNetworkProcess;
 #if ENABLE(SERVICE_WORKER)
-    HashMap<WebCore::RegistrableDomain, ProcessThrottler::ForegroundActivityToken> m_foregroundTokensForServiceWorkerProcesses;
-    HashMap<WebCore::RegistrableDomain, ProcessThrottler::BackgroundActivityToken> m_backgroundTokensForServiceWorkerProcesses;
+    HashMap<WebCore::RegistrableDomain, std::unique_ptr<ProcessThrottler::ForegroundActivity>> m_foregroundActivitiesForServiceWorkerProcesses;
+    HashMap<WebCore::RegistrableDomain, std::unique_ptr<ProcessThrottler::BackgroundActivity>> m_backgroundActivitiesForServiceWorkerProcesses;
 #endif
 #endif
 
index 0aea5ba..ed54d4a 100644 (file)
@@ -372,7 +372,7 @@ void WebProcessProxy::shutDown()
 
     m_responsivenessTimer.invalidate();
     m_backgroundResponsivenessTimer.invalidate();
-    m_tokenForHoldingLockedFiles = nullptr;
+    m_activityForHoldingLockedFiles = nullptr;
 
     for (auto& frame : copyToVector(m_frameMap.values()))
         frame->webProcessWillShutDown();
@@ -1013,10 +1013,10 @@ void WebProcessProxy::fetchWebsiteData(PAL::SessionID sessionID, OptionSet<Websi
     ASSERT(canSendMessage());
     ASSERT_UNUSED(sessionID, sessionID == this->sessionID());
 
-    auto token = throttler().backgroundActivityToken();
+    auto activity = throttler().backgroundActivity("WebProcessProxy::fetchWebsiteData"_s);
     RELEASE_LOG_IF(isReleaseLoggingAllowed(), ProcessSuspension, "%p - WebProcessProxy is taking a background assertion because the Web process is fetching Website data", this);
 
-    connection()->sendWithAsyncReply(Messages::WebProcess::FetchWebsiteData(dataTypes), [this, protectedThis = makeRef(*this), token, completionHandler = WTFMove(completionHandler)] (auto reply) mutable {
+    connection()->sendWithAsyncReply(Messages::WebProcess::FetchWebsiteData(dataTypes), [this, protectedThis = makeRef(*this), activity = WTFMove(activity), completionHandler = WTFMove(completionHandler)] (auto reply) mutable {
 #if RELEASE_LOG_DISABLED
         UNUSED_PARAM(this);
 #endif
@@ -1030,10 +1030,10 @@ void WebProcessProxy::deleteWebsiteData(PAL::SessionID sessionID, OptionSet<Webs
     ASSERT(canSendMessage());
     ASSERT_UNUSED(sessionID, sessionID == this->sessionID());
 
-    auto token = throttler().backgroundActivityToken();
+    auto activity = throttler().backgroundActivity("WebProcessProxy::deleteWebsiteData"_s);
     RELEASE_LOG_IF(isReleaseLoggingAllowed(), ProcessSuspension, "%p - WebProcessProxy is taking a background assertion because the Web process is deleting Website data", this);
 
-    connection()->sendWithAsyncReply(Messages::WebProcess::DeleteWebsiteData(dataTypes, modifiedSince), [this, protectedThis = makeRef(*this), token, completionHandler = WTFMove(completionHandler)] () mutable {
+    connection()->sendWithAsyncReply(Messages::WebProcess::DeleteWebsiteData(dataTypes, modifiedSince), [this, protectedThis = makeRef(*this), activity = WTFMove(activity), completionHandler = WTFMove(completionHandler)] () mutable {
 #if RELEASE_LOG_DISABLED
         UNUSED_PARAM(this);
 #endif
@@ -1047,10 +1047,10 @@ void WebProcessProxy::deleteWebsiteDataForOrigins(PAL::SessionID sessionID, Opti
     ASSERT(canSendMessage());
     ASSERT_UNUSED(sessionID, sessionID == this->sessionID());
 
-    auto token = throttler().backgroundActivityToken();
+    auto activity = throttler().backgroundActivity("WebProcessProxy::deleteWebsiteDataForOrigins"_s);
     RELEASE_LOG_IF(isReleaseLoggingAllowed(), ProcessSuspension, "%p - WebProcessProxy is taking a background assertion because the Web process is deleting Website data for several origins", this);
 
-    connection()->sendWithAsyncReply(Messages::WebProcess::DeleteWebsiteDataForOrigins(dataTypes, origins), [this, protectedThis = makeRef(*this), token, completionHandler = WTFMove(completionHandler)] () mutable {
+    connection()->sendWithAsyncReply(Messages::WebProcess::DeleteWebsiteDataForOrigins(dataTypes, origins), [this, protectedThis = makeRef(*this), activity = WTFMove(activity), completionHandler = WTFMove(completionHandler)] () mutable {
 #if RELEASE_LOG_DISABLED
         UNUSED_PARAM(this);
 #endif
@@ -1292,12 +1292,12 @@ void WebProcessProxy::setIsHoldingLockedFiles(bool isHoldingLockedFiles)
 {
     if (!isHoldingLockedFiles) {
         RELEASE_LOG(ProcessSuspension, "UIProcess is releasing a background assertion because the WebContent process is no longer holding locked files");
-        m_tokenForHoldingLockedFiles = nullptr;
+        m_activityForHoldingLockedFiles = nullptr;
         return;
     }
-    if (!m_tokenForHoldingLockedFiles) {
+    if (!m_activityForHoldingLockedFiles) {
         RELEASE_LOG(ProcessSuspension, "UIProcess is taking a background assertion because the WebContent process is holding locked files");
-        m_tokenForHoldingLockedFiles = m_throttler.backgroundActivityToken();
+        m_activityForHoldingLockedFiles = m_throttler.backgroundActivity("Holding locked files"_s);
     }
 }
 
@@ -1518,21 +1518,21 @@ void WebProcessProxy::plugInDidReceiveUserInteraction(uint32_t hash)
 
 #if PLATFORM(WATCHOS)
 
-void WebProcessProxy::takeBackgroundActivityTokenForFullscreenInput()
+void WebProcessProxy::startBackgroundActivityForFullscreenInput()
 {
-    if (m_backgroundActivityTokenForFullscreenFormControls)
+    if (m_backgroundActivityForFullscreenFormControls)
         return;
 
-    m_backgroundActivityTokenForFullscreenFormControls = m_throttler.backgroundActivityToken();
+    m_backgroundActivityForFullscreenFormControls = m_throttler.backgroundActivity("Fullscreen input"_s);
     RELEASE_LOG(ProcessSuspension, "UIProcess is taking a background assertion because it is presenting fullscreen UI for form controls.");
 }
 
-void WebProcessProxy::releaseBackgroundActivityTokenForFullscreenInput()
+void WebProcessProxy::endBackgroundActivityForFullscreenInput()
 {
-    if (!m_backgroundActivityTokenForFullscreenFormControls)
+    if (!m_backgroundActivityForFullscreenFormControls)
         return;
 
-    m_backgroundActivityTokenForFullscreenFormControls = nullptr;
+    m_backgroundActivityForFullscreenFormControls = nullptr;
     RELEASE_LOG(ProcessSuspension, "UIProcess is releasing a background assertion because it has dismissed fullscreen UI for form controls.");
 }
 
index 0632b69..2a246e7 100644 (file)
@@ -246,8 +246,8 @@ public:
     bool hasCommittedAnyProvisionalLoads() const { return m_hasCommittedAnyProvisionalLoads; }
 
 #if PLATFORM(WATCHOS)
-    void takeBackgroundActivityTokenForFullscreenInput();
-    void releaseBackgroundActivityTokenForFullscreenInput();
+    void startBackgroundActivityForFullscreenInput();
+    void endBackgroundActivityForFullscreenInput();
 #endif
 
     bool isPrewarmed() const { return m_isPrewarmed; }
@@ -479,7 +479,7 @@ private:
 
     int m_numberOfTimesSuddenTerminationWasDisabled;
     ProcessThrottler m_throttler;
-    ProcessThrottler::BackgroundActivityToken m_tokenForHoldingLockedFiles;
+    std::unique_ptr<ProcessThrottler::BackgroundActivity> m_activityForHoldingLockedFiles;
 #if PLATFORM(IOS_FAMILY)
     ForegroundWebProcessToken m_foregroundToken;
     BackgroundWebProcessToken m_backgroundToken;
@@ -512,7 +512,7 @@ private:
     bool m_hasAudibleWebPage { false };
 
 #if PLATFORM(WATCHOS)
-    ProcessThrottler::BackgroundActivityToken m_backgroundActivityTokenForFullscreenFormControls;
+    std::unique_ptr<ProcessThrottler::BackgroundActivityToken> m_backgroundActivityForFullscreenFormControls;
 #endif
 
 #if PLATFORM(COCOA)
index e93895f..cb4a46e 100644 (file)
@@ -5931,7 +5931,7 @@ static BOOL allPasteboardItemOriginsMatchOrigin(UIPasteboard *pasteboard, const
         [presentingViewController presentViewController:_presentedFullScreenInputViewController.get() animated:YES completion:nil];
 
     // Presenting a fullscreen input view controller fully obscures the web view. Without taking this token, the web content process will get backgrounded.
-    _page->process().takeBackgroundActivityTokenForFullscreenInput();
+    _page->process().startBackgroundActivityForFullscreenInput();
 
     [presentingViewController.transitionCoordinator animateAlongsideTransition:nil completion:[weakWebView = WeakObjCPtr<WKWebView>(_webView), controller = _presentedFullScreenInputViewController] (id <UIViewControllerTransitionCoordinatorContext>) {
         auto strongWebView = weakWebView.get();
@@ -5967,7 +5967,7 @@ static BOOL allPasteboardItemOriginsMatchOrigin(UIPasteboard *pasteboard, const
             [self becomeFirstResponder];
     }
 
-    _page->process().releaseBackgroundActivityTokenForFullscreenInput();
+    _page->process().endBackgroundActivityForFullscreenInput();
 }
 
 - (void)focusedFormControlViewDidSubmit:(WKFocusedFormControlView *)view
index 8ea1b38..29040a4 100644 (file)
@@ -200,7 +200,7 @@ void WebPageProxy::requestFocusedElementInformation(Function<void(const FocusedE
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivity("WebPageProxy::requestFocusedElementInformation"_s));
     m_process->send(Messages::WebPage::RequestFocusedElementInformation(callbackID), m_webPageID);
 }
 
@@ -431,7 +431,7 @@ void WebPageProxy::selectWithGesture(const WebCore::IntPoint point, WebCore::Tex
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::selectWithGesture"_s));
     m_process->send(Messages::WebPage::SelectWithGesture(point, (uint32_t)granularity, gestureType, gestureState, isInteractingWithFocusedElement, callbackID), m_webPageID);
 }
 
@@ -442,7 +442,7 @@ void WebPageProxy::updateSelectionWithTouches(const WebCore::IntPoint point, uin
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::updateSelectionWithTouches"_s));
     m_process->send(Messages::WebPage::UpdateSelectionWithTouches(point, touches, baseIsStart, callbackID), m_webPageID);
 }
     
@@ -472,7 +472,7 @@ void WebPageProxy::applyAutocorrection(const String& correction, const String& o
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::applyAutocorrection"_s));
     m_process->send(Messages::WebPage::ApplyAutocorrection(correction, originalText, callbackID), m_webPageID);
 }
 
@@ -490,7 +490,7 @@ void WebPageProxy::selectTextWithGranularityAtPoint(const WebCore::IntPoint poin
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::selectTextWithGranularityAtPoint"_s));
     m_process->send(Messages::WebPage::SelectTextWithGranularityAtPoint(point, static_cast<uint32_t>(granularity), isInteractingWithFocusedElement, callbackID), m_webPageID);
 }
 
@@ -501,7 +501,7 @@ void WebPageProxy::selectPositionAtBoundaryWithDirection(const WebCore::IntPoint
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::selectPositionAtBoundaryWithDirection"_s));
     m_process->send(Messages::WebPage::SelectPositionAtBoundaryWithDirection(point, static_cast<uint32_t>(granularity), static_cast<uint32_t>(direction), isInteractingWithFocusedElement, callbackID), m_webPageID);
 }
 
@@ -512,7 +512,7 @@ void WebPageProxy::moveSelectionAtBoundaryWithDirection(WebCore::TextGranularity
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::moveSelectionAtBoundaryWithDirection"_s));
     m_process->send(Messages::WebPage::MoveSelectionAtBoundaryWithDirection(static_cast<uint32_t>(granularity), static_cast<uint32_t>(direction), callbackID), m_webPageID);
 }
     
@@ -523,7 +523,7 @@ void WebPageProxy::selectPositionAtPoint(const WebCore::IntPoint point, bool isI
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::selectPositionAtPoint"_s));
     m_process->send(Messages::WebPage::SelectPositionAtPoint(point, isInteractingWithFocusedElement, callbackID), m_webPageID);
 }
 
@@ -534,7 +534,7 @@ void WebPageProxy::beginSelectionInDirection(WebCore::SelectionDirection directi
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::beginSelectionInDirection"_s));
     m_process->send(Messages::WebPage::BeginSelectionInDirection(direction, callbackID), m_webPageID);
 }
 
@@ -545,7 +545,7 @@ void WebPageProxy::updateSelectionWithExtentPoint(const WebCore::IntPoint point,
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::updateSelectionWithExtentPoint"_s));
     m_process->send(Messages::WebPage::UpdateSelectionWithExtentPoint(point, isInteractingWithFocusedElement, callbackID), m_webPageID);
     
 }
@@ -557,7 +557,7 @@ void WebPageProxy::updateSelectionWithExtentPointAndBoundary(const WebCore::IntP
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::updateSelectionWithExtentPointAndBoundary"_s));
     m_process->send(Messages::WebPage::UpdateSelectionWithExtentPointAndBoundary(point, granularity, isInteractingWithFocusedElement, callbackID), m_webPageID);
     
 }
@@ -569,7 +569,7 @@ void WebPageProxy::requestDictationContext(WTF::Function<void (const String&, co
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::requestDictationContext"_s));
     m_process->send(Messages::WebPage::RequestDictationContext(callbackID), m_webPageID);
 }
 
@@ -590,7 +590,7 @@ void WebPageProxy::getSelectionContext(WTF::Function<void(const String&, const S
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::getSelectionContext"_s));
     m_process->send(Messages::WebPage::GetSelectionContext(callbackID), m_webPageID);
 }
 
@@ -611,7 +611,7 @@ void WebPageProxy::selectWithTwoTouches(const WebCore::IntPoint from, const WebC
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::selectWithTwoTouches"_s));
     m_process->send(Messages::WebPage::SelectWithTwoTouches(from, to, gestureType, gestureState, callbackID), m_webPageID);
 }
 
@@ -657,7 +657,7 @@ void WebPageProxy::applicationDidEnterBackground()
     // We normally delay process suspension when the app is backgrounded until the current page load completes. However,
     // we do not want to do so when the screen is locked for power reasons.
     if (isSuspendedUnderLock)
-        NavigationState::fromWebPage(*this).releaseNetworkActivityToken(NavigationState::NetworkActivityTokenReleaseReason::ScreenLocked);
+        NavigationState::fromWebPage(*this).releaseNetworkActivity(NavigationState::NetworkActivityReleaseReason::ScreenLocked);
 #endif
     m_process->send(Messages::WebPage::ApplicationDidEnterBackground(isSuspendedUnderLock), m_webPageID);
 }
@@ -716,7 +716,7 @@ void WebPageProxy::requestRectsForGranularityWithSelectionOffset(WebCore::TextGr
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::requestRectsForGranularityWithSelectionOffset"_s));
     m_process->send(Messages::WebPage::GetRectsForGranularityWithSelectionOffset(static_cast<uint32_t>(granularity), offset, callbackID), m_webPageID);
 }
 
@@ -727,7 +727,7 @@ void WebPageProxy::requestRectsAtSelectionOffsetWithText(int32_t offset, const S
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::requestRectsAtSelectionOffsetWithText"_s));
     m_process->send(Messages::WebPage::GetRectsAtSelectionOffsetWithText(offset, text, callbackID), m_webPageID);
 }
 
@@ -753,7 +753,7 @@ void WebPageProxy::moveSelectionByOffset(int32_t offset, WTF::Function<void (Cal
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::moveSelectionByOffset"_s));
     m_process->send(Messages::WebPage::MoveSelectionByOffset(offset, callbackID), m_webPageID);
 }
 
@@ -1017,7 +1017,7 @@ void WebPageProxy::focusNextFocusedElement(bool isForward, WTF::Function<void(Ca
         return;
     }
     
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::focusNextFocusedElement"_s));
     process().send(Messages::WebPage::FocusNextFocusedElement(isForward, callbackID), m_webPageID);
 }
 
@@ -1096,7 +1096,7 @@ uint32_t WebPageProxy::computePagesForPrintingAndDrawToPDF(FrameIdentifier frame
     }
 
     uint32_t pageCount = 0;
-    auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivity("WebPageProxy::computePagesForPrintingAndDrawToPDF"_s));
     using Message = Messages::WebPage::ComputePagesForPrintingAndDrawToPDF;
     process().sendSync(Message(frameID, printInfo, callbackID), Message::Reply(pageCount), m_webPageID, Seconds::infinity());
     return pageCount;
index 1169e25..0977bb4 100644 (file)
@@ -222,7 +222,7 @@ void WebPageProxy::attributedSubstringForCharacterRangeAsync(const EditingRange&
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::attributedSubstringForCharacterRangeAsync"_s));
 
     process().send(Messages::WebPage::AttributedSubstringForCharacterRangeAsync(range, callbackID), m_webPageID);
 }
@@ -248,7 +248,7 @@ void WebPageProxy::fontAtSelection(Function<void(const FontInfo&, double, bool,
         return;
     }
 
-    auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivityToken());
+    auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivity("WebPageProxy::fontAtSelection"_s));
     process().send(Messages::WebPage::FontAtSelection(callbackID), m_webPageID);
 }