Changeset 238655 in webkit
- Timestamp:
- Nov 28, 2018, 6:19:54 PM (6 years ago)
- Location:
- trunk/Source
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r238653 r238655 1 2018-11-28 Alex Christensen <achristensen@webkit.org> 2 3 Modernize BlobRegistry::writeBlobsToTemporaryFiles 4 https://bugs.webkit.org/show_bug.cgi?id=192117 5 6 Reviewed by Dean Jackson. 7 8 No change in behavior. Just use CompletionHandlers and the new sendWithAsyncReply instead of two way messaging 9 and manual completion handler management. 10 11 * bindings/js/SerializedScriptValue.cpp: 12 (WebCore::SerializedScriptValue::writeBlobsToDiskForIndexedDB): 13 * platform/network/BlobRegistry.h: 14 * platform/network/BlobRegistryImpl.cpp: 15 (WebCore::BlobRegistryImpl::writeBlobsToTemporaryFiles): 16 * platform/network/BlobRegistryImpl.h: 17 1 18 2018-11-15 Megan Gardner <megan_gardner@apple.com> 2 19 -
trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp
r238632 r238655 3567 3567 ASSERT(hasBlobURLs()); 3568 3568 3569 RefPtr<SerializedScriptValue> protectedThis(this);3570 3569 // FIXME: Add m_sessionID as a parameter here. 3571 blobRegistry().writeBlobsToTemporaryFiles(m_blobURLs, [completionHandler = WTFMove(completionHandler), this, protectedThis = WTFMove(protectedThis)] (auto& blobFilePaths) mutable {3570 blobRegistry().writeBlobsToTemporaryFiles(m_blobURLs, [completionHandler = WTFMove(completionHandler), this, protectedThis = makeRef(*this)] (auto&& blobFilePaths) mutable { 3572 3571 ASSERT(isMainThread()); 3573 3572 -
trunk/Source/WebCore/platform/network/BlobRegistry.h
r222113 r238655 32 32 #pragma once 33 33 34 #include <functional>35 34 #include <wtf/Forward.h> 36 #include <wtf/Function.h>37 35 38 36 namespace WebCore { … … 68 66 virtual unsigned long long blobSize(const URL&) = 0; 69 67 70 virtual void writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, WTF::Function<void (const Vector<String>& filePaths)>&& completionHandler) = 0;68 virtual void writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&& filePaths)>&&) = 0; 71 69 72 70 virtual bool isBlobRegistryImpl() const { return false; } -
trunk/Source/WebCore/platform/network/BlobRegistryImpl.cpp
r236762 r238655 42 42 #include "ResourceRequest.h" 43 43 #include "ResourceResponse.h" 44 #include <wtf/CompletionHandler.h> 44 45 #include <wtf/MainThread.h> 45 46 #include <wtf/NeverDestroyed.h> … … 301 302 } 302 303 303 void BlobRegistryImpl::writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, Function<void(const Vector<String>& filePaths)>&& completionHandler)304 void BlobRegistryImpl::writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&& filePaths)>&& completionHandler) 304 305 { 305 306 Vector<BlobForFileWriting> blobsForWriting; … … 321 322 } 322 323 323 callOnMainThread([completionHandler = WTFMove(completionHandler), filePaths = WTFMove(filePaths)] (){324 completionHandler( filePaths);324 callOnMainThread([completionHandler = WTFMove(completionHandler), filePaths = WTFMove(filePaths)] () mutable { 325 completionHandler(WTFMove(filePaths)); 325 326 }); 326 327 }); -
trunk/Source/WebCore/platform/network/BlobRegistryImpl.h
r226470 r238655 71 71 unsigned long long blobSize(const URL&) override; 72 72 73 void writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, Function<void (const Vector<String>& filePaths)>&& completionHandler) override;73 void writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&& filePaths)>&&) override; 74 74 75 75 struct BlobForFileWriting { -
trunk/Source/WebKit/ChangeLog
r238654 r238655 1 2 2018-11-28 Alex Christensen <achristensen@webkit.org> 3 4 Modernize BlobRegistry::writeBlobsToTemporaryFiles 5 https://bugs.webkit.org/show_bug.cgi?id=192117 6 7 Reviewed by Dean Jackson. 8 9 * NetworkProcess/FileAPI/NetworkBlobRegistry.cpp: 10 (WebKit::NetworkBlobRegistry::writeBlobsToTemporaryFiles): 11 (WebKit::NetworkBlobRegistry::writeBlobToFilePath): 12 * NetworkProcess/FileAPI/NetworkBlobRegistry.h: 13 * NetworkProcess/NetworkConnectionToWebProcess.cpp: 14 (WebKit::NetworkConnectionToWebProcess::writeBlobsToTemporaryFiles): 15 * NetworkProcess/NetworkConnectionToWebProcess.h: 16 * NetworkProcess/NetworkConnectionToWebProcess.messages.in: 17 * NetworkProcess/NetworkProcess.cpp: 18 (WebKit::NetworkProcess::writeBlobToFilePath): 19 * NetworkProcess/NetworkProcess.h: 20 * NetworkProcess/NetworkProcess.messages.in: 21 * UIProcess/ChildProcessProxy.h: 22 (WebKit::ChildProcessProxy::sendWithAsyncReply): 23 * UIProcess/Network/NetworkProcessProxy.cpp: 24 (WebKit::NetworkProcessProxy::didClose): 25 (WebKit::NetworkProcessProxy::writeBlobToFilePath): 26 (WebKit::NetworkProcessProxy::didWriteBlobToFilePath): Deleted. 27 * UIProcess/Network/NetworkProcessProxy.h: 28 * UIProcess/Network/NetworkProcessProxy.messages.in: 29 * WebProcess/FileAPI/BlobRegistryProxy.cpp: 30 (WebKit::BlobRegistryProxy::writeBlobsToTemporaryFiles): 31 * WebProcess/FileAPI/BlobRegistryProxy.h: 32 * WebProcess/Network/NetworkProcessConnection.cpp: 33 (WebKit::NetworkProcessConnection::didClose): 34 (WebKit::NetworkProcessConnection::writeBlobsToTemporaryFiles): 35 (WebKit::NetworkProcessConnection::didWriteBlobsToTemporaryFiles): Deleted. 36 * WebProcess/Network/NetworkProcessConnection.h: 37 * WebProcess/Network/NetworkProcessConnection.messages.in: 38 1 39 2018-11-28 Alex Christensen <achristensen@webkit.org> 2 40 -
trunk/Source/WebKit/NetworkProcess/FileAPI/NetworkBlobRegistry.cpp
r238283 r238655 131 131 } 132 132 133 void NetworkBlobRegistry::writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, Function<void(const Vector<String>&)>&& completionHandler)133 void NetworkBlobRegistry::writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&&)>&& completionHandler) 134 134 { 135 135 blobRegistry().writeBlobsToTemporaryFiles(blobURLs, WTFMove(completionHandler)); 136 136 } 137 137 138 void NetworkBlobRegistry::writeBlobToFilePath(const URL& blobURL, const String& path, Function<void(bool success)>&& completionHandler)138 void NetworkBlobRegistry::writeBlobToFilePath(const URL& blobURL, const String& path, CompletionHandler<void(bool success)>&& completionHandler) 139 139 { 140 140 if (!blobRegistry().isBlobRegistryImpl()) { … … 148 148 file->prepareForFileAccess(); 149 149 150 static_cast<BlobRegistryImpl&>(blobRegistry()).writeBlobToFilePath(blobURL, path, [blobFiles = WTFMove(blobFiles), completionHandler = WTFMove(completionHandler)] (bool success) {150 static_cast<BlobRegistryImpl&>(blobRegistry()).writeBlobToFilePath(blobURL, path, [blobFiles = WTFMove(blobFiles), completionHandler = WTFMove(completionHandler)] (bool success) mutable { 151 151 for (auto& file : blobFiles) 152 152 file->revokeFileAccess(); -
trunk/Source/WebKit/NetworkProcess/FileAPI/NetworkBlobRegistry.h
r226470 r238655 54 54 void unregisterBlobURL(NetworkConnectionToWebProcess*, const WebCore::URL&); 55 55 uint64_t blobSize(NetworkConnectionToWebProcess*, const WebCore::URL&); 56 void writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, Function<void (const Vector<String>&)>&& completionHandler);57 void writeBlobToFilePath(const WebCore::URL& blobURL, const String& path, Function<void(bool success)>&& completionHandler);56 void writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&&)>&&); 57 void writeBlobToFilePath(const WebCore::URL& blobURL, const String& path, CompletionHandler<void(bool success)>&&); 58 58 59 59 void connectionToWebProcessDidClose(NetworkConnectionToWebProcess*); -
trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp
r238630 r238655 533 533 } 534 534 535 void NetworkConnectionToWebProcess::writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, uint64_t requestIdentifier)535 void NetworkConnectionToWebProcess::writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&&)>&& completionHandler) 536 536 { 537 537 Vector<RefPtr<BlobDataFileReference>> fileReferences; … … 542 542 file->prepareForFileAccess(); 543 543 544 NetworkBlobRegistry::singleton().writeBlobsToTemporaryFiles(blobURLs, [ this, protectedThis = makeRef(*this), requestIdentifier, fileReferences = WTFMove(fileReferences)](auto& fileNames) mutable {544 NetworkBlobRegistry::singleton().writeBlobsToTemporaryFiles(blobURLs, [fileReferences = WTFMove(fileReferences), completionHandler = WTFMove(completionHandler)](auto&& fileNames) mutable { 545 545 for (auto& file : fileReferences) 546 546 file->revokeFileAccess(); 547 548 m_connection->send(Messages::NetworkProcessConnection::DidWriteBlobsToTemporaryFiles(requestIdentifier, fileNames), 0); 547 completionHandler(WTFMove(fileNames)); 549 548 }); 550 549 } -
trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h
r238283 r238655 169 169 void blobSize(const WebCore::URL&, uint64_t& resultSize); 170 170 void unregisterBlobURL(const WebCore::URL&); 171 void writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, uint64_t requestIdentifier);171 void writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&&)>&&); 172 172 173 173 void storeDerivedDataToCache(const WebKit::NetworkCache::DataKey&, const IPC::DataReference&); -
trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.messages.in
r238283 r238655 49 49 UnregisterBlobURL(WebCore::URL url) 50 50 BlobSize(WebCore::URL url) -> (uint64_t resultSize) LegacySync 51 WriteBlobsToTemporaryFiles(Vector<String> blobURLs , uint64_t requestIdentifier)51 WriteBlobsToTemporaryFiles(Vector<String> blobURLs) -> (Vector<String> fileNames) Async 52 52 53 53 StoreDerivedDataToCache(WebKit::NetworkCache::DataKey key, IPC::SharedBufferDataReference data) -
trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp
r238654 r238655 483 483 } 484 484 485 void NetworkProcess::writeBlobToFilePath(const WebCore::URL& url, const String& path, SandboxExtension::Handle&& handleForWriting, uint64_t requestID)485 void NetworkProcess::writeBlobToFilePath(const WebCore::URL& url, const String& path, SandboxExtension::Handle&& handleForWriting, CompletionHandler<void(bool)>&& completionHandler) 486 486 { 487 487 auto extension = SandboxExtension::create(WTFMove(handleForWriting)); 488 488 if (!extension) { 489 parentProcessConnection()->send(Messages::NetworkProcessProxy::DidWriteBlobToFilePath(false, requestID), 0);489 completionHandler(false); 490 490 return; 491 491 } 492 492 493 493 extension->consume(); 494 NetworkBlobRegistry::singleton().writeBlobToFilePath(url, path, [ this, extension = WTFMove(extension), requestID] (bool success){494 NetworkBlobRegistry::singleton().writeBlobToFilePath(url, path, [extension = WTFMove(extension), completionHandler = WTFMove(completionHandler)] (bool success) mutable { 495 495 extension->revoke(); 496 parentProcessConnection()->send(Messages::NetworkProcessProxy::DidWriteBlobToFilePath(success, requestID), 0);496 completionHandler(success); 497 497 }); 498 498 } -
trunk/Source/WebKit/NetworkProcess/NetworkProcess.h
r238654 r238655 288 288 void didSyncAllCookies(); 289 289 290 void writeBlobToFilePath(const WebCore::URL&, const String& path, SandboxExtension::Handle&&, uint64_t requestID);290 void writeBlobToFilePath(const WebCore::URL&, const String& path, SandboxExtension::Handle&&, CompletionHandler<void(bool)>&&); 291 291 292 292 #if USE(SOUP) -
trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in
r238063 r238655 78 78 ProcessDidResume() 79 79 80 WriteBlobToFilePath(WebCore::URL blobURL, String path, WebKit::SandboxExtension::Handle handle , uint64_t callbackID)80 WriteBlobToFilePath(WebCore::URL blobURL, String path, WebKit::SandboxExtension::Handle handle) -> (bool success) Async 81 81 82 82 PreconnectTo(WebCore::URL url, enum:bool WebCore::StoredCredentialsPolicy storedCredentialsPolicy); -
trunk/Source/WebKit/UIProcess/ChildProcessProxy.h
r237107 r238655 51 51 template<typename T> bool send(T&& message, uint64_t destinationID, OptionSet<IPC::SendOption> sendOptions = { }); 52 52 template<typename T> bool sendSync(T&& message, typename T::Reply&&, uint64_t destinationID, Seconds timeout = 1_s, OptionSet<IPC::SendSyncOption> sendSyncOptions = { }); 53 template<typename T, typename... Args> void sendWithAsyncReply(T&&, CompletionHandler<void(Args...)>&&); 53 54 54 55 IPC::Connection* connection() const … … 132 133 } 133 134 135 template<typename T, typename... Args> 136 void ChildProcessProxy::sendWithAsyncReply(T&& message, CompletionHandler<void(Args...)>&& completionHandler) 137 { 138 if (!m_connection) { 139 T::cancelReply(WTFMove(completionHandler)); 140 return; 141 } 142 143 connection()->sendWithAsyncReply(std::forward<T>(message), WTFMove(completionHandler)); 144 } 145 134 146 } // namespace WebKit -
trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp
r238351 r238655 273 273 m_syncAllCookiesCounter = 0; 274 274 275 for (auto& callback : m_writeBlobToFilePathCallbackMap.values())276 callback(false);277 m_writeBlobToFilePathCallbackMap.clear();278 279 275 for (auto& callback : m_removeAllStorageAccessCallbackMap.values()) 280 276 callback(); … … 565 561 } 566 562 567 void NetworkProcessProxy::writeBlobToFilePath(const WebCore::URL& url, const String& path, CompletionHandler<void(bool)>&& c allback)563 void NetworkProcessProxy::writeBlobToFilePath(const WebCore::URL& url, const String& path, CompletionHandler<void(bool)>&& completionHandler) 568 564 { 569 565 if (!canSendMessage()) { 570 callback(false); 571 return; 572 } 573 574 static uint64_t writeBlobToFilePathCallbackIdentifiers = 0; 575 uint64_t callbackID = ++writeBlobToFilePathCallbackIdentifiers; 576 m_writeBlobToFilePathCallbackMap.add(callbackID, WTFMove(callback)); 566 completionHandler(false); 567 return; 568 } 577 569 578 570 SandboxExtension::Handle handleForWriting; 579 571 SandboxExtension::createHandle(path, SandboxExtension::Type::ReadWrite, handleForWriting); 580 send(Messages::NetworkProcess::WriteBlobToFilePath(url, path, handleForWriting, callbackID), 0); 581 } 582 583 void NetworkProcessProxy::didWriteBlobToFilePath(bool success, uint64_t callbackID) 584 { 585 if (auto handler = m_writeBlobToFilePathCallbackMap.take(callbackID)) 586 handler(success); 587 else 588 ASSERT_NOT_REACHED(); 572 sendWithAsyncReply(Messages::NetworkProcess::WriteBlobToFilePath(url, path, handleForWriting), WTFMove(completionHandler)); 589 573 } 590 574 -
trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h
r238335 r238655 89 89 #endif 90 90 91 void writeBlobToFilePath(const WebCore::URL&, const String& path, CompletionHandler<void(bool)>&& callback);91 void writeBlobToFilePath(const WebCore::URL&, const String& path, CompletionHandler<void(bool)>&&); 92 92 93 93 void processReadyToSuspend(); … … 140 140 void didDeleteWebsiteData(uint64_t callbackID); 141 141 void didDeleteWebsiteDataForOrigins(uint64_t callbackID); 142 void didWriteBlobToFilePath(bool success, uint64_t callbackID);143 142 void logDiagnosticMessage(uint64_t pageID, const String& message, const String& description, WebCore::ShouldSample); 144 143 void logDiagnosticMessageWithResult(uint64_t pageID, const String& message, const String& description, uint32_t result, WebCore::ShouldSample); … … 192 191 unsigned m_syncAllCookiesCounter { 0 }; 193 192 194 HashMap<uint64_t, CompletionHandler<void(bool success)>> m_writeBlobToFilePathCallbackMap;195 193 HashMap<uint64_t, CompletionHandler<void()>> m_updateBlockCookiesCallbackMap; 196 194 HashMap<uint64_t, CompletionHandler<void(bool wasGranted)>> m_storageAccessResponseCallbackMap; -
trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in
r238063 r238655 32 32 DidSyncAllCookies() 33 33 34 DidWriteBlobToFilePath(bool success, uint64_t callbackID)35 36 34 ProcessReadyToSuspend() 37 35 SetIsHoldingLockedFiles(bool isHoldingLockedFiles) -
trunk/Source/WebKit/WebProcess/FileAPI/BlobRegistryProxy.cpp
r235205 r238655 86 86 } 87 87 88 void BlobRegistryProxy::writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, Function<void (const Vector<String>& filePaths)>&& completionHandler)88 void BlobRegistryProxy::writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&& filePaths)>&& completionHandler) 89 89 { 90 90 WebProcess::singleton().ensureNetworkProcessConnection().writeBlobsToTemporaryFiles(blobURLs, WTFMove(completionHandler)); -
trunk/Source/WebKit/WebProcess/FileAPI/BlobRegistryProxy.h
r209184 r238655 39 39 void registerBlobURLForSlice(const WebCore::URL&, const WebCore::URL& srcURL, long long start, long long end) override; 40 40 unsigned long long blobSize(const WebCore::URL&) override; 41 void writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, Function<void (const Vector<String>& filePaths)>&& completionHandler) override;41 void writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&& filePaths)>&&) override; 42 42 }; 43 43 -
trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.cpp
r236477 r238655 165 165 WebProcess::singleton().networkProcessConnectionClosed(this); 166 166 167 Vector<String> dummyFilenames;168 for (auto& handler : m_writeBlobToFileCompletionHandlers.values())169 handler(dummyFilenames);170 171 m_writeBlobToFileCompletionHandlers.clear();172 173 174 167 #if ENABLE(INDEXED_DATABASE) 175 168 for (auto& connection : m_webIDBConnectionsByIdentifier.values()) … … 193 186 } 194 187 195 void NetworkProcessConnection::writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, Function<void (const Vector<String>& filePaths)>&& completionHandler) 196 { 197 static uint64_t writeBlobToFileIdentifier; 198 uint64_t requestIdentifier = ++writeBlobToFileIdentifier; 199 200 m_writeBlobToFileCompletionHandlers.set(requestIdentifier, WTFMove(completionHandler)); 201 202 WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkConnectionToWebProcess::WriteBlobsToTemporaryFiles(blobURLs, requestIdentifier), 0); 203 } 204 205 void NetworkProcessConnection::didWriteBlobsToTemporaryFiles(uint64_t requestIdentifier, const Vector<String>& filenames) 206 { 207 auto handler = m_writeBlobToFileCompletionHandlers.take(requestIdentifier); 208 if (handler) 209 handler(filenames); 188 void NetworkProcessConnection::writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&& filePaths)>&& completionHandler) 189 { 190 WebProcess::singleton().ensureNetworkProcessConnection().connection().sendWithAsyncReply(Messages::NetworkConnectionToWebProcess::WriteBlobsToTemporaryFiles(blobURLs), WTFMove(completionHandler)); 210 191 } 211 192 -
trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.h
r236477 r238655 65 65 void didReceiveNetworkProcessConnectionMessage(IPC::Connection&, IPC::Decoder&); 66 66 67 void writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, Function<void (const Vector<String>& filePaths)>&& completionHandler);67 void writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&& filePaths)>&&); 68 68 69 69 #if ENABLE(INDEXED_DATABASE) … … 86 86 void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override; 87 87 88 void didWriteBlobsToTemporaryFiles(uint64_t requestIdentifier, const Vector<String>& filenames);89 88 void didFinishPingLoad(uint64_t pingLoadIdentifier, WebCore::ResourceError&&, WebCore::ResourceResponse&&); 90 89 void didFinishPreconnection(uint64_t preconnectionIdentifier, WebCore::ResourceError&&); … … 98 97 // The connection from the web process to the network process. 99 98 Ref<IPC::Connection> m_connection; 100 101 HashMap<uint64_t, Function<void (const Vector<String>&)>> m_writeBlobToFileCompletionHandlers;102 99 103 100 #if ENABLE(INDEXED_DATABASE) -
trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnection.messages.in
r230007 r238655 27 27 #endif 28 28 29 DidWriteBlobsToTemporaryFiles(uint64_t requestIdentifier, Vector<String> filenames)30 29 DidFinishPingLoad(uint64_t pingLoadIdentifier, WebCore::ResourceError error, WebCore::ResourceResponse response) 31 30 DidFinishPreconnection(uint64_t preconnectionIdentifier, WebCore::ResourceError error)
Note:
See TracChangeset
for help on using the changeset viewer.