diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-06-20 13:01:08 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-06-20 13:01:08 +0200 |
commit | 49233e234e5c787396cadb2cea33b31ae0cd65c1 (patch) | |
tree | 5410cb9a8fd53168bb60d62c54b654d86f03c38d /Source/WebKit2/WebProcess/qt/WebProcessQt.cpp | |
parent | b211c645d8ab690f713515dfdc84d80b11c27d2c (diff) | |
download | qtwebkit-49233e234e5c787396cadb2cea33b31ae0cd65c1.tar.gz |
Imported WebKit commit 3a8c29f35d00659d2ce7a0ccdfa8304f14e82327 (http://svn.webkit.org/repository/webkit/trunk@120813)
New snapshot with Windows build fixes
Diffstat (limited to 'Source/WebKit2/WebProcess/qt/WebProcessQt.cpp')
-rw-r--r-- | Source/WebKit2/WebProcess/qt/WebProcessQt.cpp | 83 |
1 files changed, 79 insertions, 4 deletions
diff --git a/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp b/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp index a2beac14b..268c4b093 100644 --- a/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp +++ b/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp @@ -35,24 +35,93 @@ #include <QCoreApplication> #include <QNetworkAccessManager> #include <QNetworkCookieJar> +#include <QNetworkDiskCache> #include <WebCore/CookieJarQt.h> +#include <WebCore/FileSystem.h> +#include <WebCore/MemoryCache.h> #include <WebCore/PageCache.h> #include <WebCore/RuntimeEnabledFeatures.h> #if defined(Q_OS_MACX) #include <dispatch/dispatch.h> +#include <mach/host_info.h> +#include <mach/mach.h> +#include <mach/mach_error.h> +#elif !defined(Q_OS_WIN) +#include <unistd.h> #endif using namespace WebCore; namespace WebKit { -static const int DefaultPageCacheCapacity = 20; +static uint64_t physicalMemorySizeInBytes() +{ + static uint64_t physicalMemorySize = 0; + + if (!physicalMemorySize) { +#if defined(Q_OS_MACX) + host_basic_info_data_t hostInfo; + mach_port_t host = mach_host_self(); + mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; + kern_return_t r = host_info(host, HOST_BASIC_INFO, (host_info_t)&hostInfo, &count); + mach_port_deallocate(mach_task_self(), host); + + if (r == KERN_SUCCESS) + physicalMemorySize = hostInfo.max_mem; + +#elif defined(Q_OS_WIN) + MEMORYSTATUSEX statex; + statex.dwLength = sizeof(statex); + GlobalMemoryStatusEx(&statex); + physicalMemorySize = static_cast<uint64_t>(statex.ullTotalPhys); + +#else + long pageSize = sysconf(_SC_PAGESIZE); + long numberOfPages = sysconf(_SC_PHYS_PAGES); + + if (pageSize > 0 && numberOfPages > 0) + physicalMemorySize = static_cast<uint64_t>(pageSize) * static_cast<uint64_t>(numberOfPages); + +#endif + } + return physicalMemorySize; +} -void WebProcess::platformSetCacheModel(CacheModel) +void WebProcess::platformSetCacheModel(CacheModel cacheModel) { - // FIXME: see bug 73918 - pageCache()->setCapacity(DefaultPageCacheCapacity); + QNetworkDiskCache* diskCache = qobject_cast<QNetworkDiskCache*>(m_networkAccessManager->cache()); + ASSERT(diskCache); + + uint64_t physicalMemorySizeInMegabytes = physicalMemorySizeInBytes() / 1024 / 1024; + + // The Mac port of WebKit2 uses a fudge factor of 1000 here to account for misalignment, however, + // that tends to overestimate the memory quite a bit (1 byte misalignment ~ 48 MiB misestimation). + // We use 1024 * 1023 for now to keep the estimation error down to +/- ~1 MiB. + uint64_t freeVolumeSpace = WebCore::getVolumeFreeSizeForPath(diskCache->cacheDirectory().toAscii().constData()) / 1024 / 1023; + + // The following variables are initialised to 0 because WebProcess::calculateCacheSizes might not + // set them in some rare cases. + unsigned cacheTotalCapacity = 0; + unsigned cacheMinDeadCapacity = 0; + unsigned cacheMaxDeadCapacity = 0; + double deadDecodedDataDeletionInterval = 0; + unsigned pageCacheCapacity = 0; + unsigned long urlCacheMemoryCapacity = 0; + unsigned long urlCacheDiskCapacity = 0; + + calculateCacheSizes(cacheModel, physicalMemorySizeInMegabytes, freeVolumeSpace, + cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval, + pageCacheCapacity, urlCacheMemoryCapacity, urlCacheDiskCapacity); + + diskCache->setMaximumCacheSize(urlCacheDiskCapacity); + + memoryCache()->setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity); + memoryCache()->setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval); + + pageCache()->setCapacity(pageCacheCapacity); + + // FIXME: Implement hybrid in-memory- and disk-caching as e.g. the Mac port does. } void WebProcess::platformClearResourceCaches(ResourceCachesToClear) @@ -75,6 +144,12 @@ void WebProcess::platformInitializeWebProcess(const WebProcessCreationParameters // Do not let QNetworkAccessManager delete the jar. jar->setParent(0); + ASSERT(!parameters.diskCacheDirectory.isEmpty() && !parameters.diskCacheDirectory.isNull()); + QNetworkDiskCache* diskCache = new QNetworkDiskCache(); + diskCache->setCacheDirectory(parameters.diskCacheDirectory); + // The m_networkAccessManager takes ownership of the diskCache object upon the following call. + m_networkAccessManager->setCache(diskCache); + #if defined(Q_OS_MACX) pid_t ppid = getppid(); dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); |