Split calculateCacheSizes in two methods
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 29 Jul 2016 05:22:14 +0000 (05:22 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 29 Jul 2016 05:22:14 +0000 (05:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=160237

Reviewed by Darin Adler.

Source/WebCore:

Rename getVolumeFreeSizeForPath as volumeFreeSizeForPath and make it available to all platforms adding an
implementation for mac.

* platform/FileSystem.h:
* platform/efl/FileSystemEfl.cpp:
(WebCore::volumeFreeSizeForPath):
(WebCore::getVolumeFreeSizeForPath): Deleted.
* platform/glib/FileSystemGlib.cpp:
(WebCore::volumeFreeSizeForPath):
(WebCore::getVolumeFreeSizeForPath): Deleted.
* platform/mac/FileSystemMac.mm:
(WebCore::volumeFreeSizeForPath):
* platform/win/FileSystemWin.cpp:
(WebCore::volumeFreeSizeForPath):

Source/WebKit2:

It's used to calculate memory and disk cache sizes, but only the web process is interested in memory caches, and
the network process in disk cache. We can also avoid a lot of duplicated code between ports to set the cache model.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::setCacheModel): Use calculateURLCacheSizes to set the disk cache size and call
platformSetURLCacheSize if not set to allow ports to setup platform specific cache.
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/cocoa/NetworkProcessCocoa.mm:
(WebKit::NetworkProcess::platformSetURLCacheSize): Remove common code that is now in cross-platform file.
(WebKit::volumeFreeSize): Deleted.
(WebKit::NetworkProcess::platformSetCacheModel): Renamed to platformSetURLCacheSize().
* NetworkProcess/soup/NetworkProcessSoup.cpp:
(WebKit::NetworkProcess::platformSetURLCacheSize): Remove common code that is now in cross-platform file.
(WebKit::getCacheDiskFreeSize): Deleted.
(WebKit::NetworkProcess::platformSetCacheModel): Renamed to platformSetURLCacheSize().
* Shared/CacheModel.cpp:
(WebKit::calculateMemoryCacheSizes): Calculate the memory and page cache sizes.
(WebKit::calculateURLCacheSizes): Calculate the disk cache size.
(WebKit::calculateCacheSizes): Deleted.
* Shared/CacheModel.h:
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess): Tell the page cache to clear backing stores for GTK+ port too. This was done before when
setting the cache model.
(WebKit::WebProcess::setCacheModel): Use calculateMemoryCacheSizes to setup memory caches and call
platformSetCacheModel to allow ports do more setup according to the cache model.
(WebKit::WebProcess::clearResourceCaches): Deleted.
* WebProcess/WebProcess.h:
* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::platformSetCacheModel): Remove common code that is now in cross-platform file.
(WebKit::volumeFreeSize): Deleted.
(WebKit::WebProcess::platformClearResourceCaches): Deleted.
* WebProcess/soup/WebProcessSoup.cpp:
(WebKit::WebProcess::platformSetCacheModel): Remove common code that is now in cross-platform file.
(WebKit::WebProcess::platformInitializeWebProcess):
(WebKit::WebProcess::platformClearResourceCaches): Deleted.

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

17 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/FileSystem.h
Source/WebCore/platform/efl/FileSystemEfl.cpp
Source/WebCore/platform/glib/FileSystemGlib.cpp
Source/WebCore/platform/mac/FileSystemMac.mm
Source/WebCore/platform/win/FileSystemWin.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/NetworkProcess.cpp
Source/WebKit2/NetworkProcess/NetworkProcess.h
Source/WebKit2/NetworkProcess/cocoa/NetworkProcessCocoa.mm
Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp
Source/WebKit2/Shared/CacheModel.cpp
Source/WebKit2/Shared/CacheModel.h
Source/WebKit2/WebProcess/WebProcess.cpp
Source/WebKit2/WebProcess/WebProcess.h
Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm
Source/WebKit2/WebProcess/soup/WebProcessSoup.cpp

index 76ab03d..524e357 100644 (file)
@@ -1,3 +1,25 @@
+2016-07-28  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        Split calculateCacheSizes in two methods
+        https://bugs.webkit.org/show_bug.cgi?id=160237
+
+        Reviewed by Darin Adler.
+
+        Rename getVolumeFreeSizeForPath as volumeFreeSizeForPath and make it available to all platforms adding an
+        implementation for mac.
+
+        * platform/FileSystem.h:
+        * platform/efl/FileSystemEfl.cpp:
+        (WebCore::volumeFreeSizeForPath):
+        (WebCore::getVolumeFreeSizeForPath): Deleted.
+        * platform/glib/FileSystemGlib.cpp:
+        (WebCore::volumeFreeSizeForPath):
+        (WebCore::getVolumeFreeSizeForPath): Deleted.
+        * platform/mac/FileSystemMac.mm:
+        (WebCore::volumeFreeSizeForPath):
+        * platform/win/FileSystemWin.cpp:
+        (WebCore::volumeFreeSizeForPath):
+
 2016-07-28  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Remove deprecated SPI for video inline / fullscreen controls
index 1af26cd..868bce5 100644 (file)
@@ -145,6 +145,7 @@ WEBCORE_EXPORT bool makeAllDirectories(const String& path);
 String homeDirectoryPath();
 WEBCORE_EXPORT String pathGetFileName(const String&);
 WEBCORE_EXPORT String directoryName(const String&);
+WEBCORE_EXPORT bool getVolumeFreeSpace(const String&, uint64_t&);
 
 WEBCORE_EXPORT void setMetadataURL(String& URLString, const String& referrer, const String& path);
 
@@ -202,9 +203,6 @@ String filenameForDisplay(const String&);
 CString applicationDirectoryPath();
 CString sharedResourcesPath();
 #endif
-#if USE(SOUP)
-uint64_t getVolumeFreeSizeForPath(const char*);
-#endif
 
 #if PLATFORM(WIN)
 WEBCORE_EXPORT String localUserSpecificStorageDirectory();
index c595ef5..8d97910 100644 (file)
@@ -88,13 +88,18 @@ String homeDirectoryPath()
     return String::fromUTF8(home);
 }
 
-uint64_t getVolumeFreeSizeForPath(const char* path)
+bool getVolumeFreeSpace(const String& path, uint64_t& freeSpace)
 {
+    CString fsRep = fileSystemRepresentation(path);
+    if (!fsRep.data() || fsRep.data()[0] == '\0')
+        return false;
+
     struct statvfs buf;
-    if (statvfs(path, &buf) < 0)
-        return 0;
+    if (statvfs(fsRep.data(), &buf) < 0)
+        return false;
 
-    return static_cast<uint64_t>(buf.f_bavail) * buf.f_bsize;
+    freeSpace = static_cast<uint64_t>(buf.f_bavail) * buf.f_bsize;
+    return true;
 }
 
 }
index 1d11b78..1174091 100644 (file)
@@ -232,14 +232,19 @@ CString sharedResourcesPath()
     return cachedPath;
 }
 
-uint64_t getVolumeFreeSizeForPath(const char* path)
+bool getVolumeFreeSpace(const String& path, uint64_t& freeSpace)
 {
-    GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(path));
+    GUniquePtr<gchar> filename = unescapedFilename(path);
+    if (!filename)
+        return false;
+
+    GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(filename.get()));
     GRefPtr<GFileInfo> fileInfo = adoptGRef(g_file_query_filesystem_info(file.get(), G_FILE_ATTRIBUTE_FILESYSTEM_FREE, 0, 0));
     if (!fileInfo)
-        return 0;
+        return false;
 
-    return g_file_info_get_attribute_uint64(fileInfo.get(), G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
+    freeSpace = g_file_info_get_attribute_uint64(fileInfo.get(), G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
+    return !!freeSpace;
 }
 
 String directoryName(const String& path)
index 9bba9ef..605387a 100644 (file)
@@ -98,6 +98,15 @@ bool moveFile(const String& oldPath, const String& newPath)
     return [manager moveItemAtURL:[NSURL fileURLWithPath:oldPath] toURL:[NSURL fileURLWithPath:newPath] error:nil];
 }
 
+bool getVolumeFreeSpace(const String& path, uint64_t& freeSpace)
+{
+    NSDictionary *fileSystemAttributesDictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:(NSString *)path error:NULL];
+    if (!fileSystemAttributesDictionary)
+        return false;
+    freeSpace = [[fileSystemAttributesDictionary objectForKey:NSFileSystemFreeSize] unsignedLongLongValue];
+    return true;
+}
+
 #if !PLATFORM(IOS)
 bool deleteEmptyDirectory(const String& path)
 {
index c2b93e4..60edcdf 100644 (file)
@@ -447,4 +447,10 @@ Vector<String> listDirectory(const String& directory, const String& filter)
     return entries;
 }
 
+bool getVolumeFreeSpace(const String&, uint64_t&)
+{
+    notImplemented();
+    return false;
+}
+
 } // namespace WebCore
index a9b7688..98b29b0 100644 (file)
@@ -1,5 +1,48 @@
 2016-07-28  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        Split calculateCacheSizes in two methods
+        https://bugs.webkit.org/show_bug.cgi?id=160237
+
+        Reviewed by Darin Adler.
+
+        It's used to calculate memory and disk cache sizes, but only the web process is interested in memory caches, and
+        the network process in disk cache. We can also avoid a lot of duplicated code between ports to set the cache model.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::setCacheModel): Use calculateURLCacheSizes to set the disk cache size and call
+        platformSetURLCacheSize if not set to allow ports to setup platform specific cache.
+        * NetworkProcess/NetworkProcess.h:
+        * NetworkProcess/cocoa/NetworkProcessCocoa.mm:
+        (WebKit::NetworkProcess::platformSetURLCacheSize): Remove common code that is now in cross-platform file.
+        (WebKit::volumeFreeSize): Deleted.
+        (WebKit::NetworkProcess::platformSetCacheModel): Renamed to platformSetURLCacheSize().
+        * NetworkProcess/soup/NetworkProcessSoup.cpp:
+        (WebKit::NetworkProcess::platformSetURLCacheSize): Remove common code that is now in cross-platform file.
+        (WebKit::getCacheDiskFreeSize): Deleted.
+        (WebKit::NetworkProcess::platformSetCacheModel): Renamed to platformSetURLCacheSize().
+        * Shared/CacheModel.cpp:
+        (WebKit::calculateMemoryCacheSizes): Calculate the memory and page cache sizes.
+        (WebKit::calculateURLCacheSizes): Calculate the disk cache size.
+        (WebKit::calculateCacheSizes): Deleted.
+        * Shared/CacheModel.h:
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess): Tell the page cache to clear backing stores for GTK+ port too. This was done before when
+        setting the cache model.
+        (WebKit::WebProcess::setCacheModel): Use calculateMemoryCacheSizes to setup memory caches and call
+        platformSetCacheModel to allow ports do more setup according to the cache model.
+        (WebKit::WebProcess::clearResourceCaches): Deleted.
+        * WebProcess/WebProcess.h:
+        * WebProcess/cocoa/WebProcessCocoa.mm:
+        (WebKit::WebProcess::platformSetCacheModel): Remove common code that is now in cross-platform file.
+        (WebKit::volumeFreeSize): Deleted.
+        (WebKit::WebProcess::platformClearResourceCaches): Deleted.
+        * WebProcess/soup/WebProcessSoup.cpp:
+        (WebKit::WebProcess::platformSetCacheModel): Remove common code that is now in cross-platform file.
+        (WebKit::WebProcess::platformInitializeWebProcess):
+        (WebKit::WebProcess::platformClearResourceCaches): Deleted.
+
+2016-07-28  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         Database Process: ASSERTION FAILED: paths.size() == handles.size() with SANDBOX_EXTENSIONS disabled
         https://bugs.webkit.org/show_bug.cgi?id=160188
 
index b35b2af..94e456a 100644 (file)
@@ -538,11 +538,34 @@ void NetworkProcess::setCacheModel(uint32_t cm)
 {
     CacheModel cacheModel = static_cast<CacheModel>(cm);
 
-    if (!m_hasSetCacheModel || cacheModel != m_cacheModel) {
-        m_hasSetCacheModel = true;
-        m_cacheModel = cacheModel;
-        platformSetCacheModel(cacheModel);
+    if (m_hasSetCacheModel && (cacheModel == m_cacheModel))
+        return;
+
+    m_hasSetCacheModel = true;
+    m_cacheModel = cacheModel;
+
+    unsigned urlCacheMemoryCapacity = 0;
+    uint64_t urlCacheDiskCapacity = 0;
+    uint64_t diskFreeSize = 0;
+    if (WebCore::getVolumeFreeSpace(m_diskCacheDirectory, diskFreeSize)) {
+        // As a fudge factor, use 1000 instead of 1024, in case the reported byte
+        // count doesn't align exactly to a megabyte boundary.
+        diskFreeSize /= KB * 1000;
+        calculateURLCacheSizes(cacheModel, diskFreeSize, urlCacheMemoryCapacity, urlCacheDiskCapacity);
     }
+
+    if (m_diskCacheSizeOverride >= 0)
+        urlCacheDiskCapacity = m_diskCacheSizeOverride;
+
+#if ENABLE(NETWORK_CACHE)
+    auto& networkCache = NetworkCache::singleton();
+    if (networkCache.isEnabled()) {
+        networkCache.setCapacity(urlCacheDiskCapacity);
+        return;
+    }
+#endif
+
+    platformSetURLCacheSize(urlCacheMemoryCapacity, urlCacheDiskCapacity);
 }
 
 void NetworkProcess::setCanHandleHTTPSServerTrustEvaluation(bool value)
index b732517..ae89df2 100644 (file)
@@ -197,7 +197,7 @@ private:
 #endif
 
     // Platform Helpers
-    void platformSetCacheModel(CacheModel);
+    void platformSetURLCacheSize(unsigned urlCacheMemoryCapacity, uint64_t urlCacheDiskCapacity);
 
     // Connections to WebProcesses.
     Vector<RefPtr<NetworkConnectionToWebProcess>> m_webProcessConnections;
index 070e18a..4ce5aa2 100644 (file)
@@ -38,7 +38,6 @@
 #import <WebCore/SecurityOrigin.h>
 #import <WebCore/SecurityOriginData.h>
 #import <WebKitSystemInterface.h>
-#import <wtf/RAMSize.h>
 
 namespace WebKit {
 
@@ -124,46 +123,12 @@ void NetworkProcess::platformInitializeNetworkProcessCocoa(const NetworkProcessC
     }
 }
 
-static uint64_t volumeFreeSize(const String& path)
+void NetworkProcess::platformSetURLCacheSize(unsigned urlCacheMemoryCapacity, uint64_t urlCacheDiskCapacity)
 {
-    NSDictionary *fileSystemAttributesDictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:(NSString *)path error:NULL];
-    return [[fileSystemAttributesDictionary objectForKey:NSFileSystemFreeSize] unsignedLongLongValue];
-}
-
-void NetworkProcess::platformSetCacheModel(CacheModel cacheModel)
-{
-    uint64_t memSize = ramSize() / 1024 / 1024;
-
-    // As a fudge factor, use 1000 instead of 1024, in case the reported byte
-    // count doesn't align exactly to a megabyte boundary.
-    uint64_t diskFreeSize = volumeFreeSize(m_diskCacheDirectory) / 1024 / 1000;
-
-    unsigned cacheTotalCapacity = 0;
-    unsigned cacheMinDeadCapacity = 0;
-    unsigned cacheMaxDeadCapacity = 0;
-    auto deadDecodedDataDeletionInterval = std::chrono::seconds { 0 };
-    unsigned pageCacheCapacity = 0;
-    unsigned long urlCacheMemoryCapacity = 0;
-    unsigned long urlCacheDiskCapacity = 0;
-
-    calculateCacheSizes(cacheModel, memSize, diskFreeSize,
-        cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval,
-        pageCacheCapacity, urlCacheMemoryCapacity, urlCacheDiskCapacity);
-
-    if (m_diskCacheSizeOverride >= 0)
-        urlCacheDiskCapacity = m_diskCacheSizeOverride;
-
-#if ENABLE(NETWORK_CACHE)
-    auto& networkCache = NetworkCache::singleton();
-    if (networkCache.isEnabled()) {
-        networkCache.setCapacity(urlCacheDiskCapacity);
-        return;
-    }
-#endif
     NSURLCache *nsurlCache = [NSURLCache sharedURLCache];
     [nsurlCache setMemoryCapacity:urlCacheMemoryCapacity];
     if (!m_diskCacheIsDisabledForTesting)
-        [nsurlCache setDiskCapacity:std::max<unsigned long>(urlCacheDiskCapacity, [nsurlCache diskCapacity])]; // Don't shrink a big disk cache, since that would cause churn.
+        [nsurlCache setDiskCapacity:std::max<uint64_t>(urlCacheDiskCapacity, [nsurlCache diskCapacity])]; // Don't shrink a big disk cache, since that would cause churn.
 }
 
 static RetainPtr<CFStringRef> partitionName(CFStringRef domain)
index 50e4982..a3e14df 100644 (file)
@@ -45,20 +45,6 @@ using namespace WebCore;
 
 namespace WebKit {
 
-#if !ENABLE(NETWORK_CACHE)
-static uint64_t getCacheDiskFreeSize(SoupCache* cache)
-{
-    ASSERT(cache);
-
-    GUniqueOutPtr<char> cacheDir;
-    g_object_get(G_OBJECT(cache), "cache-dir", &cacheDir.outPtr(), NULL);
-    if (!cacheDir)
-        return 0;
-
-    return WebCore::getVolumeFreeSizeForPath(cacheDir.get());
-}
-#endif
-
 void NetworkProcess::userPreferredLanguagesChanged(const Vector<String>& languages)
 {
     SoupNetworkSession::defaultSession().setAcceptLanguages(languages);
@@ -107,36 +93,14 @@ void NetworkProcess::platformInitializeNetworkProcess(const NetworkProcessCreati
     setIgnoreTLSErrors(parameters.ignoreTLSErrors);
 }
 
-void NetworkProcess::platformSetCacheModel(CacheModel cacheModel)
+void NetworkProcess::platformSetURLCacheSize(unsigned /*urlCacheMemoryCapacity*/, uint64_t urlCacheDiskCapacity)
 {
-    unsigned cacheTotalCapacity = 0;
-    unsigned cacheMinDeadCapacity = 0;
-    unsigned cacheMaxDeadCapacity = 0;
-    auto deadDecodedDataDeletionInterval = std::chrono::seconds { 0 };
-    unsigned pageCacheCapacity = 0;
-
-    unsigned long urlCacheMemoryCapacity = 0;
-    unsigned long urlCacheDiskCapacity = 0;
-
-#if ENABLE(NETWORK_CACHE)
-    uint64_t diskFreeSize = WebCore::getVolumeFreeSizeForPath(m_diskCacheDirectory.utf8().data()) / WTF::MB;
-#else
+#if !ENABLE(NETWORK_CACHE)
     SoupCache* cache = SoupNetworkSession::defaultSession().cache();
-    uint64_t diskFreeSize = getCacheDiskFreeSize(cache) / WTF::MB;
-#endif
-
-    uint64_t memSize = WTF::ramSize() / WTF::MB;
-    calculateCacheSizes(cacheModel, memSize, diskFreeSize,
-        cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval,
-        pageCacheCapacity, urlCacheMemoryCapacity, urlCacheDiskCapacity);
-
-#if ENABLE(NETWORK_CACHE)
-    auto& networkCache = NetworkCache::singleton();
-    if (networkCache.isEnabled())
-        networkCache.setCapacity(urlCacheDiskCapacity);
-#else
     if (urlCacheDiskCapacity > soup_cache_get_max_size(cache))
         soup_cache_set_max_size(cache, urlCacheDiskCapacity);
+#else
+    UNUSED_PARAM(urlCacheDiskCapacity);
 #endif
 }
 
index ccd78ae..403f34d 100644 (file)
 #include "CacheModel.h"
 
 #include <algorithm>
+#include <wtf/RAMSize.h>
+#include <wtf/StdLibExtras.h>
 
 namespace WebKit {
 
-void calculateCacheSizes(CacheModel cacheModel, uint64_t memorySize, uint64_t diskFreeSize,
-    unsigned& cacheTotalCapacity, unsigned& cacheMinDeadCapacity, unsigned& cacheMaxDeadCapacity, std::chrono::seconds& deadDecodedDataDeletionInterval,
-    unsigned& pageCacheCapacity, unsigned long& urlCacheMemoryCapacity, unsigned long& urlCacheDiskCapacity)
+void calculateMemoryCacheSizes(CacheModel cacheModel, unsigned& cacheTotalCapacity, unsigned& cacheMinDeadCapacity, unsigned& cacheMaxDeadCapacity, std::chrono::seconds& deadDecodedDataDeletionInterval, unsigned& pageCacheCapacity)
 {
+    uint64_t memorySize = ramSize() / MB;
+
     switch (cacheModel) {
     case CacheModelDocumentViewer: {
         // Page cache capacity (in pages)
@@ -41,23 +43,17 @@ void calculateCacheSizes(CacheModel cacheModel, uint64_t memorySize, uint64_t di
 
         // Object cache capacities (in bytes)
         if (memorySize >= 2048)
-            cacheTotalCapacity = 96 * 1024 * 1024;
+            cacheTotalCapacity = 96 * MB;
         else if (memorySize >= 1536)
-            cacheTotalCapacity = 64 * 1024 * 1024;
+            cacheTotalCapacity = 64 * MB;
         else if (memorySize >= 1024)
-            cacheTotalCapacity = 32 * 1024 * 1024;
+            cacheTotalCapacity = 32 * MB;
         else if (memorySize >= 512)
-            cacheTotalCapacity = 16 * 1024 * 1024;
+            cacheTotalCapacity = 16 * MB;
 
         cacheMinDeadCapacity = 0;
         cacheMaxDeadCapacity = 0;
 
-        // Foundation memory cache capacity (in bytes)
-        urlCacheMemoryCapacity = 0;
-
-        // Disk cache capacity (in bytes)
-        urlCacheDiskCapacity = 0;
-
         break;
     }
     case CacheModelDocumentBrowser: {
@@ -71,37 +67,17 @@ void calculateCacheSizes(CacheModel cacheModel, uint64_t memorySize, uint64_t di
 
         // Object cache capacities (in bytes)
         if (memorySize >= 2048)
-            cacheTotalCapacity = 96 * 1024 * 1024;
+            cacheTotalCapacity = 96 * MB;
         else if (memorySize >= 1536)
-            cacheTotalCapacity = 64 * 1024 * 1024;
+            cacheTotalCapacity = 64 * MB;
         else if (memorySize >= 1024)
-            cacheTotalCapacity = 32 * 1024 * 1024;
+            cacheTotalCapacity = 32 * MB;
         else if (memorySize >= 512)
-            cacheTotalCapacity = 16 * 1024 * 1024;
+            cacheTotalCapacity = 16 * MB;
 
         cacheMinDeadCapacity = cacheTotalCapacity / 8;
         cacheMaxDeadCapacity = cacheTotalCapacity / 4;
 
-        // Foundation memory cache capacity (in bytes)
-        if (memorySize >= 2048)
-            urlCacheMemoryCapacity = 4 * 1024 * 1024;
-        else if (memorySize >= 1024)
-            urlCacheMemoryCapacity = 2 * 1024 * 1024;
-        else if (memorySize >= 512)
-            urlCacheMemoryCapacity = 1 * 1024 * 1024;
-        else
-            urlCacheMemoryCapacity =      512 * 1024; 
-
-        // Disk cache capacity (in bytes)
-        if (diskFreeSize >= 16384)
-            urlCacheDiskCapacity = 75 * 1024 * 1024;
-        else if (diskFreeSize >= 8192)
-            urlCacheDiskCapacity = 40 * 1024 * 1024;
-        else if (diskFreeSize >= 4096)
-            urlCacheDiskCapacity = 30 * 1024 * 1024;
-        else
-            urlCacheDiskCapacity = 20 * 1024 * 1024;
-
         break;
     }
     case CacheModelPrimaryWebBrowser: {
@@ -115,16 +91,16 @@ void calculateCacheSizes(CacheModel cacheModel, uint64_t memorySize, uint64_t di
 
         // Object cache capacities (in bytes)
         // (Testing indicates that value / MB depends heavily on content and
-        // browsing pattern. Even growth above 128MB can have substantial 
+        // browsing pattern. Even growth above 128MB can have substantial
         // value / MB for some content / browsing patterns.)
         if (memorySize >= 2048)
-            cacheTotalCapacity = 128 * 1024 * 1024;
+            cacheTotalCapacity = 128 * MB;
         else if (memorySize >= 1536)
-            cacheTotalCapacity = 96 * 1024 * 1024;
+            cacheTotalCapacity = 96 * MB;
         else if (memorySize >= 1024)
-            cacheTotalCapacity = 64 * 1024 * 1024;
+            cacheTotalCapacity = 64 * MB;
         else if (memorySize >= 512)
-            cacheTotalCapacity = 32 * 1024 * 1024;
+            cacheTotalCapacity = 32 * MB;
 
         cacheMinDeadCapacity = cacheTotalCapacity / 4;
         cacheMaxDeadCapacity = cacheTotalCapacity / 2;
@@ -135,37 +111,84 @@ void calculateCacheSizes(CacheModel cacheModel, uint64_t memorySize, uint64_t di
 
         deadDecodedDataDeletionInterval = std::chrono::seconds { 60 };
 
+        break;
+    }
+    default:
+        ASSERT_NOT_REACHED();
+    };
+}
+
+void calculateURLCacheSizes(CacheModel cacheModel, uint64_t diskFreeSize, unsigned& urlCacheMemoryCapacity, uint64_t& urlCacheDiskCapacity)
+{
+    switch (cacheModel) {
+    case CacheModelDocumentViewer: {
+        // Foundation memory cache capacity (in bytes)
+        urlCacheMemoryCapacity = 0;
+
+        // Disk cache capacity (in bytes)
+        urlCacheDiskCapacity = 0;
+
+        break;
+    }
+    case CacheModelDocumentBrowser: {
+        uint64_t memorySize = ramSize() / MB;
+
+        // Foundation memory cache capacity (in bytes)
+        if (memorySize >= 2048)
+            urlCacheMemoryCapacity = 4 * MB;
+        else if (memorySize >= 1024)
+            urlCacheMemoryCapacity = 2 * MB;
+        else if (memorySize >= 512)
+            urlCacheMemoryCapacity = 1 * MB;
+        else
+            urlCacheMemoryCapacity = 512 * KB;
+
+        // Disk cache capacity (in bytes)
+        if (diskFreeSize >= 16384)
+            urlCacheDiskCapacity = 75 * MB;
+        else if (diskFreeSize >= 8192)
+            urlCacheDiskCapacity = 40 * MB;
+        else if (diskFreeSize >= 4096)
+            urlCacheDiskCapacity = 30 * MB;
+        else
+            urlCacheDiskCapacity = 20 * MB;
+
+        break;
+    }
+    case CacheModelPrimaryWebBrowser: {
+        uint64_t memorySize = ramSize() / MB;
+
 #if PLATFORM(IOS)
         if (memorySize >= 1024)
-            urlCacheMemoryCapacity = 16 * 1024 * 1024;
+            urlCacheMemoryCapacity = 16 * MB;
         else
-            urlCacheMemoryCapacity = 8 * 1024 * 1024;
+            urlCacheMemoryCapacity = 8 * MB;
 #else
         // Foundation memory cache capacity (in bytes)
         // (These values are small because WebCore does most caching itself.)
         if (memorySize >= 1024)
-            urlCacheMemoryCapacity = 4 * 1024 * 1024;
+            urlCacheMemoryCapacity = 4 * MB;
         else if (memorySize >= 512)
-            urlCacheMemoryCapacity = 2 * 1024 * 1024;
+            urlCacheMemoryCapacity = 2 * MB;
         else if (memorySize >= 256)
-            urlCacheMemoryCapacity = 1 * 1024 * 1024;
+            urlCacheMemoryCapacity = 1 * MB;
         else
-            urlCacheMemoryCapacity =      512 * 1024;
+            urlCacheMemoryCapacity = 512 * KB;
 #endif
 
         // Disk cache capacity (in bytes)
         if (diskFreeSize >= 16384)
-            urlCacheDiskCapacity = 500 * 1024 * 1024;
+            urlCacheDiskCapacity = 500 * MB;
         else if (diskFreeSize >= 8192)
-            urlCacheDiskCapacity = 250 * 1024 * 1024;
+            urlCacheDiskCapacity = 250 * MB;
         else if (diskFreeSize >= 4096)
-            urlCacheDiskCapacity = 125 * 1024 * 1024;
+            urlCacheDiskCapacity = 125 * MB;
         else if (diskFreeSize >= 2048)
-            urlCacheDiskCapacity = 100 * 1024 * 1024;
+            urlCacheDiskCapacity = 100 * MB;
         else if (diskFreeSize >= 1024)
-            urlCacheDiskCapacity = 75 * 1024 * 1024;
+            urlCacheDiskCapacity = 75 * MB;
         else
-            urlCacheDiskCapacity = 50 * 1024 * 1024;
+            urlCacheDiskCapacity = 50 * MB;
 
         break;
     }
index 34ddd04..cf47345 100644 (file)
@@ -37,9 +37,8 @@ enum CacheModel {
     CacheModelPrimaryWebBrowser
 };
 
-void calculateCacheSizes(CacheModel cacheModel, uint64_t memorySize, uint64_t diskFreeSize,
-    unsigned& cacheTotalCapacity, unsigned& cacheMinDeadCapacity, unsigned& cacheMaxDeadCapacity, std::chrono::seconds& deadDecodedDataDeletionInterval,
-    unsigned& pageCacheCapacity, unsigned long& urlCacheMemoryCapacity, unsigned long& urlCacheDiskCapacity);
+void calculateMemoryCacheSizes(CacheModel, unsigned& cacheTotalCapacity, unsigned& cacheMinDeadCapacity, unsigned& cacheMaxDeadCapacity, std::chrono::seconds& deadDecodedDataDeletionInterval, unsigned& pageCacheCapacity);
+void calculateURLCacheSizes(CacheModel, uint64_t diskFreeSize, unsigned& urlCacheMemoryCapacity, uint64_t& urlCacheDiskCapacity);
 
 } // namespace WebKit
 
index ac3e1cf..1475287 100644 (file)
@@ -205,7 +205,7 @@ WebProcess::WebProcess()
     RuntimeEnabledFeatures::sharedFeatures().setWebkitIndexedDBEnabled(true);
 #endif
 
-#if PLATFORM(IOS)
+#if PLATFORM(IOS) || PLATFORM(GTK)
     PageCache::singleton().setShouldClearBackingStores(true);
 #endif
 
@@ -529,11 +529,25 @@ void WebProcess::setCacheModel(uint32_t cm)
 {
     CacheModel cacheModel = static_cast<CacheModel>(cm);
 
-    if (!m_hasSetCacheModel || cacheModel != m_cacheModel) {
-        m_hasSetCacheModel = true;
-        m_cacheModel = cacheModel;
-        platformSetCacheModel(cacheModel);
-    }
+    if (m_hasSetCacheModel && (cacheModel == m_cacheModel))
+        return;
+
+    m_hasSetCacheModel = true;
+    m_cacheModel = cacheModel;
+
+    unsigned cacheTotalCapacity = 0;
+    unsigned cacheMinDeadCapacity = 0;
+    unsigned cacheMaxDeadCapacity = 0;
+    auto deadDecodedDataDeletionInterval = std::chrono::seconds { 0 };
+    unsigned pageCacheSize = 0;
+    calculateMemoryCacheSizes(cacheModel, cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval, pageCacheSize);
+
+    auto& memoryCache = MemoryCache::singleton();
+    memoryCache.setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
+    memoryCache.setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
+    PageCache::singleton().setMaxSize(pageCacheSize);
+
+    platformSetCacheModel(cacheModel);
 }
 
 void WebProcess::clearCachedCredentials()
@@ -751,8 +765,6 @@ void WebProcess::userGestureTokenDestroyed(UserGestureToken& token)
 
 void WebProcess::clearResourceCaches(ResourceCachesToClear resourceCachesToClear)
 {
-    platformClearResourceCaches(resourceCachesToClear);
-
     // Toggling the cache model like this forces the cache to evict all its in-memory resources.
     // FIXME: We need a better way to do this.
     CacheModel cacheModel = m_cacheModel;
index 8a5222d..08b4dbd 100644 (file)
@@ -261,7 +261,6 @@ private:
     void resetPlugInAutoStartOriginHashes(const HashMap<WebCore::SessionID, HashMap<unsigned, double>>& hashes);
 
     void platformSetCacheModel(CacheModel);
-    void platformClearResourceCaches(ResourceCachesToClear);
 
     void setEnhancedAccessibility(bool);
     
index 503671b..4d71566 100644 (file)
 #import <WebCore/FontCache.h>
 #import <WebCore/FontCascade.h>
 #import <WebCore/LocalizedStrings.h>
-#import <WebCore/MemoryCache.h>
 #import <WebCore/MemoryPressureHandler.h>
 #import <WebCore/NSAccessibilitySPI.h>
-#import <WebCore/PageCache.h>
 #import <WebCore/RuntimeApplicationChecks.h>
 #import <WebCore/pthreadSPI.h>
 #import <WebCore/VNodeTracker.h>
@@ -61,7 +59,6 @@
 #import <dispatch/dispatch.h>
 #import <objc/runtime.h>
 #import <stdio.h>
-#import <wtf/RAMSize.h>
 
 #if PLATFORM(IOS)
 #import <WebCore/GraphicsServicesSPI.h>
@@ -75,45 +72,8 @@ using namespace WebCore;
 
 namespace WebKit {
 
-static uint64_t volumeFreeSize(NSString *path)
+void WebProcess::platformSetCacheModel(CacheModel)
 {
-    NSDictionary *fileSystemAttributesDictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:path error:NULL];
-    return [[fileSystemAttributesDictionary objectForKey:NSFileSystemFreeSize] unsignedLongLongValue];
-}
-
-void WebProcess::platformSetCacheModel(CacheModel cacheModel)
-{
-    RetainPtr<NSString> nsurlCacheDirectory = adoptNS((NSString *)WKCopyFoundationCacheDirectory());
-    if (!nsurlCacheDirectory)
-        nsurlCacheDirectory = NSHomeDirectory();
-
-    uint64_t memSize = ramSize() / 1024 / 1024;
-
-    // As a fudge factor, use 1000 instead of 1024, in case the reported byte 
-    // count doesn't align exactly to a megabyte boundary.
-    uint64_t diskFreeSize = volumeFreeSize(nsurlCacheDirectory.get()) / 1024 / 1000;
-
-    unsigned cacheTotalCapacity = 0;
-    unsigned cacheMinDeadCapacity = 0;
-    unsigned cacheMaxDeadCapacity = 0;
-    auto deadDecodedDataDeletionInterval = std::chrono::seconds { 0 };
-    unsigned pageCacheSize = 0;
-    unsigned long urlCacheMemoryCapacity = 0;
-    unsigned long urlCacheDiskCapacity = 0;
-
-    calculateCacheSizes(cacheModel, memSize, diskFreeSize,
-        cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval,
-        pageCacheSize, urlCacheMemoryCapacity, urlCacheDiskCapacity);
-
-    auto& memoryCache = MemoryCache::singleton();
-    memoryCache.setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
-    memoryCache.setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
-    PageCache::singleton().setMaxSize(pageCacheSize);
-}
-
-void WebProcess::platformClearResourceCaches(ResourceCachesToClear cachesToClear)
-{
-    // FIXME: Remove this.
 }
 
 #if USE(APPKIT)
index 5fda21b..0d69060 100644 (file)
 #include "config.h"
 #include "WebProcess.h"
 
-#include "CertificateInfo.h"
-#include "WebCookieManager.h"
 #include "WebProcessCreationParameters.h"
-#include <WebCore/FileSystem.h>
-#include <WebCore/Language.h>
 #include <WebCore/MemoryCache.h>
-#include <WebCore/PageCache.h>
-#include <WebCore/ResourceHandle.h>
-#include <WebCore/SoupNetworkSession.h>
-#include <libsoup/soup.h>
-#include <wtf/RAMSize.h>
-#include <wtf/glib/GRefPtr.h>
-#include <wtf/glib/GUniquePtr.h>
 
 namespace WebKit {
 
 void WebProcess::platformSetCacheModel(CacheModel cacheModel)
 {
-    unsigned cacheTotalCapacity = 0;
-    unsigned cacheMinDeadCapacity = 0;
-    unsigned cacheMaxDeadCapacity = 0;
-    auto deadDecodedDataDeletionInterval = std::chrono::seconds { 0 };
-    unsigned pageCacheSize = 0;
-
-    unsigned long urlCacheMemoryCapacity = 0;
-    unsigned long urlCacheDiskCapacity = 0;
-
-    uint64_t diskFreeSize = 0;
-
-    uint64_t memSize = WTF::ramSize() / WTF::MB;
-    calculateCacheSizes(cacheModel, memSize, diskFreeSize,
-                        cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval,
-                        pageCacheSize, urlCacheMemoryCapacity, urlCacheDiskCapacity);
-
-    auto& memoryCache = WebCore::MemoryCache::singleton();
-    memoryCache.setDisabled(cacheModel == CacheModelDocumentViewer);
-    memoryCache.setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
-    memoryCache.setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
-    WebCore::PageCache::singleton().setMaxSize(pageCacheSize);
-
-#if PLATFORM(GTK)
-    WebCore::PageCache::singleton().setShouldClearBackingStores(true);
-#endif
-}
-
-void WebProcess::platformClearResourceCaches(ResourceCachesToClear cachesToClear)
-{
+    // FIXME: this is no longer soup specific, this file should be renamed.
+    WebCore::MemoryCache::singleton().setDisabled(cacheModel == CacheModelDocumentViewer);
 }
 
-void WebProcess::platformInitializeWebProcess(WebProcessCreationParameters&& parameters)
+void WebProcess::platformInitializeWebProcess(WebProcessCreationParameters&&)
 {
 }