Have the UIProcess take the UnboundedNetworking assertion when downloads are in progress.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Mar 2019 23:58:52 +0000 (23:58 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Mar 2019 23:58:52 +0000 (23:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195468

Reviewed by Andy Estes.

* UIProcess/Downloads/DownloadProxyMap.cpp:
(WebKit::DownloadProxyMap::DownloadProxyMap):
(WebKit::DownloadProxyMap::createDownloadProxy): If this is the first download, and the process has the entitlement,
  take the assertion.
(WebKit::DownloadProxyMap::downloadFinished):
(WebKit::DownloadProxyMap::processDidClose):
* UIProcess/Downloads/DownloadProxyMap.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242662 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/Downloads/DownloadProxyMap.cpp
Source/WebKit/UIProcess/Downloads/DownloadProxyMap.h

index 2447597..bef18c5 100644 (file)
@@ -1,3 +1,18 @@
+2019-03-08  Brady Eidson  <beidson@apple.com>
+
+        Have the UIProcess take the UnboundedNetworking assertion when downloads are in progress.
+        https://bugs.webkit.org/show_bug.cgi?id=195468
+
+        Reviewed by Andy Estes.
+
+        * UIProcess/Downloads/DownloadProxyMap.cpp:
+        (WebKit::DownloadProxyMap::DownloadProxyMap):
+        (WebKit::DownloadProxyMap::createDownloadProxy): If this is the first download, and the process has the entitlement,
+          take the assertion.
+        (WebKit::DownloadProxyMap::downloadFinished):
+        (WebKit::DownloadProxyMap::processDidClose):
+        * UIProcess/Downloads/DownloadProxyMap.h:
+
 2019-03-08  Chris Dumez  <cdumez@apple.com>
 
         Add assertions to help debug a WebProcessCache crash
index 2e3f7f8..9699e42 100644 (file)
 #include "DownloadProxy.h"
 #include "DownloadProxyMessages.h"
 #include "MessageReceiverMap.h"
+#include "ProcessAssertion.h"
 #include <wtf/StdLibExtras.h>
 
+#if PLATFORM(COCOA)
+#include <wtf/cocoa/Entitlements.h>
+#endif
+
 namespace WebKit {
 
 DownloadProxyMap::DownloadProxyMap(NetworkProcessProxy& process)
     : m_process(&process)
+#if PLATFORM(COCOA)
+    , m_shouldTakeAssertion(WTF::processHasEntitlement("com.apple.multitasking.systemappassertions"))
+#endif
 {
 }
 
@@ -49,6 +57,11 @@ DownloadProxy* DownloadProxyMap::createDownloadProxy(WebProcessPool& processPool
     auto downloadProxy = DownloadProxy::create(*this, processPool, resourceRequest);
     m_downloads.set(downloadProxy->downloadID(), downloadProxy.copyRef());
 
+    if (m_downloads.size() == 1 && m_shouldTakeAssertion) {
+        ASSERT(!m_downloadAssertion);
+        m_downloadAssertion = std::make_unique<ProcessAssertion>(getCurrentProcessID(), "WebKit downloads"_s, AssertionState::UnboundedNetworking);
+    }
+
     m_process->addMessageReceiver(Messages::DownloadProxy::messageReceiverName(), downloadProxy->downloadID().downloadID(), downloadProxy.get());
 
     return downloadProxy.ptr();
@@ -63,6 +76,11 @@ void DownloadProxyMap::downloadFinished(DownloadProxy* downloadProxy)
     m_process->removeMessageReceiver(Messages::DownloadProxy::messageReceiverName(), downloadID.downloadID());
     downloadProxy->invalidate();
     m_downloads.remove(downloadID);
+
+    if (m_downloads.isEmpty() && m_shouldTakeAssertion) {
+        ASSERT(m_downloadAssertion);
+        m_downloadAssertion = nullptr;
+    }
 }
 
 void DownloadProxyMap::processDidClose()
@@ -75,6 +93,7 @@ void DownloadProxyMap::processDidClose()
     }
 
     m_downloads.clear();
+    m_downloadAssertion = nullptr;
     m_process = nullptr;
 }
 
index 84583dd..03c8cf0 100644 (file)
@@ -37,6 +37,7 @@ namespace WebKit {
 
 class DownloadProxy;
 class NetworkProcessProxy;
+class ProcessAssertion;
 class WebProcessPool;
 
 class DownloadProxyMap {
@@ -57,6 +58,9 @@ public:
 private:
     NetworkProcessProxy* m_process;
     HashMap<DownloadID, RefPtr<DownloadProxy>> m_downloads;
+
+    bool m_shouldTakeAssertion { false };
+    std::unique_ptr<ProcessAssertion> m_downloadAssertion;
 };
 
 } // namespace WebKit