- Revision
- 265162
- Author
- [email protected]
- Date
- 2020-07-31 15:23:06 -0700 (Fri, 31 Jul 2020)
Log Message
Drop ProcessAssertion::Client and replace with a simple invalidation handler
https://bugs.webkit.org/show_bug.cgi?id=214976
Reviewed by Brady Eidson.
ProcessAssertion had a Client class with 2 functions:
(1) one to indicate that the assertion was invalidated
(2) one to indicate that the UI assertion is about to expire
While ProcessAssertion is used in several places, only the ProcessThrottler
ever sets itself as a client. The reason is that other call sites use
assertion types that do not expire. Also, (2) only makes sense for
ProcessAndUIAssertion, not for ProcessAssertion. Only the ProcessThrottler
is using a ProcessAndUIAssertion.
I think a better design is to have a simple invalidation handler on
the ProcessAssertion, that the call site can set if they are interested
in invalidation.
Similarly, I added a UIAssertion expiration handler on ProcessAndUIAssertion
so that the ProcessThrottler can know if the UIAssertion is about to expire.
This new design also matches more closely the system process assertion API
that ProcessAssertion / ProcessAndUIAssertion are wrapping.
This patch also fixes a bug found by Youenn Fablet where the ProcessThrottler
would only set its invalidation handler in didConnectToProcess(), instead of
doing it every time a new ProcessAssertion is created in setAssertionType().
The assertion type can change (e.g. from foreground to background) after the
process has launched.
* UIProcess/ProcessAssertion.h:
(WebKit::ProcessAssertion::setInvalidationHandler):
(WebKit::ProcessAssertion::Client::~Client): Deleted.
(WebKit::ProcessAssertion::setClient): Deleted.
(WebKit::ProcessAssertion::client): Deleted.
* UIProcess/ProcessThrottler.cpp:
(WebKit::ProcessThrottler::setAssertionType):
(WebKit::ProcessThrottler::didConnectToProcess):
* UIProcess/ProcessThrottler.h:
* UIProcess/ios/ProcessAssertionIOS.mm:
(WebKit::ProcessAssertion::processAssertionWasInvalidated):
(WebKit::ProcessAndUIAssertion::uiAssertionWillExpireImminently):
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (265161 => 265162)
--- trunk/Source/WebKit/ChangeLog 2020-07-31 22:22:23 UTC (rev 265161)
+++ trunk/Source/WebKit/ChangeLog 2020-07-31 22:23:06 UTC (rev 265162)
@@ -1,3 +1,49 @@
+2020-07-31 Chris Dumez <[email protected]>
+
+ Drop ProcessAssertion::Client and replace with a simple invalidation handler
+ https://bugs.webkit.org/show_bug.cgi?id=214976
+
+ Reviewed by Brady Eidson.
+
+ ProcessAssertion had a Client class with 2 functions:
+ (1) one to indicate that the assertion was invalidated
+ (2) one to indicate that the UI assertion is about to expire
+
+ While ProcessAssertion is used in several places, only the ProcessThrottler
+ ever sets itself as a client. The reason is that other call sites use
+ assertion types that do not expire. Also, (2) only makes sense for
+ ProcessAndUIAssertion, not for ProcessAssertion. Only the ProcessThrottler
+ is using a ProcessAndUIAssertion.
+
+ I think a better design is to have a simple invalidation handler on
+ the ProcessAssertion, that the call site can set if they are interested
+ in invalidation.
+
+ Similarly, I added a UIAssertion expiration handler on ProcessAndUIAssertion
+ so that the ProcessThrottler can know if the UIAssertion is about to expire.
+
+ This new design also matches more closely the system process assertion API
+ that ProcessAssertion / ProcessAndUIAssertion are wrapping.
+
+ This patch also fixes a bug found by Youenn Fablet where the ProcessThrottler
+ would only set its invalidation handler in didConnectToProcess(), instead of
+ doing it every time a new ProcessAssertion is created in setAssertionType().
+ The assertion type can change (e.g. from foreground to background) after the
+ process has launched.
+
+ * UIProcess/ProcessAssertion.h:
+ (WebKit::ProcessAssertion::setInvalidationHandler):
+ (WebKit::ProcessAssertion::Client::~Client): Deleted.
+ (WebKit::ProcessAssertion::setClient): Deleted.
+ (WebKit::ProcessAssertion::client): Deleted.
+ * UIProcess/ProcessThrottler.cpp:
+ (WebKit::ProcessThrottler::setAssertionType):
+ (WebKit::ProcessThrottler::didConnectToProcess):
+ * UIProcess/ProcessThrottler.h:
+ * UIProcess/ios/ProcessAssertionIOS.mm:
+ (WebKit::ProcessAssertion::processAssertionWasInvalidated):
+ (WebKit::ProcessAndUIAssertion::uiAssertionWillExpireImminently):
+
2020-07-31 Jiewen Tan <[email protected]>
SOAuthorizationSession::dismissViewController could crash on calling WebPageProxy::platformWindow
Modified: trunk/Source/WebKit/UIProcess/ProcessAssertion.cpp (265161 => 265162)
--- trunk/Source/WebKit/UIProcess/ProcessAssertion.cpp 2020-07-31 22:22:23 UTC (rev 265161)
+++ trunk/Source/WebKit/UIProcess/ProcessAssertion.cpp 2020-07-31 22:23:06 UTC (rev 265162)
@@ -45,6 +45,13 @@
return true;
}
+ProcessAndUIAssertion::ProcessAndUIAssertion(ProcessID pid, const String& reason, ProcessAssertionType assertionType)
+ : ProcessAssertion(pid, reason, assertionType)
+{
+}
+
+ProcessAndUIAssertion::~ProcessAndUIAssertion() = default;
+
} // namespace WebKit
#endif // !PLATFORM(IOS_FAMILY)
Modified: trunk/Source/WebKit/UIProcess/ProcessAssertion.h (265161 => 265162)
--- trunk/Source/WebKit/UIProcess/ProcessAssertion.h 2020-07-31 22:22:23 UTC (rev 265161)
+++ trunk/Source/WebKit/UIProcess/ProcessAssertion.h 2020-07-31 22:23:06 UTC (rev 265162)
@@ -58,19 +58,10 @@
class ProcessAssertion : public CanMakeWeakPtr<ProcessAssertion> {
WTF_MAKE_FAST_ALLOCATED;
public:
- class Client {
- public:
- virtual ~Client() { }
-
- virtual void uiAssertionWillExpireImminently() = 0;
- virtual void assertionWasInvalidated() = 0;
- };
-
ProcessAssertion(ProcessID, const String& reason, ProcessAssertionType);
virtual ~ProcessAssertion();
- void setClient(Client& client) { m_client = &client; }
- Client* client() { return m_client; }
+ void setInvalidationHandler(Function<void()>&& handler) { m_invalidationHandler = WTFMove(handler); }
ProcessAssertionType type() const { return m_assertionType; }
ProcessID pid() const { return m_pid; }
@@ -92,11 +83,9 @@
RetainPtr<BKSProcessAssertion> m_bksAssertion; // Legacy.
#endif
#endif
- Client* m_client { nullptr };
+ Function<void()> m_invalidationHandler;
};
-#if PLATFORM(IOS_FAMILY)
-
class ProcessAndUIAssertion final : public ProcessAssertion {
public:
ProcessAndUIAssertion(ProcessID, const String& reason, ProcessAssertionType);
@@ -104,17 +93,16 @@
void uiAssertionWillExpireImminently();
+ void setUIAssertionExpirationHandler(Function<void()>&& handler) { m_uiAssertionExpirationHandler = WTFMove(handler); }
+
private:
+#if PLATFORM(IOS_FAMILY)
void processAssertionWasInvalidated() final;
+#endif
void updateRunInBackgroundCount();
+ Function<void()> m_uiAssertionExpirationHandler;
bool m_isHoldingBackgroundTask { false };
};
-
-#else
-
-using ProcessAndUIAssertion = ProcessAssertion;
-
-#endif // PLATFORM(IOS_FAMILY)
} // namespace WebKit
Modified: trunk/Source/WebKit/UIProcess/ProcessThrottler.cpp (265161 => 265162)
--- trunk/Source/WebKit/UIProcess/ProcessThrottler.cpp 2020-07-31 22:22:23 UTC (rev 265161)
+++ trunk/Source/WebKit/UIProcess/ProcessThrottler.cpp 2020-07-31 22:23:06 UTC (rev 265162)
@@ -127,10 +127,18 @@
return;
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, assertionName(newType), newType);
- else
+ if (m_shouldTakeUIBackgroundAssertion) {
+ auto assertion = makeUnique<ProcessAndUIAssertion>(m_processIdentifier, assertionName(newType), newType);
+ assertion->setUIAssertionExpirationHandler([this] {
+ uiAssertionWillExpireImminently();
+ });
+ m_assertion = WTFMove(assertion);
+ } else
m_assertion = makeUnique<ProcessAssertion>(m_processIdentifier, assertionName(newType), newType);
+
+ m_assertion->setInvalidationHandler([this] {
+ assertionWasInvalidated();
+ });
m_process.didSetAssertionType(newType);
}
@@ -170,7 +178,6 @@
m_processIdentifier = pid;
setAssertionType(expectedAssertionType());
RELEASE_ASSERT(m_assertion);
- m_assertion->setClient(*this);
}
void ProcessThrottler::prepareToSuspendTimeoutTimerFired()
Modified: trunk/Source/WebKit/UIProcess/ProcessThrottler.h (265161 => 265162)
--- trunk/Source/WebKit/UIProcess/ProcessThrottler.h 2020-07-31 22:22:23 UTC (rev 265161)
+++ trunk/Source/WebKit/UIProcess/ProcessThrottler.h 2020-07-31 22:23:06 UTC (rev 265162)
@@ -51,7 +51,7 @@
class ProcessThrottlerClient;
-class ProcessThrottler : public CanMakeWeakPtr<ProcessThrottler>, private ProcessAssertion::Client {
+class ProcessThrottler : public CanMakeWeakPtr<ProcessThrottler> {
public:
ProcessThrottler(ProcessThrottlerClient&, bool shouldTakeUIBackgroundAssertion);
~ProcessThrottler();
@@ -142,9 +142,8 @@
void invalidateAllActivities();
String assertionName(ProcessAssertionType) const;
- // ProcessAssertionClient
- void uiAssertionWillExpireImminently() final;
- void assertionWasInvalidated() final;
+ void uiAssertionWillExpireImminently();
+ void assertionWasInvalidated();
void clearPendingRequestToSuspend();
Modified: trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm (265161 => 265162)
--- trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm 2020-07-31 22:22:23 UTC (rev 265161)
+++ trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm 2020-07-31 22:23:06 UTC (rev 265162)
@@ -452,8 +452,8 @@
ASSERT(RunLoop::isMain());
RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion::processAssertionWasInvalidated() PID: %d", this, m_pid);
- if (auto* client = this->client())
- client->assertionWasInvalidated();
+ if (m_invalidationHandler)
+ m_invalidationHandler();
}
bool ProcessAssertion::isValid() const
@@ -497,8 +497,8 @@
void ProcessAndUIAssertion::uiAssertionWillExpireImminently()
{
- if (auto* client = this->client())
- client->uiAssertionWillExpireImminently();
+ if (m_uiAssertionExpirationHandler)
+ m_uiAssertionExpirationHandler();
}
void ProcessAndUIAssertion::processAssertionWasInvalidated()