WebKit Bugzilla
Attachment 361200 Details for
Bug 194294
: Add a new DownloadMap type that manages taking an assertion automatically
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Patch
bug-194294-20190205105357.patch (text/plain), 16.07 KB, created by
Brady Eidson
on 2019-02-05 10:53:58 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Brady Eidson
Created:
2019-02-05 10:53:58 PST
Size:
16.07 KB
patch
obsolete
>Subversion Revision: 240975 >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 9a66bc17985e6808cbd6d3b2b65d49b7d8aa5b25..74f0348ed067ccd1fb85c4554c10e96dac753c05 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,68 @@ >+2019-02-05 Brady Eidson <beidson@apple.com> >+ >+ Add a new DownloadMap type that manages taking an assertion automatically. >+ https://bugs.webkit.org/show_bug.cgi?id=194294 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ If we don't need the download assertion, we use a vanilla HashMap like today. >+ If we need the download assertion, we use the new DownloadMap class instead. >+ >+ The new DownloadMap is a wrapper around a HashMap that also creates/destroys the assertion as needed. >+ >+ * NetworkProcess/Downloads/DownloadManager.cpp: >+ (WebKit::DownloadManager::dataTaskBecameDownloadTask): >+ (WebKit::DownloadManager::downloadFinished): >+ * NetworkProcess/Downloads/DownloadManager.h: >+ >+ * NetworkProcess/Downloads/DownloadMap.cpp: Added. >+ (WebKit::DownloadMap::get const): >+ (WebKit::DownloadMap::isEmpty const): >+ (WebKit::DownloadMap::size const): >+ (WebKit::DownloadMap::contains const): >+ (WebKit::DownloadMap::add): >+ (WebKit::DownloadMap::remove): >+ * NetworkProcess/Downloads/DownloadMap.h: Added. >+ >+ * Sources.txt: >+ >+ * UIProcess/ios/ProcessAssertionIOS.mm: >+ (WebKit::ProcessAssertion::ProcessAssertion): >+ >+ * WebKit.xcodeproj/project.pbxproj: >+ >+2019-02-04 Brady Eidson <beidson@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-05 Alex Christensen <achristensen@webkit.org> > > Protect globalWebSocketStreamMap with a Lock >diff --git a/Source/WebKit/NetworkProcess/Downloads/DownloadManager.cpp b/Source/WebKit/NetworkProcess/Downloads/DownloadManager.cpp >index da377b89469963307205ffd01f6b2b61f7b73967..4ebf32b4e29bff3358b6685b03f3ba0ea3a01a70 100644 >--- a/Source/WebKit/NetworkProcess/Downloads/DownloadManager.cpp >+++ b/Source/WebKit/NetworkProcess/Downloads/DownloadManager.cpp >@@ -71,13 +71,6 @@ void DownloadManager::dataTaskBecameDownloadTask(DownloadID downloadID, std::uni > 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) >@@ -180,12 +173,6 @@ void DownloadManager::downloadFinished(Download* download) > 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() >diff --git a/Source/WebKit/NetworkProcess/Downloads/DownloadManager.h b/Source/WebKit/NetworkProcess/Downloads/DownloadManager.h >index ffe1ad045a95f246ceffc60a353549b75b926fe3..ff11dfb86a74b716c93be87026a6a2a6547aa492 100644 >--- a/Source/WebKit/NetworkProcess/Downloads/DownloadManager.h >+++ b/Source/WebKit/NetworkProcess/Downloads/DownloadManager.h >@@ -26,9 +26,9 @@ > #pragma once > > #include "DownloadID.h" >+#include "DownloadMap.h" > #include "NetworkDataTask.h" > #include "PendingDownload.h" >-#include "ProcessAssertion.h" > #include "SandboxExtension.h" > #include <WebCore/NotImplemented.h> > #include <wtf/Forward.h> >@@ -113,11 +113,7 @@ private: > HashMap<DownloadID, std::unique_ptr<PendingDownload>> m_pendingDownloads; > 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 >+ DownloadMap m_downloads; > }; > > } // namespace WebKit >diff --git a/Source/WebKit/NetworkProcess/Downloads/DownloadMap.cpp b/Source/WebKit/NetworkProcess/Downloads/DownloadMap.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..b2baa33263193aaf658a21dbb3055811c733971f >--- /dev/null >+++ b/Source/WebKit/NetworkProcess/Downloads/DownloadMap.cpp >@@ -0,0 +1,80 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+#include "DownloadMap.h" >+ >+#if ENABLE(TAKE_DOWNLOAD_ASSERTION) >+ >+#include "Download.h" >+ >+namespace WebKit { >+ >+ >+Download* DownloadMap::get(DownloadID downloadID) const >+{ >+ return m_downloads.get(downloadID); >+} >+ >+bool DownloadMap::isEmpty() const >+{ >+ return m_downloads.isEmpty(); >+} >+ >+uint64_t DownloadMap::size() const >+{ >+ return m_downloads.size(); >+} >+ >+bool DownloadMap::contains(DownloadID downloadID) const >+{ >+ return m_downloads.contains(downloadID); >+} >+ >+DownloadMap::DownloadMapType::AddResult DownloadMap::add(DownloadID downloadID, std::unique_ptr<Download>&& download) >+{ >+ auto result = m_downloads.add(downloadID, WTFMove(download)); >+ if (m_downloads.size() == 1) { >+ ASSERT(!m_downloadAssertion); >+ m_downloadAssertion = std::make_unique<ProcessAssertion>(getpid(), "WebKit downloads"_s, AssertionState::Download); >+ } >+ >+ return result; >+} >+ >+bool DownloadMap::remove(DownloadID downloadID) >+{ >+ auto result = m_downloads.remove(downloadID); >+ if (m_downloads.isEmpty()) { >+ ASSERT(m_downloadAssertion); >+ m_downloadAssertion = nullptr; >+ } >+ >+ return result; >+} >+ >+} // namespace WebKit >+ >+#endif // ENABLE(TAKE_DOWNLOAD_ASSERTION) >diff --git a/Source/WebKit/NetworkProcess/Downloads/DownloadMap.h b/Source/WebKit/NetworkProcess/Downloads/DownloadMap.h >new file mode 100644 >index 0000000000000000000000000000000000000000..9843a83d9e8bcad23a71d554d7b5f7fdbdacc177 >--- /dev/null >+++ b/Source/WebKit/NetworkProcess/Downloads/DownloadMap.h >@@ -0,0 +1,59 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#include "DownloadID.h" >+#include "ProcessAssertion.h" >+#include <wtf/HashMap.h> >+ >+namespace WebKit { >+ >+class Download; >+ >+#if !ENABLE(TAKE_DOWNLOAD_ASSERTION) >+typedef HashMap<DownloadID, std::unique_ptr<Download>> DownloadMap; >+#else >+ >+class DownloadMap { >+public: >+ typedef HashMap<DownloadID, std::unique_ptr<Download>> DownloadMapType; >+ >+ Download* get(DownloadID) const; >+ bool isEmpty() const; >+ uint64_t size() const; >+ bool contains(DownloadID) const; >+ >+ DownloadMapType::AddResult add(DownloadID, std::unique_ptr<Download>&&); >+ bool remove(DownloadID); >+ >+private: >+ DownloadMapType m_downloads; >+ std::unique_ptr<ProcessAssertion> m_downloadAssertion; >+}; >+ >+#endif // !ENABLE(TAKE_DOWNLOAD_ASSERTION) >+ >+} // namespace WebKit >diff --git a/Source/WebKit/Sources.txt b/Source/WebKit/Sources.txt >index d2595d76b3e9d27400c570f1e81adac107311332..b39d264c8f8f6576439cdcdaf45c7caa71e5b9be 100644 >--- a/Source/WebKit/Sources.txt >+++ b/Source/WebKit/Sources.txt >@@ -48,6 +48,7 @@ NetworkProcess/Cookies/WebCookieManager.cpp > > NetworkProcess/Downloads/Download.cpp > NetworkProcess/Downloads/DownloadManager.cpp >+NetworkProcess/Downloads/DownloadMap.cpp > NetworkProcess/Downloads/PendingDownload.cpp > > NetworkProcess/FileAPI/NetworkBlobRegistry.cpp >diff --git a/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm b/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm >index 408995d94c5493c474c39b7e23e16a655e143b77..ac0d6fc61b42ca6d30f4b9061297164ea3571008 100644 >--- a/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm >+++ b/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm >@@ -192,7 +192,7 @@ ProcessAssertion::ProcessAssertion(pid_t pid, const String& name, AssertionState > }); > } > }; >- RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() PID %d acquiring assertion for process with PID %d", this, getpid(), pid); >+ RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() PID %d acquiring assertion for process with PID %d, name '%s'", this, getpid(), pid, name.utf8().data()); > > m_assertion = adoptNS([[BKSProcessAssertion alloc] initWithPID:pid flags:flagsForState(assertionState) reason:reasonForState(assertionState) name:(NSString *)name withHandler:handler]); > m_assertion.get().invalidationHandler = ^() { >diff --git a/Source/WebKit/WebKit.xcodeproj/project.pbxproj b/Source/WebKit/WebKit.xcodeproj/project.pbxproj >index f4577b01c2d62ac13248ce8213f920a4d6e07d7f..34c016a8342cd07313f73c2a1fa614c1e6ed7d4c 100644 >--- a/Source/WebKit/WebKit.xcodeproj/project.pbxproj >+++ b/Source/WebKit/WebKit.xcodeproj/project.pbxproj >@@ -923,6 +923,7 @@ > 512127C41908239A00DAF35C /* WebPasteboardOverrides.h in Headers */ = {isa = PBXBuildFile; fileRef = 512127C21908239A00DAF35C /* WebPasteboardOverrides.h */; }; > 51217461164C20E30037A5C1 /* ShareableResource.h in Headers */ = {isa = PBXBuildFile; fileRef = 5121745F164C20E30037A5C1 /* ShareableResource.h */; }; > 5123CF1C133D260A0056F800 /* WKIconDatabaseCG.h in Headers */ = {isa = PBXBuildFile; fileRef = 5123CF1A133D260A0056F800 /* WKIconDatabaseCG.h */; settings = {ATTRIBUTES = (Private, ); }; }; >+ 51240EBA220A08D2005CFC63 /* DownloadMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 51240EB8220A08CA005CFC63 /* DownloadMap.h */; }; > 512935D81288D19400A4B695 /* WebContextMenuItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 512935D61288D19400A4B695 /* WebContextMenuItem.h */; }; > 512935E41288D97800A4B695 /* InjectedBundlePageContextMenuClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 512935E21288D97800A4B695 /* InjectedBundlePageContextMenuClient.h */; }; > 512E34E5130B4D0500ABD19A /* WKApplicationCacheManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A33B4130B308C00F80CB5 /* WKApplicationCacheManager.h */; settings = {ATTRIBUTES = (Private, ); }; }; >@@ -3156,6 +3157,8 @@ > 5121745F164C20E30037A5C1 /* ShareableResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShareableResource.h; sourceTree = "<group>"; }; > 5123CF19133D260A0056F800 /* WKIconDatabaseCG.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WKIconDatabaseCG.cpp; path = cg/WKIconDatabaseCG.cpp; sourceTree = "<group>"; }; > 5123CF1A133D260A0056F800 /* WKIconDatabaseCG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKIconDatabaseCG.h; path = cg/WKIconDatabaseCG.h; sourceTree = "<group>"; }; >+ 51240EB8220A08CA005CFC63 /* DownloadMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DownloadMap.h; sourceTree = "<group>"; }; >+ 51240EB9220A08CA005CFC63 /* DownloadMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DownloadMap.cpp; sourceTree = "<group>"; }; > 512935D51288D19400A4B695 /* WebContextMenuItem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebContextMenuItem.cpp; sourceTree = "<group>"; }; > 512935D61288D19400A4B695 /* WebContextMenuItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebContextMenuItem.h; sourceTree = "<group>"; }; > 512935E11288D97800A4B695 /* InjectedBundlePageContextMenuClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundlePageContextMenuClient.cpp; sourceTree = "<group>"; }; >@@ -6825,6 +6828,8 @@ > 5C1426F71C23F84300D41183 /* DownloadID.h */, > 5C1426F81C23F84300D41183 /* DownloadManager.cpp */, > 5C1426F91C23F84300D41183 /* DownloadManager.h */, >+ 51240EB9220A08CA005CFC63 /* DownloadMap.cpp */, >+ 51240EB8220A08CA005CFC63 /* DownloadMap.h */, > 5C85C7861C3F23C50061A4FA /* PendingDownload.cpp */, > 5C298D9E1C3DEF2900470AFE /* PendingDownload.h */, > ); >@@ -9058,6 +9063,7 @@ > A1DF631318E0B7C8003A3E2A /* DownloadClient.h in Headers */, > 5C1427051C23F84C00D41183 /* DownloadID.h in Headers */, > 5C1427071C23F84C00D41183 /* DownloadManager.h in Headers */, >+ 51240EBA220A08D2005CFC63 /* DownloadMap.h in Headers */, > 1AB7D4CA1288AAA700CFD08C /* DownloadProxy.h in Headers */, > 1AD25E96167AB08100EA9BCD /* DownloadProxyMap.h in Headers */, > 1AB7D61A1288B9D900CFD08C /* DownloadProxyMessages.h in Headers */,
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 194294
:
361200
|
361203