Title: [253794] trunk/Source/WebKit
Revision
253794
Author
cdu...@apple.com
Date
2019-12-19 15:49:54 -0800 (Thu, 19 Dec 2019)

Log Message

Use a WeakHashSet for WKProcessAssertionBackgroundTaskManager._assertionsNeedingBackgroundTask
https://bugs.webkit.org/show_bug.cgi?id=205471

Reviewed by Ryosuke Niwa.

Use a WeakHashSet for WKProcessAssertionBackgroundTaskManager._assertionsNeedingBackgroundTask, instead
of a HashSet of raw pointers, for extra safety.

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

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (253793 => 253794)


--- trunk/Source/WebKit/ChangeLog	2019-12-19 23:47:47 UTC (rev 253793)
+++ trunk/Source/WebKit/ChangeLog	2019-12-19 23:49:54 UTC (rev 253794)
@@ -1,3 +1,18 @@
+2019-12-19  Chris Dumez  <cdu...@apple.com>
+
+        Use a WeakHashSet for WKProcessAssertionBackgroundTaskManager._assertionsNeedingBackgroundTask
+        https://bugs.webkit.org/show_bug.cgi?id=205471
+
+        Reviewed by Ryosuke Niwa.
+
+        Use a WeakHashSet for WKProcessAssertionBackgroundTaskManager._assertionsNeedingBackgroundTask, instead
+        of a HashSet of raw pointers, for extra safety.
+
+        * UIProcess/ios/ProcessAssertionIOS.mm:
+        (-[WKProcessAssertionBackgroundTaskManager removeAssertionNeedingBackgroundTask:]):
+        (-[WKProcessAssertionBackgroundTaskManager _notifyAssertionsOfImminentSuspension]):
+        (-[WKProcessAssertionBackgroundTaskManager _updateBackgroundTask]):
+
 2019-12-19  Brent Fulgham  <bfulg...@apple.com>
 
         Unblock iokit-get-property needed for frame buffer initialization

Modified: trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm (253793 => 253794)


--- trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm	2019-12-19 23:47:47 UTC (rev 253793)
+++ trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm	2019-12-19 23:49:54 UTC (rev 253794)
@@ -35,6 +35,7 @@
 #import <wtf/HashMap.h>
 #import <wtf/RunLoop.h>
 #import <wtf/Vector.h>
+#import <wtf/WeakHashSet.h>
 
 using WebKit::ProcessAndUIAssertion;
 
@@ -55,7 +56,7 @@
 @implementation WKProcessAssertionBackgroundTaskManager
 {
     UIBackgroundTaskIdentifier _backgroundTask;
-    HashSet<ProcessAndUIAssertion*> _assertionsNeedingBackgroundTask;
+    WeakHashSet<ProcessAndUIAssertion> _assertionsNeedingBackgroundTask;
     BOOL _applicationIsBackgrounded;
     dispatch_block_t _pendingTaskReleaseTask;
 }
@@ -104,7 +105,7 @@
 
 - (void)removeAssertionNeedingBackgroundTask:(ProcessAndUIAssertion&)assertion
 {
-    _assertionsNeedingBackgroundTask.remove(&assertion);
+    _assertionsNeedingBackgroundTask.remove(assertion);
     [self _updateBackgroundTask];
 }
 
@@ -112,9 +113,9 @@
 {
     ASSERT(RunLoop::isMain());
 
-    Vector<WeakPtr<ProcessAndUIAssertion>> assertionsNeedingBackgroundTask = WTF::map(_assertionsNeedingBackgroundTask, [](auto* assertion) {
-        return makeWeakPtr(*assertion);
-    });
+    Vector<WeakPtr<ProcessAndUIAssertion>> assertionsNeedingBackgroundTask;
+    for (auto& assertion : _assertionsNeedingBackgroundTask)
+        assertionsNeedingBackgroundTask.append(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.
@@ -155,7 +156,7 @@
 
 - (void)_updateBackgroundTask
 {
-    if (!_assertionsNeedingBackgroundTask.isEmpty() && _backgroundTask == UIBackgroundTaskInvalid) {
+    if (!_assertionsNeedingBackgroundTask.computesEmpty() && _backgroundTask == UIBackgroundTaskInvalid) {
         if (_applicationIsBackgrounded) {
             RELEASE_LOG_ERROR(ProcessSuspension, "%p - WKProcessAssertionBackgroundTaskManager: Ignored request to start a new background task because the application is already in the background", self);
             return;
@@ -185,7 +186,7 @@
 
             [self _scheduleReleaseTask];
         }];
-    } else if (_assertionsNeedingBackgroundTask.isEmpty())
+    } else if (_assertionsNeedingBackgroundTask.computesEmpty())
         [self _releaseBackgroundTask];
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to