- Revision
- 242580
- Author
- [email protected]
- Date
- 2019-03-06 16:43:24 -0800 (Wed, 06 Mar 2019)
Log Message
[iOS] ProcessDidResume() IPC should be sent upon resuming when ProcessWillSuspendImminently() IPC was sent
https://bugs.webkit.org/show_bug.cgi?id=195382
<rdar://problem/48642739>
Reviewed by Geoffrey Garen.
ProcessDidResume() IPC should be sent upon resuming when ProcessWillSuspendImminently() IPC was sent. Previously,
we only send ProcessDidResume() to the WebProcess if PrepareToSuspend() was sent, not when the more urgent
ProcessWillSuspendImminently() IPC was sent.
This mismatch has lead to bugs because the WebProcess does not know it got resumed and failed to unfreeze the
layers it froze upon suspension.
* UIProcess/ProcessAssertion.h:
(WebKit::ProcessAssertionClient::~ProcessAssertionClient):
* UIProcess/ProcessThrottler.cpp:
(WebKit::ProcessThrottler::updateAssertion):
(WebKit::ProcessThrottler::uiAssertionWillExpireImminently):
(WebKit::ProcessThrottler::assertionWillExpireImminently): Deleted.
* UIProcess/ProcessThrottler.h:
* UIProcess/ios/ProcessAssertionIOS.mm:
(-[WKProcessAssertionBackgroundTaskManager _notifyClientsOfImminentSuspension]):
(WebKit::ProcessAssertion::~ProcessAssertion):
(WebKit::ProcessAndUIAssertion::~ProcessAndUIAssertion):
(WebKit::ProcessAndUIAssertion::setClient):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::didCompletePageTransition):
Revert change that was landed in r242098 to work around this ProcessThrottler bug.
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::applicationWillEnterForeground):
Revert change that was landed in r242554 to work around this ProcessThrottler bug.
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (242579 => 242580)
--- trunk/Source/WebKit/ChangeLog 2019-03-07 00:38:01 UTC (rev 242579)
+++ trunk/Source/WebKit/ChangeLog 2019-03-07 00:43:24 UTC (rev 242580)
@@ -1,3 +1,41 @@
+2019-03-06 Chris Dumez <[email protected]>
+
+ [iOS] ProcessDidResume() IPC should be sent upon resuming when ProcessWillSuspendImminently() IPC was sent
+ https://bugs.webkit.org/show_bug.cgi?id=195382
+ <rdar://problem/48642739>
+
+ Reviewed by Geoffrey Garen.
+
+ ProcessDidResume() IPC should be sent upon resuming when ProcessWillSuspendImminently() IPC was sent. Previously,
+ we only send ProcessDidResume() to the WebProcess if PrepareToSuspend() was sent, not when the more urgent
+ ProcessWillSuspendImminently() IPC was sent.
+
+ This mismatch has lead to bugs because the WebProcess does not know it got resumed and failed to unfreeze the
+ layers it froze upon suspension.
+
+ * UIProcess/ProcessAssertion.h:
+ (WebKit::ProcessAssertionClient::~ProcessAssertionClient):
+
+ * UIProcess/ProcessThrottler.cpp:
+ (WebKit::ProcessThrottler::updateAssertion):
+ (WebKit::ProcessThrottler::uiAssertionWillExpireImminently):
+ (WebKit::ProcessThrottler::assertionWillExpireImminently): Deleted.
+
+ * UIProcess/ProcessThrottler.h:
+ * UIProcess/ios/ProcessAssertionIOS.mm:
+ (-[WKProcessAssertionBackgroundTaskManager _notifyClientsOfImminentSuspension]):
+ (WebKit::ProcessAssertion::~ProcessAssertion):
+ (WebKit::ProcessAndUIAssertion::~ProcessAndUIAssertion):
+ (WebKit::ProcessAndUIAssertion::setClient):
+
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::didCompletePageTransition):
+ Revert change that was landed in r242098 to work around this ProcessThrottler bug.
+
+ * WebProcess/WebPage/ios/WebPageIOS.mm:
+ (WebKit::WebPage::applicationWillEnterForeground):
+ Revert change that was landed in r242554 to work around this ProcessThrottler bug.
+
2019-03-06 Alex Christensen <[email protected]>
Add gettid to allowed syscalls on Mac
Modified: trunk/Source/WebKit/UIProcess/ProcessAssertion.h (242579 => 242580)
--- trunk/Source/WebKit/UIProcess/ProcessAssertion.h 2019-03-07 00:38:01 UTC (rev 242579)
+++ trunk/Source/WebKit/UIProcess/ProcessAssertion.h 2019-03-07 00:43:24 UTC (rev 242580)
@@ -51,8 +51,8 @@
class ProcessAssertionClient {
public:
- virtual ~ProcessAssertionClient() { };
- virtual void assertionWillExpireImminently() = 0;
+ virtual ~ProcessAssertionClient() { }
+ virtual void uiAssertionWillExpireImminently() = 0;
};
class ProcessAssertion
Modified: trunk/Source/WebKit/UIProcess/ProcessThrottler.cpp (242579 => 242580)
--- trunk/Source/WebKit/UIProcess/ProcessThrottler.cpp 2019-03-07 00:38:01 UTC (rev 242579)
+++ trunk/Source/WebKit/UIProcess/ProcessThrottler.cpp 2019-03-07 00:43:24 UTC (rev 242580)
@@ -68,10 +68,12 @@
void ProcessThrottler::updateAssertion()
{
+ bool shouldBeRunnable = m_foregroundCounter.value() || m_backgroundCounter.value();
+
// 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 && m_assertion->state() != AssertionState::Suspended && !m_foregroundCounter.value() && !m_backgroundCounter.value()) {
+ if (m_assertion && m_assertion->state() != AssertionState::Suspended && !shouldBeRunnable) {
++m_suspendMessageCount;
RELEASE_LOG(ProcessSuspension, "%p - ProcessThrottler::updateAssertion() sending PrepareToSuspend IPC", this);
m_process.sendPrepareToSuspend();
@@ -81,14 +83,16 @@
return;
}
- bool shouldBeRunnable = m_foregroundCounter.value() || m_backgroundCounter.value();
+ if (shouldBeRunnable) {
+ // If we're currently waiting for the Web process to do suspension cleanup, but no longer need to be suspended, tell the Web process to cancel the cleanup.
+ if (m_suspendTimer.isActive())
+ m_process.sendCancelPrepareToSuspend();
- // If we're currently waiting for the Web process to do suspension cleanup, but no longer need to be suspended, tell the Web process to cancel the cleanup.
- if (m_suspendTimer.isActive() && shouldBeRunnable)
- m_process.sendCancelPrepareToSuspend();
-
- if (m_assertion && m_assertion->state() == AssertionState::Suspended && shouldBeRunnable)
- m_process.sendProcessDidResume();
+ if ((m_assertion && m_assertion->state() == AssertionState::Suspended) || m_uiAssertionExpired) {
+ m_process.sendProcessDidResume();
+ m_uiAssertionExpired = false;
+ }
+ }
updateAssertionNow();
}
@@ -125,9 +129,10 @@
ASSERT(m_suspendMessageCount >= 0);
}
-void ProcessThrottler::assertionWillExpireImminently()
+void ProcessThrottler::uiAssertionWillExpireImminently()
{
m_process.sendProcessWillSuspendImminently();
+ m_uiAssertionExpired = true;
}
}
Modified: trunk/Source/WebKit/UIProcess/ProcessThrottler.h (242579 => 242580)
--- trunk/Source/WebKit/UIProcess/ProcessThrottler.h 2019-03-07 00:38:01 UTC (rev 242579)
+++ trunk/Source/WebKit/UIProcess/ProcessThrottler.h 2019-03-07 00:43:24 UTC (rev 242580)
@@ -68,7 +68,7 @@
void suspendTimerFired();
// ProcessAssertionClient
- void assertionWillExpireImminently() override;
+ void uiAssertionWillExpireImminently() override;
ProcessThrottlerClient& m_process;
std::unique_ptr<ProcessAssertion> m_assertion;
@@ -77,6 +77,7 @@
BackgroundActivityCounter m_backgroundCounter;
int m_suspendMessageCount { 0 };
bool m_shouldTakeUIBackgroundAssertion;
+ bool m_uiAssertionExpired { false };
};
inline ProcessThrottler::ForegroundActivityToken ProcessThrottler::foregroundActivityToken() const
Modified: trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm (242579 => 242580)
--- trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm 2019-03-07 00:38:01 UTC (rev 242579)
+++ trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm 2019-03-07 00:43:24 UTC (rev 242580)
@@ -98,7 +98,7 @@
ASSERT(RunLoop::isMain());
for (auto* client : copyToVector(_clients))
- client->assertionWillExpireImminently();
+ client->uiAssertionWillExpireImminently();
}
- (void)_updateBackgroundTask
@@ -208,9 +208,6 @@
{
m_assertion.get().invalidationHandler = nil;
- if (ProcessAssertionClient* client = this->client())
- [[WKProcessAssertionBackgroundTaskManager shared] removeClient:*client];
-
RELEASE_LOG(ProcessSuspension, "%p - ~ProcessAssertion() Releasing process assertion", this);
[m_assertion invalidate];
}
@@ -259,6 +256,9 @@
{
if (m_isHoldingBackgroundAssertion)
[[WKProcessAssertionBackgroundTaskManager shared] decrementNeedsToRunInBackgroundCount];
+
+ if (auto* client = this->client())
+ [[WKProcessAssertionBackgroundTaskManager shared] removeClient:*client];
}
void ProcessAndUIAssertion::setState(AssertionState assertionState)
@@ -270,7 +270,7 @@
void ProcessAndUIAssertion::setClient(ProcessAssertionClient& newClient)
{
[[WKProcessAssertionBackgroundTaskManager shared] addClient:newClient];
- if (ProcessAssertionClient* oldClient = this->client())
+ if (auto* oldClient = this->client())
[[WKProcessAssertionBackgroundTaskManager shared] removeClient:*oldClient];
ProcessAssertion::setClient(newClient);
}
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (242579 => 242580)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2019-03-07 00:38:01 UTC (rev 242579)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2019-03-07 00:43:24 UTC (rev 242580)
@@ -3147,10 +3147,9 @@
if (m_LayerTreeFreezeReasons.contains(LayerTreeFreezeReason::ProcessSuspended)) {
RELEASE_LOG_ERROR(ProcessSuspension, "%p - WebPage (PageID=%" PRIu64 ") - LayerTreeFreezeReason::ProcessSuspended was set when removing LayerTreeFreezeReason::PageTransition; current reasons are %d",
this, m_pageID, m_LayerTreeFreezeReasons.toRaw());
+ ASSERT_NOT_REACHED();
}
- // FIXME: In iOS, we sometimes never unset ProcessSuspended. See <rdar://problem/48154508>.
- unfreezeLayerTree(LayerTreeFreezeReason::ProcessSuspended);
RELEASE_LOG_IF_ALLOWED("%p - WebPage - Did complete page transition", this);
bool isInitialEmptyDocument = !m_mainFrame;
Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (242579 => 242580)
--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2019-03-07 00:38:01 UTC (rev 242579)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2019-03-07 00:43:24 UTC (rev 242580)
@@ -3010,8 +3010,6 @@
m_isSuspendedUnderLock = false;
cancelMarkLayersVolatile();
- // FIXME: In iOS, we sometimes never unset ProcessSuspended. See <rdar://problem/48538837>.
- unfreezeLayerTree(LayerTreeFreezeReason::ProcessSuspended);
unfreezeLayerTree(LayerTreeFreezeReason::BackgroundApplication);
[[NSNotificationCenter defaultCenter] postNotificationName:WebUIApplicationWillEnterForegroundNotification object:nil userInfo:@{@"isSuspendedUnderLock": @(isSuspendedUnderLock)}];