<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[242610] trunk/Source/WebKit</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/242610">242610</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2019-03-07 13:49:22 -0800 (Thu, 07 Mar 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>Clean up / simplify ProcessAssertion code
https://bugs.webkit.org/show_bug.cgi?id=195394

Reviewed by Geoffrey Garen.

Clean up / simplify ProcessAssertion code to facilitate its maintenance and make it
less error-prone.

* Platform/IPC/mac/ConnectionMac.mm:
(IPC::ConnectionTerminationWatchdog::ConnectionTerminationWatchdog):
* UIProcess/ProcessAssertion.cpp:
(WebKit::ProcessAssertion::ProcessAssertion):
(WebKit::ProcessAssertion::setState):
* UIProcess/ProcessAssertion.h:
(WebKit::ProcessAssertion::Client::~Client):
(WebKit::ProcessAssertion::setClient):
(WebKit::ProcessAssertion::client):
* UIProcess/ProcessThrottler.cpp:
(WebKit::ProcessThrottler::didConnectToProcess):
* UIProcess/ProcessThrottler.h:
* UIProcess/ios/ProcessAssertionIOS.mm:
(-[WKProcessAssertionBackgroundTaskManager dealloc]):
(-[WKProcessAssertionBackgroundTaskManager addAssertionNeedingBackgroundTask:]):
(-[WKProcessAssertionBackgroundTaskManager removeAssertionNeedingBackgroundTask:]):
(-[WKProcessAssertionBackgroundTaskManager _notifyAssertionsOfImminentSuspension]):
(-[WKProcessAssertionBackgroundTaskManager _releaseBackgroundTask]):
(-[WKProcessAssertionBackgroundTaskManager _updateBackgroundTask]):
(WebKit::ProcessAssertion::ProcessAssertion):
(WebKit::ProcessAssertion::processAssertionWasInvalidated):
(WebKit::ProcessAssertion::setState):
(WebKit::ProcessAndUIAssertion::updateRunInBackgroundCount):
(WebKit::ProcessAndUIAssertion::ProcessAndUIAssertion):
(WebKit::ProcessAndUIAssertion::~ProcessAndUIAssertion):
(WebKit::ProcessAndUIAssertion::processAssertionWasInvalidated):
(WebKit::ProcessAndUIAssertion::setState):
(WebKit::ProcessAndUIAssertion::uiAssertionWillExpireImminently):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitPlatformIPCmacConnectionMacmm">trunk/Source/WebKit/Platform/IPC/mac/ConnectionMac.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessProcessAssertioncpp">trunk/Source/WebKit/UIProcess/ProcessAssertion.cpp</a></li>
<li><a href="#trunkSourceWebKitUIProcessProcessAssertionh">trunk/Source/WebKit/UIProcess/ProcessAssertion.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessProcessThrottlercpp">trunk/Source/WebKit/UIProcess/ProcessThrottler.cpp</a></li>
<li><a href="#trunkSourceWebKitUIProcessProcessThrottlerh">trunk/Source/WebKit/UIProcess/ProcessThrottler.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessiosProcessAssertionIOSmm">trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (242609 => 242610)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2019-03-07 21:44:19 UTC (rev 242609)
+++ trunk/Source/WebKit/ChangeLog       2019-03-07 21:49:22 UTC (rev 242610)
</span><span class="lines">@@ -1,3 +1,42 @@
</span><ins>+2019-03-07  Chris Dumez  <cdumez@apple.com>
+
+        Clean up / simplify ProcessAssertion code
+        https://bugs.webkit.org/show_bug.cgi?id=195394
+
+        Reviewed by Geoffrey Garen.
+
+        Clean up / simplify ProcessAssertion code to facilitate its maintenance and make it
+        less error-prone.
+
+        * Platform/IPC/mac/ConnectionMac.mm:
+        (IPC::ConnectionTerminationWatchdog::ConnectionTerminationWatchdog):
+        * UIProcess/ProcessAssertion.cpp:
+        (WebKit::ProcessAssertion::ProcessAssertion):
+        (WebKit::ProcessAssertion::setState):
+        * UIProcess/ProcessAssertion.h:
+        (WebKit::ProcessAssertion::Client::~Client):
+        (WebKit::ProcessAssertion::setClient):
+        (WebKit::ProcessAssertion::client):
+        * UIProcess/ProcessThrottler.cpp:
+        (WebKit::ProcessThrottler::didConnectToProcess):
+        * UIProcess/ProcessThrottler.h:
+        * UIProcess/ios/ProcessAssertionIOS.mm:
+        (-[WKProcessAssertionBackgroundTaskManager dealloc]):
+        (-[WKProcessAssertionBackgroundTaskManager addAssertionNeedingBackgroundTask:]):
+        (-[WKProcessAssertionBackgroundTaskManager removeAssertionNeedingBackgroundTask:]):
+        (-[WKProcessAssertionBackgroundTaskManager _notifyAssertionsOfImminentSuspension]):
+        (-[WKProcessAssertionBackgroundTaskManager _releaseBackgroundTask]):
+        (-[WKProcessAssertionBackgroundTaskManager _updateBackgroundTask]):
+        (WebKit::ProcessAssertion::ProcessAssertion):
+        (WebKit::ProcessAssertion::processAssertionWasInvalidated):
+        (WebKit::ProcessAssertion::setState):
+        (WebKit::ProcessAndUIAssertion::updateRunInBackgroundCount):
+        (WebKit::ProcessAndUIAssertion::ProcessAndUIAssertion):
+        (WebKit::ProcessAndUIAssertion::~ProcessAndUIAssertion):
+        (WebKit::ProcessAndUIAssertion::processAssertionWasInvalidated):
+        (WebKit::ProcessAndUIAssertion::setState):
+        (WebKit::ProcessAndUIAssertion::uiAssertionWillExpireImminently):
+
</ins><span class="cx"> 2019-03-07  Commit Queue  <commit-queue@webkit.org>
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, rolling out r242297.
</span></span></pre></div>
<a id="trunkSourceWebKitPlatformIPCmacConnectionMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Platform/IPC/mac/ConnectionMac.mm (242609 => 242610)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Platform/IPC/mac/ConnectionMac.mm    2019-03-07 21:44:19 UTC (rev 242609)
+++ trunk/Source/WebKit/Platform/IPC/mac/ConnectionMac.mm       2019-03-07 21:49:22 UTC (rev 242610)
</span><span class="lines">@@ -92,7 +92,7 @@
</span><span class="cx">         : m_xpcConnection(xpcConnection)
</span><span class="cx">         , m_watchdogTimer(RunLoop::main(), this, &ConnectionTerminationWatchdog::watchdogTimerFired)
</span><span class="cx"> #if PLATFORM(IOS_FAMILY)
</span><del>-        , m_assertion(std::make_unique<WebKit::ProcessAndUIAssertion>(xpc_connection_get_pid(m_xpcConnection.get()), WebKit::AssertionState::Background))
</del><ins>+        , m_assertion(std::make_unique<WebKit::ProcessAndUIAssertion>(xpc_connection_get_pid(m_xpcConnection.get()), "ConnectionTerminationWatchdog"_s, WebKit::AssertionState::Background))
</ins><span class="cx"> #endif
</span><span class="cx">     {
</span><span class="cx">         m_watchdogTimer.startOneShot(interval);
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessProcessAssertioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ProcessAssertion.cpp (242609 => 242610)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ProcessAssertion.cpp       2019-03-07 21:44:19 UTC (rev 242609)
+++ trunk/Source/WebKit/UIProcess/ProcessAssertion.cpp  2019-03-07 21:49:22 UTC (rev 242610)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2014 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2014-2019 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -26,51 +26,22 @@
</span><span class="cx"> #include "config.h"
</span><span class="cx"> #include "ProcessAssertion.h"
</span><span class="cx"> 
</span><del>-#if !PLATFORM(IOS_FAMILY)
</del><ins>+#if !PLATFORM(IOS_FAMILY) || PLATFORM(IOS_FAMILY_SIMULATOR)
</ins><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><del>-ProcessAssertion::ProcessAssertion(ProcessID, AssertionState assertionState, Function<void()>&&)
</del><ins>+ProcessAssertion::ProcessAssertion(ProcessID, const String&, AssertionState assertionState)
</ins><span class="cx">     : m_assertionState(assertionState)
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-ProcessAssertion::ProcessAssertion(ProcessID, const String&, AssertionState assertionState, Function<void()>&&)
-    : m_assertionState(assertionState)
-{
-}
</del><ins>+ProcessAssertion::~ProcessAssertion() = default;
</ins><span class="cx"> 
</span><del>-ProcessAssertion::~ProcessAssertion()
-{
-}
-
</del><span class="cx"> void ProcessAssertion::setState(AssertionState assertionState)
</span><span class="cx"> {
</span><del>-    if (m_assertionState == assertionState)
-        return;
-
</del><span class="cx">     m_assertionState = assertionState;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-ProcessAndUIAssertion::ProcessAndUIAssertion(ProcessID pid, AssertionState assertionState)
-    : ProcessAssertion(pid, assertionState)
-{
-}
</del><ins>+} // namespace WebKit
</ins><span class="cx"> 
</span><del>-ProcessAndUIAssertion::~ProcessAndUIAssertion()
-{
-}
-
-void ProcessAndUIAssertion::setState(AssertionState assertionState)
-{
-    ProcessAssertion::setState(assertionState);
-}
-
-void ProcessAndUIAssertion::setClient(ProcessAssertionClient& client)
-{
-    ProcessAssertion::setClient(client);
-}
-
-}
-
-#endif // !PLATFORM(IOS_FAMILY)
</del><ins>+#endif // !PLATFORM(IOS_FAMILY) || PLATFORM(IOS_FAMILY_SIMULATOR)
</ins></span></pre></div>
<a id="trunkSourceWebKitUIProcessProcessAssertionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ProcessAssertion.h (242609 => 242610)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ProcessAssertion.h 2019-03-07 21:44:19 UTC (rev 242609)
+++ trunk/Source/WebKit/UIProcess/ProcessAssertion.h    2019-03-07 21:49:22 UTC (rev 242610)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2014 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2014-2019 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -23,11 +23,11 @@
</span><span class="cx">  * THE POSSIBILITY OF SUCH DAMAGE.
</span><span class="cx">  */
</span><span class="cx"> 
</span><del>-#ifndef ProcessAssertion_h
-#define ProcessAssertion_h
</del><ins>+#pragma once
</ins><span class="cx"> 
</span><span class="cx"> #include <wtf/Function.h>
</span><span class="cx"> #include <wtf/ProcessID.h>
</span><ins>+#include <wtf/WeakPtr.h>
</ins><span class="cx"> #include <wtf/text/WTFString.h>
</span><span class="cx"> 
</span><span class="cx"> #if !OS(WINDOWS)
</span><span class="lines">@@ -36,7 +36,6 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS_FAMILY) && !PLATFORM(IOS_FAMILY_SIMULATOR)
</span><span class="cx"> #include <wtf/RetainPtr.h>
</span><del>-#include <wtf/WeakPtr.h>
</del><span class="cx"> OBJC_CLASS BKSProcessAssertion;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="lines">@@ -49,25 +48,20 @@
</span><span class="cx">     Foreground
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-class ProcessAssertionClient {
</del><ins>+class ProcessAssertion : public CanMakeWeakPtr<ProcessAssertion> {
+    WTF_MAKE_FAST_ALLOCATED;
</ins><span class="cx"> public:
</span><del>-    virtual ~ProcessAssertionClient() { }
-    virtual void uiAssertionWillExpireImminently() = 0;
-};
</del><ins>+    class Client {
+    public:
+        virtual ~Client() { }
+        virtual void uiAssertionWillExpireImminently() = 0;
+    };
</ins><span class="cx"> 
</span><del>-class ProcessAssertion
-#if PLATFORM(IOS_FAMILY) && !PLATFORM(IOS_FAMILY_SIMULATOR)
-    : public CanMakeWeakPtr<ProcessAssertion>
-#endif
-{
-    WTF_MAKE_FAST_ALLOCATED;
-public:
-    ProcessAssertion(ProcessID, AssertionState, Function<void()>&& invalidationCallback = { });
-    ProcessAssertion(ProcessID, const String& reason, AssertionState, Function<void()>&& invalidationCallback = { });
</del><ins>+    ProcessAssertion(ProcessID, const String& reason, AssertionState);
</ins><span class="cx">     virtual ~ProcessAssertion();
</span><span class="cx"> 
</span><del>-    virtual void setClient(ProcessAssertionClient& client) { m_client = &client; }
-    ProcessAssertionClient* client() { return m_client; }
</del><ins>+    void setClient(Client& client) { m_client = &client; }
+    Client* client() { return m_client; }
</ins><span class="cx"> 
</span><span class="cx">     AssertionState state() const { return m_assertionState; }
</span><span class="cx">     virtual void setState(AssertionState);
</span><span class="lines">@@ -76,37 +70,40 @@
</span><span class="cx"> protected:
</span><span class="cx">     enum class Validity { No, Yes, Unset };
</span><span class="cx">     Validity validity() const { return m_validity; }
</span><ins>+
+    virtual void processAssertionWasInvalidated();
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx"> #if PLATFORM(IOS_FAMILY) && !PLATFORM(IOS_FAMILY_SIMULATOR)
</span><del>-    void markAsInvalidated();
-
</del><span class="cx">     RetainPtr<BKSProcessAssertion> m_assertion;
</span><span class="cx">     Validity m_validity { Validity::Unset };
</span><del>-    Function<void()> m_invalidationCallback;
</del><span class="cx"> #endif
</span><span class="cx">     AssertionState m_assertionState;
</span><del>-    ProcessAssertionClient* m_client { nullptr };
</del><ins>+    Client* m_client { nullptr };
</ins><span class="cx"> };
</span><del>-    
</del><ins>+
+#if PLATFORM(IOS_FAMILY) && !PLATFORM(IOS_FAMILY_SIMULATOR)
+
</ins><span class="cx"> class ProcessAndUIAssertion final : public ProcessAssertion {
</span><span class="cx"> public:
</span><del>-    ProcessAndUIAssertion(ProcessID, AssertionState);
</del><ins>+    ProcessAndUIAssertion(ProcessID, const String& reason, AssertionState);
</ins><span class="cx">     ~ProcessAndUIAssertion();
</span><span class="cx"> 
</span><del>-    void setClient(ProcessAssertionClient&) final;
-
</del><span class="cx">     void setState(AssertionState) final;
</span><ins>+    void uiAssertionWillExpireImminently();
</ins><span class="cx"> 
</span><del>-#if PLATFORM(IOS_FAMILY) && !PLATFORM(IOS_FAMILY_SIMULATOR)
</del><span class="cx"> private:
</span><ins>+    void processAssertionWasInvalidated() final;
</ins><span class="cx">     void updateRunInBackgroundCount();
</span><span class="cx"> 
</span><del>-    bool m_isHoldingBackgroundAssertion { false };
-#endif
</del><ins>+    bool m_isHoldingBackgroundTask { false };
</ins><span class="cx"> };
</span><ins>+
+#else
+
+using ProcessAndUIAssertion = ProcessAssertion;
+
+#endif // PLATFORM(IOS_FAMILY) && !PLATFORM(IOS_FAMILY_SIMULATOR)
</ins><span class="cx">     
</span><del>-}
-
-#endif // ProcessAssertion_h
</del><ins>+} // namespace WebKit
</ins></span></pre></div>
<a id="trunkSourceWebKitUIProcessProcessThrottlercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ProcessThrottler.cpp (242609 => 242610)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ProcessThrottler.cpp       2019-03-07 21:44:19 UTC (rev 242609)
+++ trunk/Source/WebKit/UIProcess/ProcessThrottler.cpp  2019-03-07 21:49:22 UTC (rev 242610)
</span><span class="lines">@@ -103,9 +103,9 @@
</span><span class="cx"> 
</span><span class="cx">     m_suspendTimer.stop();
</span><span class="cx">     if (m_shouldTakeUIBackgroundAssertion)
</span><del>-        m_assertion = std::make_unique<ProcessAndUIAssertion>(pid, assertionState());
</del><ins>+        m_assertion = std::make_unique<ProcessAndUIAssertion>(pid, "Web content visibility"_s, assertionState());
</ins><span class="cx">     else
</span><del>-        m_assertion = std::make_unique<ProcessAssertion>(pid, assertionState());
</del><ins>+        m_assertion = std::make_unique<ProcessAssertion>(pid, "Web content visibility"_s, assertionState());
</ins><span class="cx">     m_process.didSetAssertionState(assertionState());
</span><span class="cx">     m_assertion->setClient(*this);
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessProcessThrottlerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ProcessThrottler.h (242609 => 242610)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ProcessThrottler.h 2019-03-07 21:44:19 UTC (rev 242609)
+++ trunk/Source/WebKit/UIProcess/ProcessThrottler.h    2019-03-07 21:49:22 UTC (rev 242610)
</span><span class="lines">@@ -43,7 +43,7 @@
</span><span class="cx"> 
</span><span class="cx"> class ProcessThrottlerClient;
</span><span class="cx"> 
</span><del>-class ProcessThrottler : private ProcessAssertionClient {
</del><ins>+class ProcessThrottler : private ProcessAssertion::Client {
</ins><span class="cx"> public:
</span><span class="cx">     enum ForegroundActivityCounterType { };
</span><span class="cx">     typedef RefCounter<ForegroundActivityCounterType> ForegroundActivityCounter;
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessiosProcessAssertionIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm (242609 => 242610)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm 2019-03-07 21:44:19 UTC (rev 242609)
+++ trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm    2019-03-07 21:49:22 UTC (rev 242610)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2014 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2014-2019 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -26,36 +26,30 @@
</span><span class="cx"> #import "config.h"
</span><span class="cx"> #import "ProcessAssertion.h"
</span><span class="cx"> 
</span><del>-#if PLATFORM(IOS_FAMILY)
</del><ins>+#if PLATFORM(IOS_FAMILY) && !PLATFORM(IOS_FAMILY_SIMULATOR)
</ins><span class="cx"> 
</span><span class="cx"> #import "AssertionServicesSPI.h"
</span><span class="cx"> #import "Logging.h"
</span><span class="cx"> #import <UIKit/UIApplication.h>
</span><del>-#import <wtf/HashSet.h>
</del><ins>+#import <wtf/HashMap.h>
</ins><span class="cx"> #import <wtf/RunLoop.h>
</span><span class="cx"> #import <wtf/Vector.h>
</span><span class="cx"> 
</span><del>-#if !PLATFORM(IOS_FAMILY_SIMULATOR)
</del><ins>+using WebKit::ProcessAndUIAssertion;
</ins><span class="cx"> 
</span><del>-using WebKit::ProcessAssertionClient;
-
</del><span class="cx"> @interface WKProcessAssertionBackgroundTaskManager : NSObject
</span><span class="cx"> 
</span><span class="cx"> + (WKProcessAssertionBackgroundTaskManager *)shared;
</span><span class="cx"> 
</span><del>-- (void)incrementNeedsToRunInBackgroundCount;
-- (void)decrementNeedsToRunInBackgroundCount;
</del><ins>+- (void)addAssertionNeedingBackgroundTask:(ProcessAndUIAssertion&)assertion;
+- (void)removeAssertionNeedingBackgroundTask:(ProcessAndUIAssertion&)assertion;
</ins><span class="cx"> 
</span><del>-- (void)addClient:(ProcessAssertionClient&)client;
-- (void)removeClient:(ProcessAssertionClient&)client;
-
</del><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> @implementation WKProcessAssertionBackgroundTaskManager
</span><span class="cx"> {
</span><del>-    unsigned _needsToRunInBackgroundCount;
</del><span class="cx">     UIBackgroundTaskIdentifier _backgroundTask;
</span><del>-    HashSet<ProcessAssertionClient*> _clients;
</del><ins>+    HashSet<ProcessAndUIAssertion*> _assertionsNeedingBackgroundTask;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> + (WKProcessAssertionBackgroundTaskManager *)shared
</span><span class="lines">@@ -77,66 +71,58 @@
</span><span class="cx"> 
</span><span class="cx"> - (void)dealloc
</span><span class="cx"> {
</span><del>-    if (_backgroundTask != UIBackgroundTaskInvalid)
-        [[UIApplication sharedApplication] endBackgroundTask:_backgroundTask];
-
</del><ins>+    [self _releaseBackgroundTask];
</ins><span class="cx">     [super dealloc];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (void)addClient:(ProcessAssertionClient&)client
</del><ins>+- (void)addAssertionNeedingBackgroundTask:(ProcessAndUIAssertion&)assertion
</ins><span class="cx"> {
</span><del>-    _clients.add(&client);
</del><ins>+    _assertionsNeedingBackgroundTask.add(&assertion);
+    [self _updateBackgroundTask];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (void)removeClient:(ProcessAssertionClient&)client
</del><ins>+- (void)removeAssertionNeedingBackgroundTask:(ProcessAndUIAssertion&)assertion
</ins><span class="cx"> {
</span><del>-    _clients.remove(&client);
</del><ins>+    _assertionsNeedingBackgroundTask.remove(&assertion);
+    [self _updateBackgroundTask];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (void)_notifyClientsOfImminentSuspension
</del><ins>+- (void)_notifyAssertionsOfImminentSuspension
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(RunLoop::isMain());
</span><span class="cx"> 
</span><del>-    for (auto* client : copyToVector(_clients))
-        client->uiAssertionWillExpireImminently();
</del><ins>+    for (auto* assertion : copyToVector(_assertionsNeedingBackgroundTask))
+        assertion->uiAssertionWillExpireImminently();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)_updateBackgroundTask
</span><span class="cx"> {
</span><del>-    if (_needsToRunInBackgroundCount && _backgroundTask == UIBackgroundTaskInvalid) {
</del><ins>+    if (!_assertionsNeedingBackgroundTask.isEmpty() && _backgroundTask == UIBackgroundTaskInvalid) {
</ins><span class="cx">         RELEASE_LOG(ProcessSuspension, "%p - WKProcessAssertionBackgroundTaskManager - beginBackgroundTaskWithName", self);
</span><span class="cx">         _backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithName:@"com.apple.WebKit.ProcessAssertion" expirationHandler:^{
</span><span class="cx">             RELEASE_LOG_ERROR(ProcessSuspension, "Background task expired while holding WebKit ProcessAssertion (isMainThread? %d).", RunLoop::isMain());
</span><span class="cx">             // The expiration handler gets called on a non-main thread when the underlying assertion could not be taken (rdar://problem/27278419).
</span><span class="cx">             if (RunLoop::isMain())
</span><del>-                [self _notifyClientsOfImminentSuspension];
</del><ins>+                [self _notifyAssertionsOfImminentSuspension];
</ins><span class="cx">             else {
</span><span class="cx">                 dispatch_sync(dispatch_get_main_queue(), ^{
</span><del>-                    [self _notifyClientsOfImminentSuspension];
</del><ins>+                    [self _notifyAssertionsOfImminentSuspension];
</ins><span class="cx">                 });
</span><span class="cx">             }
</span><del>-            [[UIApplication sharedApplication] endBackgroundTask:_backgroundTask];
-            _backgroundTask = UIBackgroundTaskInvalid;
</del><ins>+            [self _releaseBackgroundTask];
</ins><span class="cx">         }];
</span><del>-    }
-
-    if (!_needsToRunInBackgroundCount && _backgroundTask != UIBackgroundTaskInvalid) {
-        RELEASE_LOG(ProcessSuspension, "%p - WKProcessAssertionBackgroundTaskManager - endBackgroundTask", self);
-        [[UIApplication sharedApplication] endBackgroundTask:_backgroundTask];
-        _backgroundTask = UIBackgroundTaskInvalid;
-    }
</del><ins>+    } else if (_assertionsNeedingBackgroundTask.isEmpty())
+        [self _releaseBackgroundTask];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (void)incrementNeedsToRunInBackgroundCount
</del><ins>+- (void)_releaseBackgroundTask
</ins><span class="cx"> {
</span><del>-    ++_needsToRunInBackgroundCount;
-    [self _updateBackgroundTask];
-}
</del><ins>+    if (_backgroundTask == UIBackgroundTaskInvalid)
+        return;
</ins><span class="cx"> 
</span><del>-- (void)decrementNeedsToRunInBackgroundCount
-{
-    --_needsToRunInBackgroundCount;
-    [self _updateBackgroundTask];
</del><ins>+    RELEASE_LOG(ProcessSuspension, "%p - WKProcessAssertionBackgroundTaskManager - endBackgroundTask", self);
+    [[UIApplication sharedApplication] endBackgroundTask:_backgroundTask];
+    _backgroundTask = UIBackgroundTaskInvalid;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> @end
</span><span class="lines">@@ -172,15 +158,9 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-ProcessAssertion::ProcessAssertion(pid_t pid, AssertionState assertionState, Function<void()>&& invalidationCallback)
-    : ProcessAssertion(pid, "Web content visibility"_s, assertionState, WTFMove(invalidationCallback))
</del><ins>+ProcessAssertion::ProcessAssertion(pid_t pid, const String& name, AssertionState assertionState)
+    : m_assertionState(assertionState)
</ins><span class="cx"> {
</span><del>-}
-
-ProcessAssertion::ProcessAssertion(pid_t pid, const String& name, AssertionState assertionState, Function<void()>&& invalidationCallback)
-    : m_invalidationCallback(WTFMove(invalidationCallback))
-    , m_assertionState(assertionState)
-{
</del><span class="cx">     auto weakThis = makeWeakPtr(*this);
</span><span class="cx">     BKSProcessAssertionAcquisitionHandler handler = ^(BOOL acquired) {
</span><span class="cx">         if (!acquired) {
</span><span class="lines">@@ -188,7 +168,7 @@
</span><span class="cx">             ASSERT_NOT_REACHED();
</span><span class="cx">             dispatch_async(dispatch_get_main_queue(), ^{
</span><span class="cx">                 if (weakThis)
</span><del>-                    markAsInvalidated();
</del><ins>+                    processAssertionWasInvalidated();
</ins><span class="cx">             });
</span><span class="cx">         }
</span><span class="cx">     };
</span><span class="lines">@@ -199,7 +179,7 @@
</span><span class="cx">         dispatch_async(dispatch_get_main_queue(), ^{
</span><span class="cx">             RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() Process assertion for process with PID %d was invalidated", this, pid);
</span><span class="cx">             if (weakThis)
</span><del>-                markAsInvalidated();
</del><ins>+                processAssertionWasInvalidated();
</ins><span class="cx">         });
</span><span class="cx">     };
</span><span class="cx"> }
</span><span class="lines">@@ -212,13 +192,12 @@
</span><span class="cx">     [m_assertion invalidate];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ProcessAssertion::markAsInvalidated()
</del><ins>+void ProcessAssertion::processAssertionWasInvalidated()
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(RunLoop::isMain());
</span><ins>+    RELEASE_LOG_ERROR(ProcessSuspension, "%p - ProcessAssertion::processAssertionWasInvalidated()", this);
</ins><span class="cx"> 
</span><span class="cx">     m_validity = Validity::No;
</span><del>-    if (m_invalidationCallback)
-        m_invalidationCallback();
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ProcessAssertion::setState(AssertionState assertionState)
</span><span class="lines">@@ -226,7 +205,7 @@
</span><span class="cx">     if (m_assertionState == assertionState)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion::setState(%u)", this, static_cast<unsigned>(assertionState));
</del><ins>+    RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion::setState(%u) previousState: %u", this, static_cast<unsigned>(assertionState), static_cast<unsigned>(m_assertionState));
</ins><span class="cx">     m_assertionState = assertionState;
</span><span class="cx">     [m_assertion setFlags:flagsForState(assertionState)];
</span><span class="cx"> }
</span><span class="lines">@@ -233,21 +212,20 @@
</span><span class="cx"> 
</span><span class="cx"> void ProcessAndUIAssertion::updateRunInBackgroundCount()
</span><span class="cx"> {
</span><del>-    bool shouldHoldBackgroundAssertion = validity() != Validity::No && state() != AssertionState::Suspended;
</del><ins>+    bool shouldHoldBackgroundTask = validity() != Validity::No && state() != AssertionState::Suspended;
+    if (m_isHoldingBackgroundTask == shouldHoldBackgroundTask)
+        return;
</ins><span class="cx"> 
</span><del>-    if (shouldHoldBackgroundAssertion) {
-        if (!m_isHoldingBackgroundAssertion)
-            [[WKProcessAssertionBackgroundTaskManager shared] incrementNeedsToRunInBackgroundCount];
-    } else {
-        if (m_isHoldingBackgroundAssertion)
-            [[WKProcessAssertionBackgroundTaskManager shared] decrementNeedsToRunInBackgroundCount];
-    }
</del><ins>+    if (shouldHoldBackgroundTask)
+        [[WKProcessAssertionBackgroundTaskManager shared] addAssertionNeedingBackgroundTask:*this];
+    else
+        [[WKProcessAssertionBackgroundTaskManager shared] removeAssertionNeedingBackgroundTask:*this];
</ins><span class="cx"> 
</span><del>-    m_isHoldingBackgroundAssertion = shouldHoldBackgroundAssertion;
</del><ins>+    m_isHoldingBackgroundTask = shouldHoldBackgroundTask;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-ProcessAndUIAssertion::ProcessAndUIAssertion(pid_t pid, AssertionState assertionState)
-    : ProcessAssertion(pid, assertionState, [this] { updateRunInBackgroundCount(); })
</del><ins>+ProcessAndUIAssertion::ProcessAndUIAssertion(pid_t pid, const String& reason, AssertionState assertionState)
+    : ProcessAssertion(pid, reason, assertionState)
</ins><span class="cx"> {
</span><span class="cx">     updateRunInBackgroundCount();
</span><span class="cx"> }
</span><span class="lines">@@ -254,11 +232,8 @@
</span><span class="cx"> 
</span><span class="cx"> ProcessAndUIAssertion::~ProcessAndUIAssertion()
</span><span class="cx"> {
</span><del>-    if (m_isHoldingBackgroundAssertion)
-        [[WKProcessAssertionBackgroundTaskManager shared] decrementNeedsToRunInBackgroundCount];
-
-    if (auto* client = this->client())
-        [[WKProcessAssertionBackgroundTaskManager shared] removeClient:*client];
</del><ins>+    if (m_isHoldingBackgroundTask)
+        [[WKProcessAssertionBackgroundTaskManager shared] removeAssertionNeedingBackgroundTask:*this];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ProcessAndUIAssertion::setState(AssertionState assertionState)
</span><span class="lines">@@ -267,60 +242,18 @@
</span><span class="cx">     updateRunInBackgroundCount();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ProcessAndUIAssertion::setClient(ProcessAssertionClient& newClient)
</del><ins>+void ProcessAndUIAssertion::uiAssertionWillExpireImminently()
</ins><span class="cx"> {
</span><del>-    [[WKProcessAssertionBackgroundTaskManager shared] addClient:newClient];
-    if (auto* oldClient = this->client())
-        [[WKProcessAssertionBackgroundTaskManager shared] removeClient:*oldClient];
-    ProcessAssertion::setClient(newClient);
</del><ins>+    if (auto* client = this->client())
+        client->uiAssertionWillExpireImminently();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-} // namespace WebKit
-
-#else // PLATFORM(IOS_FAMILY_SIMULATOR)
-
-namespace WebKit {
-
-ProcessAssertion::ProcessAssertion(pid_t, AssertionState assertionState, Function<void()>&&)
-    : m_assertionState(assertionState)
</del><ins>+void ProcessAndUIAssertion::processAssertionWasInvalidated()
</ins><span class="cx"> {
</span><ins>+    ProcessAssertion::processAssertionWasInvalidated();
+    updateRunInBackgroundCount();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-ProcessAssertion::ProcessAssertion(pid_t, const String&, AssertionState assertionState, Function<void()>&&)
-    : m_assertionState(assertionState)
-{
-}
-
-ProcessAssertion::~ProcessAssertion()
-{
-}
-
-void ProcessAssertion::setState(AssertionState assertionState)
-{
-    m_assertionState = assertionState;
-}
-
-ProcessAndUIAssertion::ProcessAndUIAssertion(pid_t pid, AssertionState assertionState)
-    : ProcessAssertion(pid, assertionState)
-{
-}
-
-ProcessAndUIAssertion::~ProcessAndUIAssertion()
-{
-}
-
-void ProcessAndUIAssertion::setState(AssertionState assertionState)
-{
-    ProcessAssertion::setState(assertionState);
-}
-
-void ProcessAndUIAssertion::setClient(ProcessAssertionClient& newClient)
-{
-    ProcessAssertion::setClient(newClient);
-}
-
</del><span class="cx"> } // namespace WebKit
</span><span class="cx"> 
</span><del>-#endif // PLATFORM(IOS_FAMILY_SIMULATOR)
-
-#endif // PLATFORM(IOS_FAMILY)
</del><ins>+#endif // PLATFORM(IOS_FAMILY) && !PLATFORM(IOS_FAMILY_SIMULATOR)
</ins></span></pre>
</div>
</div>

</body>
</html>