Title: [240954] trunk/Source/WebKit
Revision
240954
Author
beid...@apple.com
Date
2019-02-04 17:27:23 -0800 (Mon, 04 Feb 2019)

Log Message

Take additional process assertion while downloading.
<rdar://problem/47741356> and https://bugs.webkit.org/show_bug.cgi?id=194239

Reviewed by Chris Dumez.

When the first download starts, grab this new assertion.
When the last download ends, release it.

* Configurations/Network-iOS.entitlements:

* NetworkProcess/Downloads/DownloadManager.cpp:
(WebKit::DownloadManager::dataTaskBecameDownloadTask):
(WebKit::DownloadManager::downloadFinished):
* NetworkProcess/Downloads/DownloadManager.h:

* Platform/spi/ios/AssertionServicesSPI.h:

* UIProcess/ProcessAssertion.cpp:
(WebKit::ProcessAssertion::ProcessAssertion):
* UIProcess/ProcessAssertion.h:
(WebKit::ProcessAssertion::ProcessAssertion):

* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::didSetAssertionState):

* UIProcess/ios/ProcessAssertionIOS.mm:
(WebKit::flagsForState):
(WebKit::reasonForState):
(WebKit::ProcessAssertion::ProcessAssertion):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (240953 => 240954)


--- trunk/Source/WebKit/ChangeLog	2019-02-05 01:16:28 UTC (rev 240953)
+++ trunk/Source/WebKit/ChangeLog	2019-02-05 01:27:23 UTC (rev 240954)
@@ -1,3 +1,35 @@
+2019-02-04  Brady Eidson  <beid...@apple.com>
+
+        Take additional process assertion while downloading.
+        <rdar://problem/47741356> and https://bugs.webkit.org/show_bug.cgi?id=194239
+
+        Reviewed by Chris Dumez.
+
+        When the first download starts, grab this new assertion.
+        When the last download ends, release it.
+
+        * Configurations/Network-iOS.entitlements:
+
+        * NetworkProcess/Downloads/DownloadManager.cpp:
+        (WebKit::DownloadManager::dataTaskBecameDownloadTask):
+        (WebKit::DownloadManager::downloadFinished):
+        * NetworkProcess/Downloads/DownloadManager.h:
+
+        * Platform/spi/ios/AssertionServicesSPI.h:
+
+        * UIProcess/ProcessAssertion.cpp:
+        (WebKit::ProcessAssertion::ProcessAssertion):
+        * UIProcess/ProcessAssertion.h:
+        (WebKit::ProcessAssertion::ProcessAssertion):
+
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::didSetAssertionState):
+
+        * UIProcess/ios/ProcessAssertionIOS.mm:
+        (WebKit::flagsForState):
+        (WebKit::reasonForState):
+        (WebKit::ProcessAssertion::ProcessAssertion):
+
 2019-02-04  Said Abou-Hallawa  <s...@apple.com>
 
         [CG] Enable setAdditionalSupportedImageTypes for WK1

Modified: trunk/Source/WebKit/Configurations/Network-iOS.entitlements (240953 => 240954)


--- trunk/Source/WebKit/Configurations/Network-iOS.entitlements	2019-02-05 01:16:28 UTC (rev 240953)
+++ trunk/Source/WebKit/Configurations/Network-iOS.entitlements	2019-02-05 01:27:23 UTC (rev 240954)
@@ -16,6 +16,8 @@
 	<array>
 		<string>com.apple.WebKit.Networking</string>
 	</array>
+	<key>com.apple.multitasking.systemappassertions</key>
+	<true/>
 	<key>com.apple.private.memorystatus</key>
 	<true/>
 </dict>

Modified: trunk/Source/WebKit/NetworkProcess/Downloads/DownloadManager.cpp (240953 => 240954)


--- trunk/Source/WebKit/NetworkProcess/Downloads/DownloadManager.cpp	2019-02-05 01:16:28 UTC (rev 240953)
+++ trunk/Source/WebKit/NetworkProcess/Downloads/DownloadManager.cpp	2019-02-05 01:27:23 UTC (rev 240954)
@@ -71,6 +71,13 @@
     ASSERT(!m_downloads.contains(downloadID));
     m_downloadsAfterDestinationDecided.remove(downloadID);
     m_downloads.add(downloadID, WTFMove(download));
+
+#if ENABLE(TAKE_DOWNLOAD_ASSERTION)
+    if (m_downloads.size() == 1) {
+        ASSERT(!m_downloadAssertion);
+        m_downloadAssertion = std::make_unique<ProcessAssertion>(getpid(), "WebKit downloads"_s, AssertionState::Download);
+    }
+#endif
 }
 
 void DownloadManager::continueWillSendRequest(DownloadID downloadID, WebCore::ResourceRequest&& request)
@@ -172,6 +179,13 @@
 {
     ASSERT(m_downloads.contains(download->downloadID()));
     m_downloads.remove(download->downloadID());
+    
+#if ENABLE(TAKE_DOWNLOAD_ASSERTION)
+    if (m_downloads.isEmpty()) {
+        ASSERT(m_downloadAssertion);
+        m_downloadAssertion = nullptr;
+    }
+#endif
 }
 
 void DownloadManager::didCreateDownload()

Modified: trunk/Source/WebKit/NetworkProcess/Downloads/DownloadManager.h (240953 => 240954)


--- trunk/Source/WebKit/NetworkProcess/Downloads/DownloadManager.h	2019-02-05 01:16:28 UTC (rev 240953)
+++ trunk/Source/WebKit/NetworkProcess/Downloads/DownloadManager.h	2019-02-05 01:27:23 UTC (rev 240954)
@@ -28,6 +28,7 @@
 #include "DownloadID.h"
 #include "NetworkDataTask.h"
 #include "PendingDownload.h"
+#include "ProcessAssertion.h"
 #include "SandboxExtension.h"
 #include <WebCore/NotImplemented.h>
 #include <wtf/Forward.h>
@@ -113,6 +114,10 @@
     HashMap<DownloadID, std::pair<RefPtr<NetworkDataTask>, ResponseCompletionHandler>> m_downloadsWaitingForDestination;
     HashMap<DownloadID, RefPtr<NetworkDataTask>> m_downloadsAfterDestinationDecided;
     HashMap<DownloadID, std::unique_ptr<Download>> m_downloads;
+
+#if ENABLE(TAKE_DOWNLOAD_ASSERTION)
+    std::unique_ptr<ProcessAssertion> m_downloadAssertion;
+#endif
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/Platform/spi/ios/AssertionServicesSPI.h (240953 => 240954)


--- trunk/Source/WebKit/Platform/spi/ios/AssertionServicesSPI.h	2019-02-05 01:16:28 UTC (rev 240953)
+++ trunk/Source/WebKit/Platform/spi/ios/AssertionServicesSPI.h	2019-02-05 01:27:23 UTC (rev 240954)
@@ -69,6 +69,7 @@
 
 enum {
     BKSProcessAssertionReasonExtension = 13,
+    BKSProcessAssertionReasonFinishTaskUnbounded = 10004,
 };
 typedef uint32_t BKSProcessAssertionReason;
 

Modified: trunk/Source/WebKit/UIProcess/ProcessAssertion.cpp (240953 => 240954)


--- trunk/Source/WebKit/UIProcess/ProcessAssertion.cpp	2019-02-05 01:16:28 UTC (rev 240953)
+++ trunk/Source/WebKit/UIProcess/ProcessAssertion.cpp	2019-02-05 01:27:23 UTC (rev 240954)
@@ -35,6 +35,11 @@
 {
 }
 
+ProcessAssertion::ProcessAssertion(ProcessID, const String&, AssertionState assertionState, Function<void()>&&)
+    : m_assertionState(assertionState)
+{
+}
+
 ProcessAssertion::~ProcessAssertion()
 {
 }

Modified: trunk/Source/WebKit/UIProcess/ProcessAssertion.h (240953 => 240954)


--- trunk/Source/WebKit/UIProcess/ProcessAssertion.h	2019-02-05 01:16:28 UTC (rev 240953)
+++ trunk/Source/WebKit/UIProcess/ProcessAssertion.h	2019-02-05 01:27:23 UTC (rev 240954)
@@ -28,6 +28,7 @@
 
 #include <wtf/Function.h>
 #include <wtf/ProcessID.h>
+#include <wtf/text/WTFString.h>
 
 #if !OS(WINDOWS)
 #include <unistd.h>
@@ -44,6 +45,7 @@
 enum class AssertionState {
     Suspended,
     Background,
+    Download,
     Foreground
 };
 
@@ -60,6 +62,7 @@
 {
 public:
     ProcessAssertion(ProcessID, AssertionState, Function<void()>&& invalidationCallback = { });
+    ProcessAssertion(ProcessID, const String& reason, AssertionState, Function<void()>&& invalidationCallback = { });
     virtual ~ProcessAssertion();
 
     virtual void setClient(ProcessAssertionClient& client) { m_client = &client; }

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp (240953 => 240954)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2019-02-05 01:16:28 UTC (rev 240953)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2019-02-05 01:27:23 UTC (rev 240954)
@@ -1077,6 +1077,9 @@
         for (auto& page : m_pageMap.values())
             page->processWillBecomeForeground();
         break;
+    
+    case AssertionState::Download:
+        ASSERT_NOT_REACHED();
     }
 
     ASSERT(!m_backgroundToken || !m_foregroundToken);

Modified: trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm (240953 => 240954)


--- trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm	2019-02-05 01:16:28 UTC (rev 240953)
+++ trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm	2019-02-05 01:27:23 UTC (rev 240954)
@@ -153,6 +153,7 @@
     case AssertionState::Suspended:
         return suspendedTabFlags;
     case AssertionState::Background:
+    case AssertionState::Download:
         return backgroundTabFlags;
     case AssertionState::Foreground:
         return foregroundTabFlags;
@@ -159,7 +160,24 @@
     }
 }
 
+static BKSProcessAssertionReason reasonForState(AssertionState assertionState)
+{
+    switch (assertionState) {
+    case AssertionState::Download:
+        return BKSProcessAssertionReasonFinishTaskUnbounded;
+    case AssertionState::Suspended:
+    case AssertionState::Background:
+    case AssertionState::Foreground:
+        return BKSProcessAssertionReasonExtension;
+    }
+}
+
 ProcessAssertion::ProcessAssertion(pid_t pid, AssertionState assertionState, Function<void()>&& invalidationCallback)
+    : ProcessAssertion(pid, "Web content visibility"_s, assertionState, WTFMove(invalidationCallback))
+{
+}
+
+ProcessAssertion::ProcessAssertion(pid_t pid, const String& name, AssertionState assertionState, Function<void()>&& invalidationCallback)
     : m_invalidationCallback(WTFMove(invalidationCallback))
     , m_assertionState(assertionState)
 {
@@ -166,7 +184,7 @@
     auto weakThis = makeWeakPtr(*this);
     BKSProcessAssertionAcquisitionHandler handler = ^(BOOL acquired) {
         if (!acquired) {
-            RELEASE_LOG_ERROR(ProcessSuspension, " %p - ProcessAssertion() Unable to acquire assertion for process with PID %d", this, pid);
+            RELEASE_LOG_ERROR(ProcessSuspension, " %p - ProcessAssertion() PID %d Unable to acquire assertion for process with PID %d", this, getpid(), pid);
             ASSERT_NOT_REACHED();
             dispatch_async(dispatch_get_main_queue(), ^{
                 if (weakThis)
@@ -174,8 +192,9 @@
             });
         }
     };
-    RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() Acquiring assertion for process with PID %d", this, pid);
-    m_assertion = adoptNS([[BKSProcessAssertion alloc] initWithPID:pid flags:flagsForState(assertionState) reason:BKSProcessAssertionReasonExtension name:@"Web content visibility" withHandler:handler]);
+    RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() PID %d acquiring assertion for process with PID %d", this, getpid(), pid);
+    
+    m_assertion = adoptNS([[BKSProcessAssertion alloc] initWithPID:pid flags:flagsForState(assertionState) reason:reasonForState(assertionState) name:(NSString *)name withHandler:handler]);
     m_assertion.get().invalidationHandler = ^() {
         dispatch_async(dispatch_get_main_queue(), ^{
             RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() Process assertion for process with PID %d was invalidated", this, pid);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to