Title: [252811] trunk/Source/WebKit
Revision
252811
Author
cdu...@apple.com
Date
2019-11-22 15:50:24 -0800 (Fri, 22 Nov 2019)

Log Message

[iOS] Copy assertions before iterating over them in _notifyAssertionsOfImminentSuspension
https://bugs.webkit.org/show_bug.cgi?id=204524
<rdar://problem/57265830>

Reviewed by Alexey Proskuryakov.

Copy assertions before iterating over them in _notifyAssertionsOfImminentSuspension and use WeakPtr
to make sure the assertions are still alive before calling uiAssertionWillExpireImminently() on
them. It is common for process assertions to get released when uiAssertionWillExpireImminently()
gets called, which would remove them from the _assertionsNeedingBackgroundTask vector we were
iterating on.

* UIProcess/ios/ProcessAssertionIOS.mm:
(-[WKProcessAssertionBackgroundTaskManager _notifyAssertionsOfImminentSuspension]):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (252810 => 252811)


--- trunk/Source/WebKit/ChangeLog	2019-11-22 23:30:43 UTC (rev 252810)
+++ trunk/Source/WebKit/ChangeLog	2019-11-22 23:50:24 UTC (rev 252811)
@@ -1,3 +1,20 @@
+2019-11-22  Chris Dumez  <cdu...@apple.com>
+
+        [iOS] Copy assertions before iterating over them in _notifyAssertionsOfImminentSuspension
+        https://bugs.webkit.org/show_bug.cgi?id=204524
+        <rdar://problem/57265830>
+
+        Reviewed by Alexey Proskuryakov.
+
+        Copy assertions before iterating over them in _notifyAssertionsOfImminentSuspension and use WeakPtr
+        to make sure the assertions are still alive before calling uiAssertionWillExpireImminently() on
+        them. It is common for process assertions to get released when uiAssertionWillExpireImminently()
+        gets called, which would remove them from the _assertionsNeedingBackgroundTask vector we were
+        iterating on.
+
+        * UIProcess/ios/ProcessAssertionIOS.mm:
+        (-[WKProcessAssertionBackgroundTaskManager _notifyAssertionsOfImminentSuspension]):
+
 2019-11-22  Alex Christensen  <achristen...@webkit.org>
 
         Null check callback in NetworkConnectionToWebProcess::didDeliverMessagePortMessages

Modified: trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm (252810 => 252811)


--- trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm	2019-11-22 23:30:43 UTC (rev 252810)
+++ trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm	2019-11-22 23:50:24 UTC (rev 252811)
@@ -112,8 +112,16 @@
 {
     ASSERT(RunLoop::isMain());
 
-    for (auto* assertion : copyToVector(_assertionsNeedingBackgroundTask))
-        assertion->uiAssertionWillExpireImminently();
+    Vector<WeakPtr<ProcessAndUIAssertion>> assertionsNeedingBackgroundTask = WTF::map(_assertionsNeedingBackgroundTask, [](auto* assertion) {
+        return makeWeakPtr(*assertion);
+    });
+
+    // Note that we don't expect clients to register new assertions when getting notified that the UI assertion will expire imminently.
+    // If clients were to do so, then those new assertions would not get notified of the imminent suspension.
+    for (auto assertion : assertionsNeedingBackgroundTask) {
+        if (assertion)
+            assertion->uiAssertionWillExpireImminently();
+    }
 }
 
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to