Implement DownloadMonitor to prevent long-running slow downloads from background...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Mar 2019 22:38:55 +0000 (22:38 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Mar 2019 22:38:55 +0000 (22:38 +0000)
commit6f8a6e2dd64cdb0a49b3251a86e56edaac7e22d8
tree693895ccf4f64f919f916f73ae97753dd438649d
parent14a08e68f09f8c53a9513fd0b84ae4ff09d83fae
Implement DownloadMonitor to prevent long-running slow downloads from background apps
https://bugs.webkit.org/show_bug.cgi?id=195785

Patch by Alex Christensen <achristensen@webkit.org> on 2019-03-18
Reviewed by Geoffrey Garen.

Source/WebKit:

This is similar to what was updated in <rdar://problem/42677685> but for WebKit Downloads.
To test it I implemented a throttled TCP server, SPI to speed up DownloadMonitor's timer,
and SPI to synthesize the application going into the background and foreground, which
NSNotificationCenter does on iOS.

* NetworkProcess/Downloads/Download.cpp:
(WebKit::Download::didReceiveData):
(WebKit::Download::didFinish):
(WebKit::Download::didFail):
(WebKit::Download::didCancel):
* NetworkProcess/Downloads/Download.h:
(WebKit::Download::applicationEnteredBackground):
(WebKit::Download::applicationEnteredForeground):
(WebKit::Download::manager const):
* NetworkProcess/Downloads/DownloadManager.cpp:
(WebKit::DownloadManager::downloadFinished):
(WebKit::DownloadManager::applicationDidEnterBackground):
(WebKit::DownloadManager::applicationWillEnterForeground):
* NetworkProcess/Downloads/DownloadManager.h:
* NetworkProcess/Downloads/DownloadMap.cpp:
(WebKit::DownloadMap::values):
* NetworkProcess/Downloads/DownloadMap.h:
* NetworkProcess/Downloads/DownloadMonitor.cpp: Added.
(WebKit::operator _kbps):
(WebKit::timeUntilNextInterval):
(WebKit::DownloadMonitor::DownloadMonitor):
(WebKit::DownloadMonitor::measuredThroughputRate const):
(WebKit::DownloadMonitor::downloadReceivedBytes):
(WebKit::DownloadMonitor::applicationEnteredForeground):
(WebKit::DownloadMonitor::applicationEnteredBackground):
(WebKit::DownloadMonitor::speedMultiplier const):
(WebKit::DownloadMonitor::timerFired):
* NetworkProcess/Downloads/DownloadMonitor.h: Added.
* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::initializeNetworkProcess):
(WebKit::NetworkProcess::applicationDidEnterBackground):
(WebKit::NetworkProcess::applicationWillEnterForeground):
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/NetworkProcess.messages.in:
* NetworkProcess/NetworkProcessCreationParameters.cpp:
(WebKit::NetworkProcessCreationParameters::encode const):
(WebKit::NetworkProcessCreationParameters::decode):
* NetworkProcess/NetworkProcessCreationParameters.h:
* Sources.txt:
* SourcesCocoa.txt:
* UIProcess/API/APIProcessPoolConfiguration.cpp:
(API::ProcessPoolConfiguration::copy):
* UIProcess/API/APIProcessPoolConfiguration.h:
* UIProcess/API/C/WKContext.cpp:
(WKContextDownloadURLRequest):
(WKContextResumeDownload):
* UIProcess/API/Cocoa/WKProcessPool.mm:
(-[WKProcessPool _synthesizeAppIsBackground:]):
(-[WKProcessPool _downloadURLRequest:originatingWebView:]):
* UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
* UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h:
* UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm:
(-[_WKProcessPoolConfiguration downloadMonitorSpeedMultiplier]):
(-[_WKProcessPoolConfiguration setDownloadMonitorSpeedMultiplier:]):
* UIProcess/Cocoa/DownloadProxyMapCocoa.mm: Added.
(WebKit::DownloadProxyMap::platformCreate):
(WebKit::DownloadProxyMap::platformDestroy):
* UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::platformInitializeNetworkProcess):
* UIProcess/Downloads/DownloadProxy.cpp:
(WebKit::DownloadProxy::didFinish):
(WebKit::DownloadProxy::didFail):
(WebKit::DownloadProxy::didCancel):
* UIProcess/Downloads/DownloadProxyMap.cpp:
(WebKit::DownloadProxyMap::DownloadProxyMap):
(WebKit::DownloadProxyMap::~DownloadProxyMap):
(WebKit::DownloadProxyMap::platformCreate):
(WebKit::DownloadProxyMap::platformDestroy):
(WebKit::DownloadProxyMap::applicationDidEnterBackground):
(WebKit::DownloadProxyMap::applicationWillEnterForeground):
(WebKit::DownloadProxyMap::createDownloadProxy):
(WebKit::DownloadProxyMap::downloadFinished):
* UIProcess/Downloads/DownloadProxyMap.h:
* UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::synthesizeAppIsBackground):
(WebKit::NetworkProcessProxy::createDownloadProxy):
* UIProcess/Network/NetworkProcessProxy.h:
* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::receivedPolicyDecision):
(WebKit::WebPageProxy::handleDownloadRequest):
* UIProcess/WebPageProxy.h:
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::download):
(WebKit::WebProcessPool::resumeDownload):
(WebKit::WebProcessPool::createDownloadProxy):
(WebKit::WebProcessPool::synthesizeAppIsBackground):
* UIProcess/WebProcessPool.h:
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::handleDownloadRequest):
* UIProcess/mac/PageClientImplMac.h:
* UIProcess/mac/PageClientImplMac.mm:
(WebKit::PageClientImpl::handleDownloadRequest):
* WebKit.xcodeproj/project.pbxproj:

Tools:

* TestWebKitAPI/TCPServer.cpp: Added.
(TestWebKitAPI::TCPServer::TCPServer):
(TestWebKitAPI::TCPServer::~TCPServer):
(TestWebKitAPI::TCPServer::socketBindListen):
(TestWebKitAPI::TCPServer::waitForAndReplyToRequests):
* TestWebKitAPI/TCPServer.h: Added.
(TestWebKitAPI::TCPServer::port const):
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/Download.mm:
(-[DownloadMonitorTestDelegate _downloadDidStart:]):
(-[DownloadMonitorTestDelegate _downloadDidCancel:]):
(-[DownloadMonitorTestDelegate _download:decideDestinationWithSuggestedFilename:completionHandler:]):
(-[DownloadMonitorTestDelegate _download:didReceiveData:]):
(TestWebKitAPI::respondSlowly):
(TestWebKitAPI::webViewWithDownloadMonitorSpeedMultiplier):
(TestWebKitAPI::downloadAtRate):
(TestWebKitAPI::TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243110 268f45cc-cd09-0410-ab3c-d52691b4dbfc
54 files changed:
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/Downloads/Download.cpp
Source/WebKit/NetworkProcess/Downloads/Download.h
Source/WebKit/NetworkProcess/Downloads/DownloadManager.cpp
Source/WebKit/NetworkProcess/Downloads/DownloadManager.h
Source/WebKit/NetworkProcess/Downloads/DownloadMap.cpp
Source/WebKit/NetworkProcess/Downloads/DownloadMap.h
Source/WebKit/NetworkProcess/Downloads/DownloadMonitor.cpp [new file with mode: 0644]
Source/WebKit/NetworkProcess/Downloads/DownloadMonitor.h [new file with mode: 0644]
Source/WebKit/NetworkProcess/NetworkProcess.cpp
Source/WebKit/NetworkProcess/NetworkProcess.h
Source/WebKit/NetworkProcess/NetworkProcess.messages.in
Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.cpp
Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.h
Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp
Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.cpp
Source/WebKit/Sources.txt
Source/WebKit/SourcesCocoa.txt
Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.cpp
Source/WebKit/UIProcess/API/APIProcessPoolConfiguration.h
Source/WebKit/UIProcess/API/C/WKContext.cpp
Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm
Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h
Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h
Source/WebKit/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm
Source/WebKit/UIProcess/API/glib/WebKitWebContext.cpp
Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp
Source/WebKit/UIProcess/API/gtk/PageClientImpl.h
Source/WebKit/UIProcess/API/wpe/PageClientImpl.cpp
Source/WebKit/UIProcess/API/wpe/PageClientImpl.h
Source/WebKit/UIProcess/Cocoa/DownloadProxyMapCocoa.mm [new file with mode: 0644]
Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm
Source/WebKit/UIProcess/Downloads/DownloadProxy.cpp
Source/WebKit/UIProcess/Downloads/DownloadProxyMap.cpp
Source/WebKit/UIProcess/Downloads/DownloadProxyMap.h
Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp
Source/WebKit/UIProcess/Network/NetworkProcessProxy.h
Source/WebKit/UIProcess/PageClient.h
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/WebProcessPool.cpp
Source/WebKit/UIProcess/WebProcessPool.h
Source/WebKit/UIProcess/ios/PageClientImplIOS.h
Source/WebKit/UIProcess/ios/PageClientImplIOS.mm
Source/WebKit/UIProcess/mac/PageClientImplMac.h
Source/WebKit/UIProcess/mac/PageClientImplMac.mm
Source/WebKit/UIProcess/win/PageClientImpl.cpp
Source/WebKit/UIProcess/win/PageClientImpl.h
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Tools/ChangeLog
Tools/TestWebKitAPI/TCPServer.cpp [new file with mode: 0644]
Tools/TestWebKitAPI/TCPServer.h [new file with mode: 0644]
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm