Title: [259540] trunk
Revision
259540
Author
[email protected]
Date
2020-04-04 17:03:45 -0700 (Sat, 04 Apr 2020)

Log Message

[iOS] Simplify ProcessAssertion class in preparation for switch to RunningBoard
https://bugs.webkit.org/show_bug.cgi?id=209984
<rdar://problem/61273941>

Reviewed by Darin Adler.

Source/WebKit:

Simplify ProcessAssertion class in preparation for switch to RunningBoard. There
is a slight mismatch between the way BKS and RunningBoard process assertion API.
This refactoring makes it so that we can use the same ProcessAssertion class in
WebKit to work with either BKS or RunningBoard. Support for RunningBoard will
come later.

In particular, the following changes were made:
- Replace AssertionState & AssertionReason enums with a single ProcessAssertionType
  one since RunningBoard does not have 2 separate concepts.
- Drop ProcessAssertion::setState() since it is not possible to change the flags
  on an existing RunningBoard assertion. Instead, we are expected to create a
  brand new process assertion of the expected type.

* NetworkProcess/Downloads/DownloadMap.cpp:
(WebKit::DownloadMap::add):
* Platform/IPC/cocoa/ConnectionCocoa.mm:
(IPC::ConnectionTerminationWatchdog::ConnectionTerminationWatchdog):
* UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h:
* UIProcess/API/Cocoa/WKWebViewTesting.mm:
(-[WKWebView _setAssertionTypeForTesting:]):
(-[WKWebView _setAssertionStateForTesting:]): Deleted.
* UIProcess/Downloads/DownloadProxyMap.cpp:
(WebKit::DownloadProxyMap::createDownloadProxy):
* UIProcess/GPU/GPUProcessProxy.h:
* UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::sendProcessDidResume):
(WebKit::NetworkProcessProxy::takeUploadAssertion):
(WebKit::NetworkProcessProxy::didSetAssertionState): Deleted.
* UIProcess/Network/NetworkProcessProxy.h:
* UIProcess/ProcessAssertion.cpp:
(WebKit::ProcessAssertion::ProcessAssertion):
(WebKit::ProcessAssertion::setState): Deleted.
* UIProcess/ProcessAssertion.h:
(WebKit::ProcessAssertion::type const):
(WebKit::ProcessAssertion::state const): Deleted.
* UIProcess/ProcessThrottler.cpp:
(WebKit::ProcessThrottler::expectedAssertionType):
(WebKit::ProcessThrottler::updateAssertionTypeNow):
(WebKit::ProcessThrottler::setAssertionType):
(WebKit::ProcessThrottler::updateAssertionIfNeeded):
(WebKit::ProcessThrottler::didConnectToProcess):
(WebKit::ProcessThrottler::prepareToSuspendTimeoutTimerFired):
(WebKit::ProcessThrottler::processReadyToSuspend):
(WebKit::ProcessThrottler::sendPrepareToSuspendIPC):
(WebKit::ProcessThrottler::expectedAssertionState): Deleted.
(WebKit::ProcessThrottler::updateAssertionStateNow): Deleted.
(WebKit::ProcessThrottler::setAssertionState): Deleted.
* UIProcess/ProcessThrottler.h:
* UIProcess/ProcessThrottlerClient.h:
(WebKit::ProcessThrottlerClient::didSetAssertionType):
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::setWebProcessHasUploads):
(WebKit::WebProcessPool::setWebProcessIsPlayingAudibleMedia):
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::didSetAssertionType):
(WebKit::WebProcessProxy::didSetAssertionState): Deleted.
* UIProcess/WebProcessProxy.h:
(WebKit::WebProcessProxy::setAssertionTypeForTesting):
(WebKit::WebProcessProxy::setAssertionStateForTesting): Deleted.
* UIProcess/ios/ProcessAssertionIOS.mm:
(WebKit::flagsForAssertionType):
(WebKit::toBKSProcessAssertionReason):
(WebKit::ProcessAssertion::ProcessAssertion):
(WebKit::ProcessAndUIAssertion::updateRunInBackgroundCount):
(WebKit::ProcessAndUIAssertion::ProcessAndUIAssertion):
(WebKit::flagsForState): Deleted.
(WebKit::reasonForState): Deleted.
(WebKit::ProcessAssertion::setState): Deleted.
(WebKit::ProcessAndUIAssertion::setState): Deleted.

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (259539 => 259540)


--- trunk/Source/WebKit/ChangeLog	2020-04-04 23:44:55 UTC (rev 259539)
+++ trunk/Source/WebKit/ChangeLog	2020-04-05 00:03:45 UTC (rev 259540)
@@ -1,3 +1,81 @@
+2020-04-04  Chris Dumez  <[email protected]>
+
+        [iOS] Simplify ProcessAssertion class in preparation for switch to RunningBoard
+        https://bugs.webkit.org/show_bug.cgi?id=209984
+        <rdar://problem/61273941>
+
+        Reviewed by Darin Adler.
+
+        Simplify ProcessAssertion class in preparation for switch to RunningBoard. There
+        is a slight mismatch between the way BKS and RunningBoard process assertion API.
+        This refactoring makes it so that we can use the same ProcessAssertion class in
+        WebKit to work with either BKS or RunningBoard. Support for RunningBoard will
+        come later.
+
+        In particular, the following changes were made:
+        - Replace AssertionState & AssertionReason enums with a single ProcessAssertionType
+          one since RunningBoard does not have 2 separate concepts.
+        - Drop ProcessAssertion::setState() since it is not possible to change the flags
+          on an existing RunningBoard assertion. Instead, we are expected to create a
+          brand new process assertion of the expected type.
+
+        * NetworkProcess/Downloads/DownloadMap.cpp:
+        (WebKit::DownloadMap::add):
+        * Platform/IPC/cocoa/ConnectionCocoa.mm:
+        (IPC::ConnectionTerminationWatchdog::ConnectionTerminationWatchdog):
+        * UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h:
+        * UIProcess/API/Cocoa/WKWebViewTesting.mm:
+        (-[WKWebView _setAssertionTypeForTesting:]):
+        (-[WKWebView _setAssertionStateForTesting:]): Deleted.
+        * UIProcess/Downloads/DownloadProxyMap.cpp:
+        (WebKit::DownloadProxyMap::createDownloadProxy):
+        * UIProcess/GPU/GPUProcessProxy.h:
+        * UIProcess/Network/NetworkProcessProxy.cpp:
+        (WebKit::NetworkProcessProxy::sendProcessDidResume):
+        (WebKit::NetworkProcessProxy::takeUploadAssertion):
+        (WebKit::NetworkProcessProxy::didSetAssertionState): Deleted.
+        * UIProcess/Network/NetworkProcessProxy.h:
+        * UIProcess/ProcessAssertion.cpp:
+        (WebKit::ProcessAssertion::ProcessAssertion):
+        (WebKit::ProcessAssertion::setState): Deleted.
+        * UIProcess/ProcessAssertion.h:
+        (WebKit::ProcessAssertion::type const):
+        (WebKit::ProcessAssertion::state const): Deleted.
+        * UIProcess/ProcessThrottler.cpp:
+        (WebKit::ProcessThrottler::expectedAssertionType):
+        (WebKit::ProcessThrottler::updateAssertionTypeNow):
+        (WebKit::ProcessThrottler::setAssertionType):
+        (WebKit::ProcessThrottler::updateAssertionIfNeeded):
+        (WebKit::ProcessThrottler::didConnectToProcess):
+        (WebKit::ProcessThrottler::prepareToSuspendTimeoutTimerFired):
+        (WebKit::ProcessThrottler::processReadyToSuspend):
+        (WebKit::ProcessThrottler::sendPrepareToSuspendIPC):
+        (WebKit::ProcessThrottler::expectedAssertionState): Deleted.
+        (WebKit::ProcessThrottler::updateAssertionStateNow): Deleted.
+        (WebKit::ProcessThrottler::setAssertionState): Deleted.
+        * UIProcess/ProcessThrottler.h:
+        * UIProcess/ProcessThrottlerClient.h:
+        (WebKit::ProcessThrottlerClient::didSetAssertionType):
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::setWebProcessHasUploads):
+        (WebKit::WebProcessPool::setWebProcessIsPlayingAudibleMedia):
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::didSetAssertionType):
+        (WebKit::WebProcessProxy::didSetAssertionState): Deleted.
+        * UIProcess/WebProcessProxy.h:
+        (WebKit::WebProcessProxy::setAssertionTypeForTesting):
+        (WebKit::WebProcessProxy::setAssertionStateForTesting): Deleted.
+        * UIProcess/ios/ProcessAssertionIOS.mm:
+        (WebKit::flagsForAssertionType):
+        (WebKit::toBKSProcessAssertionReason):
+        (WebKit::ProcessAssertion::ProcessAssertion):
+        (WebKit::ProcessAndUIAssertion::updateRunInBackgroundCount):
+        (WebKit::ProcessAndUIAssertion::ProcessAndUIAssertion):
+        (WebKit::flagsForState): Deleted.
+        (WebKit::reasonForState): Deleted.
+        (WebKit::ProcessAssertion::setState): Deleted.
+        (WebKit::ProcessAndUIAssertion::setState): Deleted.
+
 2020-04-04  David Kilzer  <[email protected]>
 
         [GPUP] Remove unnecessary RemoteCDMInstanceSessionIdentifier argument from RemoteCDMFactory::addSession()

Modified: trunk/Source/WebKit/NetworkProcess/Downloads/DownloadMap.cpp (259539 => 259540)


--- trunk/Source/WebKit/NetworkProcess/Downloads/DownloadMap.cpp	2020-04-04 23:44:55 UTC (rev 259539)
+++ trunk/Source/WebKit/NetworkProcess/Downloads/DownloadMap.cpp	2020-04-05 00:03:45 UTC (rev 259540)
@@ -61,7 +61,7 @@
     auto result = m_downloads.add(downloadID, WTFMove(download));
     if (m_downloads.size() == 1) {
         ASSERT(!m_downloadAssertion);
-        m_downloadAssertion = makeUnique<ProcessAssertion>(getpid(), "WebKit downloads"_s, AssertionState::UnboundedNetworking);
+        m_downloadAssertion = makeUnique<ProcessAssertion>(getpid(), "WebKit downloads"_s, ProcessAssertionType::UnboundedNetworking);
         RELEASE_LOG(ProcessSuspension, "Took 'WebKit downloads' assertion in NetworkProcess");
     }
 

Modified: trunk/Source/WebKit/Platform/IPC/cocoa/ConnectionCocoa.mm (259539 => 259540)


--- trunk/Source/WebKit/Platform/IPC/cocoa/ConnectionCocoa.mm	2020-04-04 23:44:55 UTC (rev 259539)
+++ trunk/Source/WebKit/Platform/IPC/cocoa/ConnectionCocoa.mm	2020-04-05 00:03:45 UTC (rev 259540)
@@ -86,7 +86,7 @@
         : m_xpcConnection(xpcConnection)
         , m_watchdogTimer(RunLoop::main(), this, &ConnectionTerminationWatchdog::watchdogTimerFired)
 #if PLATFORM(IOS_FAMILY)
-        , m_assertion(makeUnique<WebKit::ProcessAndUIAssertion>(xpc_connection_get_pid(m_xpcConnection.get()), "ConnectionTerminationWatchdog"_s, WebKit::AssertionState::Background))
+        , m_assertion(makeUnique<WebKit::ProcessAndUIAssertion>(xpc_connection_get_pid(m_xpcConnection.get()), "ConnectionTerminationWatchdog"_s, WebKit::ProcessAssertionType::Background))
 #endif
     {
         m_watchdogTimer.startOneShot(interval);

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h (259539 => 259540)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h	2020-04-04 23:44:55 UTC (rev 259539)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h	2020-04-05 00:03:45 UTC (rev 259540)
@@ -57,7 +57,7 @@
 - (void)_processDidResumeForTesting;
 @property (nonatomic, readonly) BOOL _hasServiceWorkerBackgroundActivityForTesting;
 @property (nonatomic, readonly) BOOL _hasServiceWorkerForegroundActivityForTesting;
-- (void)_setAssertionStateForTesting:(int)state;
+- (void)_setAssertionTypeForTesting:(int)type;
 
 - (void)_doAfterProcessingAllPendingMouseEvents:(dispatch_block_t)action;
 

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm (259539 => 259540)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm	2020-04-04 23:44:55 UTC (rev 259539)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm	2020-04-05 00:03:45 UTC (rev 259540)
@@ -170,12 +170,12 @@
         _page->process().sendProcessDidResume();
 }
 
-- (void)_setAssertionStateForTesting:(int)value
+- (void)_setAssertionTypeForTesting:(int)value
 {
     if (!_page)
         return;
 
-    _page->process().setAssertionStateForTesting(static_cast<WebKit::AssertionState>(value));
+    _page->process().setAssertionTypeForTesting(static_cast<WebKit::ProcessAssertionType>(value));
 }
 
 - (BOOL)_hasServiceWorkerBackgroundActivityForTesting

Modified: trunk/Source/WebKit/UIProcess/Downloads/DownloadProxyMap.cpp (259539 => 259540)


--- trunk/Source/WebKit/UIProcess/Downloads/DownloadProxyMap.cpp	2020-04-04 23:44:55 UTC (rev 259539)
+++ trunk/Source/WebKit/UIProcess/Downloads/DownloadProxyMap.cpp	2020-04-05 00:03:45 UTC (rev 259540)
@@ -89,11 +89,11 @@
 
     if (m_downloads.size() == 1 && m_shouldTakeAssertion) {
         ASSERT(!m_downloadUIAssertion);
-        m_downloadUIAssertion = makeUnique<ProcessAssertion>(getCurrentProcessID(), "WebKit downloads"_s, AssertionState::UnboundedNetworking);
+        m_downloadUIAssertion = makeUnique<ProcessAssertion>(getCurrentProcessID(), "WebKit downloads"_s, ProcessAssertionType::UnboundedNetworking);
 
         ASSERT(!m_downloadNetworkingAssertion);
         RELEASE_ASSERT(m_process);
-        m_downloadNetworkingAssertion = makeUnique<ProcessAssertion>(m_process->processIdentifier(), "WebKit downloads"_s, AssertionState::UnboundedNetworking);
+        m_downloadNetworkingAssertion = makeUnique<ProcessAssertion>(m_process->processIdentifier(), "WebKit downloads"_s, ProcessAssertionType::UnboundedNetworking);
 
         RELEASE_LOG(ProcessSuspension, "UIProcess took 'WebKit downloads' assertions for UIProcess and NetworkProcess");
     }

Modified: trunk/Source/WebKit/UIProcess/GPU/GPUProcessProxy.h (259539 => 259540)


--- trunk/Source/WebKit/UIProcess/GPU/GPUProcessProxy.h	2020-04-04 23:44:55 UTC (rev 259539)
+++ trunk/Source/WebKit/UIProcess/GPU/GPUProcessProxy.h	2020-04-05 00:03:45 UTC (rev 259540)
@@ -92,7 +92,6 @@
 
     // ProcessThrottlerClient
     void sendPrepareToSuspend(IsSuspensionImminent, CompletionHandler<void()>&&) final { }
-    void didSetAssertionState(AssertionState) final { }
 
     // ProcessLauncher::Client
     void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) override;

Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp (259539 => 259540)


--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp	2020-04-04 23:44:55 UTC (rev 259539)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp	2020-04-05 00:03:45 UTC (rev 259540)
@@ -1197,10 +1197,6 @@
     if (canSendMessage())
         send(Messages::NetworkProcess::ProcessDidResume(), 0);
 }
-
-void NetworkProcessProxy::didSetAssertionState(AssertionState)
-{
-}
     
 void NetworkProcessProxy::setIsHoldingLockedFiles(bool isHoldingLockedFiles)
 {
@@ -1404,7 +1400,7 @@
 void NetworkProcessProxy::takeUploadAssertion()
 {
     ASSERT(!m_uploadAssertion);
-    m_uploadAssertion = makeUnique<ProcessAssertion>(processIdentifier(), "WebKit uploads"_s, AssertionState::UnboundedNetworking);
+    m_uploadAssertion = makeUnique<ProcessAssertion>(processIdentifier(), "WebKit uploads"_s, ProcessAssertionType::UnboundedNetworking);
 }
 
 void NetworkProcessProxy::clearUploadAssertion()

Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h (259539 => 259540)


--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2020-04-04 23:44:55 UTC (rev 259539)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2020-04-05 00:03:45 UTC (rev 259540)
@@ -239,7 +239,6 @@
 
     // ProcessThrottlerClient
     void sendPrepareToSuspend(IsSuspensionImminent, CompletionHandler<void()>&&) final;
-    void didSetAssertionState(AssertionState) final;
 
     // IPC::Connection::Client
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;

Modified: trunk/Source/WebKit/UIProcess/ProcessAssertion.cpp (259539 => 259540)


--- trunk/Source/WebKit/UIProcess/ProcessAssertion.cpp	2020-04-04 23:44:55 UTC (rev 259539)
+++ trunk/Source/WebKit/UIProcess/ProcessAssertion.cpp	2020-04-05 00:03:45 UTC (rev 259540)
@@ -32,23 +32,13 @@
 
 namespace WebKit {
 
-ProcessAssertion::ProcessAssertion(ProcessID, const String&, AssertionState assertionState)
-    : m_assertionState(assertionState)
+ProcessAssertion::ProcessAssertion(ProcessID, const String&, ProcessAssertionType assertionType)
+    : m_assertionType(assertionType)
 {
 }
 
-ProcessAssertion::ProcessAssertion(pid_t pid, const String& name, AssertionState assertionState, AssertionReason)
-    : m_assertionState(assertionState)
-{
-}
-
 ProcessAssertion::~ProcessAssertion() = default;
 
-void ProcessAssertion::setState(AssertionState assertionState)
-{
-    m_assertionState = assertionState;
-}
-
 } // namespace WebKit
 
 #endif // !PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WebKit/UIProcess/ProcessAssertion.h (259539 => 259540)


--- trunk/Source/WebKit/UIProcess/ProcessAssertion.h	2020-04-04 23:44:55 UTC (rev 259539)
+++ trunk/Source/WebKit/UIProcess/ProcessAssertion.h	2020-04-05 00:03:45 UTC (rev 259540)
@@ -40,18 +40,12 @@
 #endif
 
 namespace WebKit {
-    
-enum class AssertionState {
+
+enum class ProcessAssertionType {
     Suspended,
     Background,
     UnboundedNetworking,
     Foreground,
-};
-
-enum class AssertionReason {
-    Extension,
-    FinishTask,
-    FinishTaskUnbounded,
     MediaPlayback,
 };
 
@@ -64,15 +58,13 @@
         virtual void uiAssertionWillExpireImminently() = 0;
     };
 
-    ProcessAssertion(ProcessID, const String& reason, AssertionState);
-    ProcessAssertion(ProcessID, const String& reason, AssertionState, AssertionReason);
+    ProcessAssertion(ProcessID, const String& reason, ProcessAssertionType);
     virtual ~ProcessAssertion();
 
     void setClient(Client& client) { m_client = &client; }
     Client* client() { return m_client; }
 
-    AssertionState state() const { return m_assertionState; }
-    virtual void setState(AssertionState);
+    ProcessAssertionType type() const { return m_assertionType; }
 
 #if PLATFORM(IOS_FAMILY)
 protected:
@@ -87,7 +79,7 @@
     RetainPtr<BKSProcessAssertion> m_assertion;
     Validity m_validity { Validity::Unset };
 #endif
-    AssertionState m_assertionState;
+    const ProcessAssertionType m_assertionType;
     Client* m_client { nullptr };
 };
 
@@ -95,10 +87,9 @@
 
 class ProcessAndUIAssertion final : public ProcessAssertion {
 public:
-    ProcessAndUIAssertion(ProcessID, const String& reason, AssertionState);
+    ProcessAndUIAssertion(ProcessID, const String& reason, ProcessAssertionType);
     ~ProcessAndUIAssertion();
 
-    void setState(AssertionState) final;
     void uiAssertionWillExpireImminently();
 
 private:

Modified: trunk/Source/WebKit/UIProcess/ProcessThrottler.cpp (259539 => 259540)


--- trunk/Source/WebKit/UIProcess/ProcessThrottler.cpp	2020-04-04 23:44:55 UTC (rev 259539)
+++ trunk/Source/WebKit/UIProcess/ProcessThrottler.cpp	2020-04-05 00:03:45 UTC (rev 259540)
@@ -86,29 +86,31 @@
     PROCESSTHROTTLER_RELEASE_LOG("invalidateAllActivities: END");
 }
     
-AssertionState ProcessThrottler::expectedAssertionState()
+ProcessAssertionType ProcessThrottler::expectedAssertionType()
 {
     if (!m_foregroundActivities.isEmpty())
-        return AssertionState::Foreground;
+        return ProcessAssertionType::Foreground;
     if (!m_backgroundActivities.isEmpty())
-        return AssertionState::Background;
-    return AssertionState::Suspended;
+        return ProcessAssertionType::Background;
+    return ProcessAssertionType::Suspended;
 }
     
-void ProcessThrottler::updateAssertionStateNow()
+void ProcessThrottler::updateAssertionTypeNow()
 {
-    setAssertionState(expectedAssertionState());
+    setAssertionType(expectedAssertionType());
 }
 
-void ProcessThrottler::setAssertionState(AssertionState newState)
+void ProcessThrottler::setAssertionType(ProcessAssertionType newType)
 {
-    RELEASE_ASSERT(m_assertion);
-    if (m_assertion->state() == newState)
+    if (m_assertion && m_assertion->type() == newType)
         return;
 
-    PROCESSTHROTTLER_RELEASE_LOG("setAssertionState: Updating process assertion state to %u (foregroundActivities: %u, backgroundActivities: %u)", newState, m_foregroundActivities.size(), m_backgroundActivities.size());
-    m_assertion->setState(newState);
-    m_process.didSetAssertionState(newState);
+    PROCESSTHROTTLER_RELEASE_LOG("setAssertionType: Updating process assertion type to %u (foregroundActivities: %u, backgroundActivities: %u)", newType, m_foregroundActivities.size(), m_backgroundActivities.size());
+    if (m_shouldTakeUIBackgroundAssertion)
+        m_assertion = makeUnique<ProcessAndUIAssertion>(m_processIdentifier, "Web content visibility"_s, newType);
+    else
+        m_assertion = makeUnique<ProcessAssertion>(m_processIdentifier, "Web content visibility"_s, newType);
+    m_process.didSetAssertionType(newType);
 }
     
 void ProcessThrottler::updateAssertionIfNeeded()
@@ -117,8 +119,8 @@
         return;
 
     if (shouldBeRunnable()) {
-        if (m_assertion->state() == AssertionState::Suspended || m_pendingRequestToSuspendID) {
-            if (m_assertion->state() == AssertionState::Suspended)
+        if (m_assertion->type() == ProcessAssertionType::Suspended || m_pendingRequestToSuspendID) {
+            if (m_assertion->type() == ProcessAssertionType::Suspended)
                 PROCESSTHROTTLER_RELEASE_LOG("updateAssertionIfNeeded: sending ProcessDidResume IPC because the process was suspended");
             else
                 PROCESSTHROTTLER_RELEASE_LOG("updateAssertionIfNeeded: sending ProcessDidResume IPC because the WebProcess is still processing request to suspend: %" PRIu64, *m_pendingRequestToSuspendID);
@@ -129,7 +131,7 @@
         // If the process is currently runnable but will be suspended then first give it a chance to complete what it was doing
         // and clean up - move it to the background and send it a message to notify. Schedule a timeout so it can't stay running
         // in the background for too long.
-        if (m_assertion->state() != AssertionState::Suspended) {
+        if (m_assertion->type() != ProcessAssertionType::Suspended) {
             m_prepareToSuspendTimeoutTimer.startOneShot(processSuspensionTimeout);
             sendPrepareToSuspendIPC(IsSuspensionImminent::No);
             return;
@@ -136,7 +138,7 @@
         }
     }
 
-    updateAssertionStateNow();
+    updateAssertionTypeNow();
 }
 
 void ProcessThrottler::didConnectToProcess(ProcessID pid)
@@ -144,13 +146,9 @@
     PROCESSTHROTTLER_RELEASE_LOG_WITH_PID("didConnectToProcess:", pid);
     RELEASE_ASSERT(!m_assertion);
 
-    if (m_shouldTakeUIBackgroundAssertion)
-        m_assertion = makeUnique<ProcessAndUIAssertion>(pid, "Web content visibility"_s, expectedAssertionState());
-    else
-        m_assertion = makeUnique<ProcessAssertion>(pid, "Web content visibility"_s, expectedAssertionState());
-
     m_processIdentifier = pid;
-    m_process.didSetAssertionState(expectedAssertionState());
+    setAssertionType(expectedAssertionType());
+    RELEASE_ASSERT(m_assertion);
     m_assertion->setClient(*this);
 }
     
@@ -158,7 +156,7 @@
 {
     PROCESSTHROTTLER_RELEASE_LOG("prepareToSuspendTimeoutTimerFired: Updating process assertion to allow suspension");
     RELEASE_ASSERT(m_pendingRequestToSuspendID);
-    updateAssertionStateNow();
+    updateAssertionTypeNow();
 }
     
 void ProcessThrottler::processReadyToSuspend()
@@ -168,8 +166,8 @@
     RELEASE_ASSERT(m_pendingRequestToSuspendID);
     clearPendingRequestToSuspend();
 
-    if (m_assertion->state() != AssertionState::Suspended)
-        updateAssertionStateNow();
+    if (m_assertion->type() != ProcessAssertionType::Suspended)
+        updateAssertionTypeNow();
 }
 
 void ProcessThrottler::clearPendingRequestToSuspend()
@@ -194,7 +192,7 @@
         });
     }
 
-    setAssertionState(isSuspensionImminent == IsSuspensionImminent::Yes ? AssertionState::Suspended : AssertionState::Background);
+    setAssertionType(isSuspensionImminent == IsSuspensionImminent::Yes ? ProcessAssertionType::Suspended : ProcessAssertionType::Background);
 }
 
 void ProcessThrottler::uiAssertionWillExpireImminently()

Modified: trunk/Source/WebKit/UIProcess/ProcessThrottler.h (259539 => 259540)


--- trunk/Source/WebKit/UIProcess/ProcessThrottler.h	2020-04-04 23:44:55 UTC (rev 259539)
+++ trunk/Source/WebKit/UIProcess/ProcessThrottler.h	2020-04-05 00:03:45 UTC (rev 259540)
@@ -107,10 +107,10 @@
     bool shouldBeRunnable() const { return m_foregroundActivities.size() || m_backgroundActivities.size(); }
 
 private:
-    AssertionState expectedAssertionState();
+    ProcessAssertionType expectedAssertionType();
     void updateAssertionIfNeeded();
-    void updateAssertionStateNow();
-    void setAssertionState(AssertionState);
+    void updateAssertionTypeNow();
+    void setAssertionType(ProcessAssertionType);
     void prepareToSuspendTimeoutTimerFired();
     void sendPrepareToSuspendIPC(IsSuspensionImminent);
     void processReadyToSuspend();

Modified: trunk/Source/WebKit/UIProcess/ProcessThrottlerClient.h (259539 => 259540)


--- trunk/Source/WebKit/UIProcess/ProcessThrottlerClient.h	2020-04-04 23:44:55 UTC (rev 259539)
+++ trunk/Source/WebKit/UIProcess/ProcessThrottlerClient.h	2020-04-05 00:03:45 UTC (rev 259540)
@@ -38,7 +38,7 @@
 
     virtual void sendPrepareToSuspend(IsSuspensionImminent, CompletionHandler<void()>&&) = 0;
     virtual void sendProcessDidResume() = 0;
-    virtual void didSetAssertionState(AssertionState) = 0;
+    virtual void didSetAssertionType(ProcessAssertionType) { };
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (259539 => 259540)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2020-04-04 23:44:55 UTC (rev 259539)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2020-04-05 00:03:45 UTC (rev 259540)
@@ -2354,12 +2354,12 @@
         ensureNetworkProcess().takeUploadAssertion();
         
         ASSERT(!m_uiProcessUploadAssertion);
-        m_uiProcessUploadAssertion = makeUnique<ProcessAssertion>(getCurrentProcessID(), "WebKit uploads"_s, AssertionState::UnboundedNetworking);
+        m_uiProcessUploadAssertion = makeUnique<ProcessAssertion>(getCurrentProcessID(), "WebKit uploads"_s, ProcessAssertionType::UnboundedNetworking);
     }
     
     auto result = m_processesWithUploads.add(processID, nullptr);
     ASSERT(result.isNewEntry);
-    result.iterator->value = makeUnique<ProcessAssertion>(process->processIdentifier(), "WebKit uploads"_s, AssertionState::UnboundedNetworking);
+    result.iterator->value = makeUnique<ProcessAssertion>(process->processIdentifier(), "WebKit uploads"_s, ProcessAssertionType::UnboundedNetworking);
 }
 
 void WebProcessPool::clearWebProcessHasUploads(ProcessIdentifier processID)
@@ -2396,16 +2396,16 @@
         WEBPROCESSPOOL_RELEASE_LOG(ProcessSuspension, "setWebProcessIsPlayingAudibleMedia: The number of processes playing audible media is now one. Taking UI process assertion.");
 
         ASSERT(!m_uiProcessMediaPlaybackAssertion);
-        m_uiProcessMediaPlaybackAssertion = makeUnique<ProcessAssertion>(getCurrentProcessID(), "WebKit Media Playback"_s, AssertionState::Foreground, AssertionReason::MediaPlayback);
+        m_uiProcessMediaPlaybackAssertion = makeUnique<ProcessAssertion>(getCurrentProcessID(), "WebKit Media Playback"_s, ProcessAssertionType::MediaPlayback);
 #if ENABLE(GPU_PROCESS)
         if (GPUProcessProxy::singletonIfCreated())
-            m_gpuProcessMediaPlaybackAssertion = makeUnique<ProcessAssertion>(GPUProcessProxy::singleton().processIdentifier(), "WebKit Media Playback"_s, AssertionState::Foreground, AssertionReason::MediaPlayback);
+            m_gpuProcessMediaPlaybackAssertion = makeUnique<ProcessAssertion>(GPUProcessProxy::singleton().processIdentifier(), "WebKit Media Playback"_s, ProcessAssertionType::MediaPlayback);
 #endif
     }
 
     auto result = m_processesPlayingAudibleMedia.add(processID, nullptr);
     ASSERT(result.isNewEntry);
-    result.iterator->value = makeUnique<ProcessAssertion>(process->processIdentifier(), "WebKit Media Playback"_s, AssertionState::Foreground, AssertionReason::MediaPlayback);
+    result.iterator->value = makeUnique<ProcessAssertion>(process->processIdentifier(), "WebKit Media Playback"_s, ProcessAssertionType::MediaPlayback);
 }
 
 void WebProcessPool::clearWebProcessIsPlayingAudibleMedia(WebCore::ProcessIdentifier processID)

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp (259539 => 259540)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2020-04-04 23:44:55 UTC (rev 259539)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2020-04-05 00:03:45 UTC (rev 259540)
@@ -1325,12 +1325,12 @@
         send(Messages::WebProcess::ProcessDidResume(), 0);
 }
 
-void WebProcessProxy::didSetAssertionState(AssertionState state)
+void WebProcessProxy::didSetAssertionType(ProcessAssertionType type)
 {
-    RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertionState(%u)", this, state);
+    RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertionType(%u)", this, type);
 
     if (isStandaloneServiceWorkerProcess()) {
-        RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertionState() release all assertions for network process because this is a service worker process without page", this);
+        RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertionType() release all assertions for network process because this is a service worker process without page", this);
         m_foregroundToken = nullptr;
         m_backgroundToken = nullptr;
         return;
@@ -1338,9 +1338,9 @@
 
     ASSERT(!m_backgroundToken || !m_foregroundToken);
 
-    switch (state) {
-    case AssertionState::Suspended:
-        RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertionState(Suspended) release all assertions for network process", this);
+    switch (type) {
+    case ProcessAssertionType::Suspended:
+        RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertionType(Suspended) release all assertions for network process", this);
         m_foregroundToken = nullptr;
         m_backgroundToken = nullptr;
 #if PLATFORM(IOS_FAMILY)
@@ -1349,14 +1349,14 @@
 #endif
         break;
 
-    case AssertionState::Background:
-        RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertionState(Background) taking background assertion for network process", this);
+    case ProcessAssertionType::Background:
+        RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertionType(Background) taking background assertion for network process", this);
         m_backgroundToken = processPool().backgroundWebProcessToken();
         m_foregroundToken = nullptr;
         break;
     
-    case AssertionState::Foreground:
-        RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertionState(Foreground) taking foreground assertion for network process", this);
+    case ProcessAssertionType::Foreground:
+        RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertionType(Foreground) taking foreground assertion for network process", this);
         m_foregroundToken = processPool().foregroundWebProcessToken();
         m_backgroundToken = nullptr;
 #if PLATFORM(IOS_FAMILY)
@@ -1365,7 +1365,8 @@
 #endif
         break;
     
-    case AssertionState::UnboundedNetworking:
+    case ProcessAssertionType::MediaPlayback:
+    case ProcessAssertionType::UnboundedNetworking:
         ASSERT_NOT_REACHED();
     }
 

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.h (259539 => 259540)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.h	2020-04-04 23:44:55 UTC (rev 259539)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.h	2020-04-05 00:03:45 UTC (rev 259540)
@@ -313,7 +313,7 @@
     // ProcessThrottlerClient
     void sendPrepareToSuspend(IsSuspensionImminent, CompletionHandler<void()>&&) final;
     void sendProcessDidResume() final;
-    void didSetAssertionState(AssertionState) final;
+    void didSetAssertionType(ProcessAssertionType) final;
 
 #if PLATFORM(COCOA)
     enum SandboxExtensionType : uint32_t {
@@ -360,7 +360,7 @@
     bool hasServiceWorkerForegroundActivityForTesting() const;
     bool hasServiceWorkerBackgroundActivityForTesting() const;
 #endif
-    void setAssertionStateForTesting(AssertionState state) { didSetAssertionState(state); }
+    void setAssertionTypeForTesting(ProcessAssertionType type) { didSetAssertionType(type); }
 
 #if PLATFORM(COCOA) && ENABLE(MEDIA_STREAM)
     UserMediaCaptureManagerProxy* userMediaCaptureManagerProxy() { return m_userMediaCaptureManagerProxy.get(); }

Modified: trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm (259539 => 259540)


--- trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm	2020-04-04 23:44:55 UTC (rev 259539)
+++ trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm	2020-04-05 00:03:45 UTC (rev 259540)
@@ -271,53 +271,37 @@
 const BKSProcessAssertionFlags backgroundTabFlags = (BKSProcessAssertionPreventTaskSuspend);
 const BKSProcessAssertionFlags foregroundTabFlags = (BKSProcessAssertionPreventTaskSuspend | BKSProcessAssertionWantsForegroundResourcePriority | BKSProcessAssertionPreventTaskThrottleDown);
 
-static BKSProcessAssertionFlags flagsForState(AssertionState assertionState)
+static BKSProcessAssertionFlags flagsForAssertionType(ProcessAssertionType assertionType)
 {
-    switch (assertionState) {
-    case AssertionState::Suspended:
+    switch (assertionType) {
+    case ProcessAssertionType::Suspended:
         return suspendedTabFlags;
-    case AssertionState::Background:
-    case AssertionState::UnboundedNetworking:
+    case ProcessAssertionType::Background:
+    case ProcessAssertionType::UnboundedNetworking:
         return backgroundTabFlags;
-    case AssertionState::Foreground:
+    case ProcessAssertionType::Foreground:
+    case ProcessAssertionType::MediaPlayback:
         return foregroundTabFlags;
     }
 }
 
-static AssertionReason reasonForState(AssertionState assertionState)
+static BKSProcessAssertionReason toBKSProcessAssertionReason(ProcessAssertionType assertionType)
 {
-    switch (assertionState) {
-    case AssertionState::UnboundedNetworking:
-        return AssertionReason::FinishTaskUnbounded;
-    case AssertionState::Suspended:
-    case AssertionState::Background:
-    case AssertionState::Foreground:
-        return AssertionReason::Extension;
-    }
-}
-
-static BKSProcessAssertionReason toBKSProcessAssertionReason(AssertionReason reason)
-{
-    switch (reason) {
-    case AssertionReason::Extension:
+    switch (assertionType) {
+    case ProcessAssertionType::Suspended:
+    case ProcessAssertionType::Background:
+    case ProcessAssertionType::Foreground:
         return BKSProcessAssertionReasonExtension;
-    case AssertionReason::FinishTask:
-        return BKSProcessAssertionReasonFinishTask;
-    case AssertionReason::FinishTaskUnbounded:
+    case ProcessAssertionType::UnboundedNetworking:
         return BKSProcessAssertionReasonFinishTaskUnbounded;
-    case AssertionReason::MediaPlayback:
+    case ProcessAssertionType::MediaPlayback:
         return BKSProcessAssertionReasonMediaPlayback;
     }
 }
 
-ProcessAssertion::ProcessAssertion(pid_t pid, const String& name, AssertionState assertionState)
-    : ProcessAssertion(pid, name, assertionState, reasonForState(assertionState))
+ProcessAssertion::ProcessAssertion(pid_t pid, const String& name, ProcessAssertionType assertionType)
+    : m_assertionType(assertionType)
 {
-}
-
-ProcessAssertion::ProcessAssertion(pid_t pid, const String& name, AssertionState assertionState, AssertionReason assertionReason)
-    : m_assertionState(assertionState)
-{
     auto weakThis = makeWeakPtr(*this);
     BKSProcessAssertionAcquisitionHandler handler = ^(BOOL acquired) {
         if (!acquired) {
@@ -330,7 +314,7 @@
     };
     RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() PID %d acquiring assertion for process with PID %d, name '%s'", this, getpid(), pid, name.utf8().data());
     
-    m_assertion = adoptNS([[BKSProcessAssertion alloc] initWithPID:pid flags:flagsForState(assertionState) reason:toBKSProcessAssertionReason(assertionReason) name:(NSString *)name withHandler:handler]);
+    m_assertion = adoptNS([[BKSProcessAssertion alloc] initWithPID:pid flags:flagsForAssertionType(assertionType) reason:toBKSProcessAssertionReason(assertionType) name:(NSString *)name withHandler:handler]);
     m_assertion.get().invalidationHandler = ^() {
         dispatch_async(dispatch_get_main_queue(), ^{
             RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() Process assertion for process with PID %d was invalidated", this, pid);
@@ -356,19 +340,9 @@
     m_validity = Validity::No;
 }
 
-void ProcessAssertion::setState(AssertionState assertionState)
-{
-    if (m_assertionState == assertionState)
-        return;
-
-    RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion::setState(%u) previousState: %u", this, static_cast<unsigned>(assertionState), static_cast<unsigned>(m_assertionState));
-    m_assertionState = assertionState;
-    [m_assertion setFlags:flagsForState(assertionState)];
-}
-
 void ProcessAndUIAssertion::updateRunInBackgroundCount()
 {
-    bool shouldHoldBackgroundTask = validity() != Validity::No && state() != AssertionState::Suspended;
+    bool shouldHoldBackgroundTask = validity() != Validity::No && type() != ProcessAssertionType::Suspended;
     if (m_isHoldingBackgroundTask == shouldHoldBackgroundTask)
         return;
 
@@ -380,8 +354,8 @@
     m_isHoldingBackgroundTask = shouldHoldBackgroundTask;
 }
 
-ProcessAndUIAssertion::ProcessAndUIAssertion(pid_t pid, const String& reason, AssertionState assertionState)
-    : ProcessAssertion(pid, reason, assertionState)
+ProcessAndUIAssertion::ProcessAndUIAssertion(pid_t pid, const String& reason, ProcessAssertionType assertionType)
+    : ProcessAssertion(pid, reason, assertionType)
 {
     updateRunInBackgroundCount();
 }
@@ -392,12 +366,6 @@
         [[WKProcessAssertionBackgroundTaskManager shared] removeAssertionNeedingBackgroundTask:*this];
 }
 
-void ProcessAndUIAssertion::setState(AssertionState assertionState)
-{
-    ProcessAssertion::setState(assertionState);
-    updateRunInBackgroundCount();
-}
-
 void ProcessAndUIAssertion::uiAssertionWillExpireImminently()
 {
     if (auto* client = this->client())

Modified: trunk/Tools/ChangeLog (259539 => 259540)


--- trunk/Tools/ChangeLog	2020-04-04 23:44:55 UTC (rev 259539)
+++ trunk/Tools/ChangeLog	2020-04-05 00:03:45 UTC (rev 259540)
@@ -1,3 +1,13 @@
+2020-04-04  Chris Dumez  <[email protected]>
+
+        [iOS] Simplify ProcessAssertion class in preparation for switch to RunningBoard
+        https://bugs.webkit.org/show_bug.cgi?id=209984
+        <rdar://problem/61273941>
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
+
 2020-04-04  Wenson Hsieh  <[email protected]>
 
         Add even more logging to try and diagnose <webkit.org/b/209685>

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm (259539 => 259540)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm	2020-04-04 23:44:55 UTC (rev 259539)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm	2020-04-05 00:03:45 UTC (rev 259540)
@@ -1665,15 +1665,15 @@
 
     waitUntilServiceWorkerProcessCount(processPool, 1);
 
-    [webView _setAssertionStateForTesting: 1];
+    [webView _setAssertionTypeForTesting: 1];
     waitUntilServiceWorkerProcessForegroundActivityState(webView.get(), false);
     waitUntilServiceWorkerProcessBackgroundActivityState(webView.get(), true);
 
-    [webView _setAssertionStateForTesting: 3];
+    [webView _setAssertionTypeForTesting: 3];
     waitUntilServiceWorkerProcessForegroundActivityState(webView.get(), true);
     waitUntilServiceWorkerProcessBackgroundActivityState(webView.get(), false);
 
-    [webView _setAssertionStateForTesting: 0];
+    [webView _setAssertionTypeForTesting: 0];
     waitUntilServiceWorkerProcessBackgroundActivityState(webView.get(), false);
     waitUntilServiceWorkerProcessForegroundActivityState(webView.get(), false);
 
@@ -1685,19 +1685,19 @@
     webView = nullptr;
 
     // The service worker process should take activity based on webView2 process.
-    [webView2 _setAssertionStateForTesting: 1];
+    [webView2 _setAssertionTypeForTesting: 1];
     while (webView2.get()._hasServiceWorkerForegroundActivityForTesting || !webView2.get()._hasServiceWorkerBackgroundActivityForTesting) {
-        [webView2 _setAssertionStateForTesting: 1];
+        [webView2 _setAssertionTypeForTesting: 1];
         TestWebKitAPI::Util::spinRunLoop(1);
     }
 
     while (!webView2.get()._hasServiceWorkerForegroundActivityForTesting || webView2.get()._hasServiceWorkerBackgroundActivityForTesting) {
-        [webView2 _setAssertionStateForTesting: 3];
+        [webView2 _setAssertionTypeForTesting: 3];
         TestWebKitAPI::Util::spinRunLoop(1);
     }
 
     while (webView2.get()._hasServiceWorkerForegroundActivityForTesting || webView2.get()._hasServiceWorkerBackgroundActivityForTesting) {
-        [webView2 _setAssertionStateForTesting: 0];
+        [webView2 _setAssertionTypeForTesting: 0];
         TestWebKitAPI::Util::spinRunLoop(1);
     }
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to