- Revision
- 160307
- Author
- [email protected]
- Date
- 2013-12-09 04:06:40 -0800 (Mon, 09 Dec 2013)
Log Message
[WK2][Soup] Support cache model in NetworkProcess
https://bugs.webkit.org/show_bug.cgi?id=118343
Reviewed by Carlos Garcia Campos.
Original patch by Kwang Yul Seo <[email protected]> and Csaba Osztrogonác <[email protected]>.
Copied cache model code from WebProcess.
NetworkProcess is configured not to use the WebCore memory cache.
* NetworkProcess/soup/NetworkProcessSoup.cpp:
(WebKit::getCacheDiskFreeSize):
(WebKit::getMemorySize):
(WebKit::NetworkProcess::platformInitializeNetworkProcess):
Initialize soup cache.
(WebKit::NetworkProcess::platformSetCacheModel):
Copied code from WebProcess::platformSetCacheModel but removed
WebCore memory cache initialization because NetworkProcess does not use
the WebCore memory cache.
(WebKit::NetworkProcess::clearCacheForAllOrigins):
Copied code from WebProcess::clearCacheForAllOrigins.
* NetworkProcess/unix/NetworkProcessMainUnix.cpp:
Copied initialization code from WebProcessMainGtk.cpp.
(WebKit::NetworkProcessMain):
* WebProcess/soup/WebProcessSoup.cpp:
(WebKit::WebProcess::platformSetCacheModel):
Don't set the disk cache if NetworkProcess is used.
(WebKit::WebProcess::platformClearResourceCaches):
Don't clear the non-existing disk cache. (if NetworkProcess is used)
(WebKit::WebProcess::platformInitializeWebProcess):
Don't initialize the disk cache if NetworkProcess is used.
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (160306 => 160307)
--- trunk/Source/WebKit2/ChangeLog 2013-12-09 11:49:27 UTC (rev 160306)
+++ trunk/Source/WebKit2/ChangeLog 2013-12-09 12:06:40 UTC (rev 160307)
@@ -1,3 +1,37 @@
+2013-12-09 Kwang Yul Seo <[email protected]>
+
+ [WK2][Soup] Support cache model in NetworkProcess
+ https://bugs.webkit.org/show_bug.cgi?id=118343
+
+ Reviewed by Carlos Garcia Campos.
+
+ Original patch by Kwang Yul Seo <[email protected]> and Csaba Osztrogonác <[email protected]>.
+
+ Copied cache model code from WebProcess.
+ NetworkProcess is configured not to use the WebCore memory cache.
+
+ * NetworkProcess/soup/NetworkProcessSoup.cpp:
+ (WebKit::getCacheDiskFreeSize):
+ (WebKit::getMemorySize):
+ (WebKit::NetworkProcess::platformInitializeNetworkProcess):
+ Initialize soup cache.
+ (WebKit::NetworkProcess::platformSetCacheModel):
+ Copied code from WebProcess::platformSetCacheModel but removed
+ WebCore memory cache initialization because NetworkProcess does not use
+ the WebCore memory cache.
+ (WebKit::NetworkProcess::clearCacheForAllOrigins):
+ Copied code from WebProcess::clearCacheForAllOrigins.
+ * NetworkProcess/unix/NetworkProcessMainUnix.cpp:
+ Copied initialization code from WebProcessMainGtk.cpp.
+ (WebKit::NetworkProcessMain):
+ * WebProcess/soup/WebProcessSoup.cpp:
+ (WebKit::WebProcess::platformSetCacheModel):
+ Don't set the disk cache if NetworkProcess is used.
+ (WebKit::WebProcess::platformClearResourceCaches):
+ Don't clear the non-existing disk cache. (if NetworkProcess is used)
+ (WebKit::WebProcess::platformInitializeWebProcess):
+ Don't initialize the disk cache if NetworkProcess is used.
+
2013-12-09 Gustavo Noronha Silva <[email protected]>
[GTK] run-webkit-tests may DOS the system, specially in debug builds
Modified: trunk/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp (160306 => 160307)
--- trunk/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp 2013-12-09 11:49:27 UTC (rev 160306)
+++ trunk/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp 2013-12-09 12:06:40 UTC (rev 160307)
@@ -29,21 +29,81 @@
#include "NetworkProcess.h"
#include "NetworkProcessCreationParameters.h"
+#include "ResourceCachesToClear.h"
+#include <WebCore/FileSystem.h>
#include <WebCore/NotImplemented.h>
+#include <WebCore/ResourceHandle.h>
+#include <libsoup/soup.h>
+#include <wtf/gobject/GOwnPtr.h>
+#include <wtf/gobject/GRefPtr.h>
using namespace WebCore;
namespace WebKit {
-void NetworkProcess::platformInitializeNetworkProcess(const NetworkProcessCreationParameters&)
+static uint64_t getCacheDiskFreeSize(SoupCache* cache)
{
+ ASSERT(cache);
+
+ GOwnPtr<char> cacheDir;
+ g_object_get(G_OBJECT(cache), "cache-dir", &cacheDir.outPtr(), NULL);
+ if (!cacheDir)
+ return 0;
+
+ return WebCore::getVolumeFreeSizeForPath(cacheDir.get());
}
-void NetworkProcess::platformSetCacheModel(CacheModel)
+static uint64_t getMemorySize()
{
- notImplemented();
+ static uint64_t kDefaultMemorySize = 512;
+#if !OS(WINDOWS)
+ long pageSize = sysconf(_SC_PAGESIZE);
+ if (pageSize == -1)
+ return kDefaultMemorySize;
+
+ long physPages = sysconf(_SC_PHYS_PAGES);
+ if (physPages == -1)
+ return kDefaultMemorySize;
+
+ return ((pageSize / 1024) * physPages) / 1024;
+#else
+ // Fallback to default for other platforms.
+ return kDefaultMemorySize;
+#endif
}
+void NetworkProcess::platformInitializeNetworkProcess(const NetworkProcessCreationParameters& parameters)
+{
+ ASSERT(!parameters.diskCacheDirectory.isEmpty());
+ GRefPtr<SoupCache> soupCache = adoptGRef(soup_cache_new(parameters.diskCacheDirectory.utf8().data(), SOUP_CACHE_SINGLE_USER));
+ soup_session_add_feature(WebCore::ResourceHandle::defaultSession(), SOUP_SESSION_FEATURE(soupCache.get()));
+ soup_cache_load(soupCache.get());
+}
+
+void NetworkProcess::platformSetCacheModel(CacheModel cacheModel)
+{
+ unsigned cacheTotalCapacity = 0;
+ unsigned cacheMinDeadCapacity = 0;
+ unsigned cacheMaxDeadCapacity = 0;
+ double deadDecodedDataDeletionInterval = 0;
+ unsigned pageCacheCapacity = 0;
+
+ unsigned long urlCacheMemoryCapacity = 0;
+ unsigned long urlCacheDiskCapacity = 0;
+
+ SoupSession* session = ResourceHandle::defaultSession();
+ SoupCache* cache = SOUP_CACHE(soup_session_get_feature(session, SOUP_TYPE_CACHE));
+ uint64_t diskFreeSize = getCacheDiskFreeSize(cache) / 1024 / 1024;
+
+ uint64_t memSize = getMemorySize();
+ calculateCacheSizes(cacheModel, memSize, diskFreeSize,
+ cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval,
+ pageCacheCapacity, urlCacheMemoryCapacity, urlCacheDiskCapacity);
+
+ if (urlCacheDiskCapacity > soup_cache_get_max_size(cache))
+ soup_cache_set_max_size(cache, urlCacheDiskCapacity);
+}
+
void NetworkProcess::allowSpecificHTTPSCertificateForHost(const CertificateInfo&, const String&)
{
notImplemented();
@@ -51,7 +111,11 @@
void NetworkProcess::clearCacheForAllOrigins(uint32_t cachesToClear)
{
- notImplemented();
+ if (cachesToClear == InMemoryResourceCachesOnly)
+ return;
+
+ SoupSession* session = ResourceHandle::defaultSession();
+ soup_cache_clear(SOUP_CACHE(soup_session_get_feature(session, SOUP_TYPE_CACHE)));
}
void NetworkProcess::platformTerminate()
Modified: trunk/Source/WebKit2/NetworkProcess/unix/NetworkProcessMainUnix.cpp (160306 => 160307)
--- trunk/Source/WebKit2/NetworkProcess/unix/NetworkProcessMainUnix.cpp 2013-12-09 11:49:27 UTC (rev 160306)
+++ trunk/Source/WebKit2/NetworkProcess/unix/NetworkProcessMainUnix.cpp 2013-12-09 12:06:40 UTC (rev 160307)
@@ -45,6 +45,10 @@
#include <Ecore.h>
#endif
+#if USE(SOUP)
+#include <libsoup/soup.h>
+#endif
+
using namespace WebCore;
namespace WebKit {
@@ -65,7 +69,7 @@
InitializeWebKit2();
#if USE(SOUP)
- SoupSession* session = WebCore::ResourceHandle::defaultSession();
+ SoupSession* session = ResourceHandle::defaultSession();
#if PLATFORM(EFL)
// Only for EFL because GTK port uses the default resolver, which uses GIO's proxy resolver.
const char* httpProxy = getenv("http_proxy");
@@ -84,8 +88,23 @@
NetworkProcess::shared().initialize(parameters);
+#if USE(SOUP)
+ // Despite using system CAs to validate certificates we're
+ // accepting invalid certificates by default. New API will be
+ // added later to let client accept/discard invalid certificates.
+ g_object_set(session, SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, TRUE,
+ SOUP_SESSION_SSL_STRICT, FALSE, NULL);
+#endif
+
RunLoop::run();
+#if USE(SOUP)
+ if (SoupSessionFeature* soupCache = soup_session_get_feature(session, SOUP_TYPE_CACHE)) {
+ soup_cache_flush(SOUP_CACHE(soupCache));
+ soup_cache_dump(SOUP_CACHE(soupCache));
+ }
+#endif
+
return 0;
}
Modified: trunk/Source/WebKit2/WebProcess/soup/WebProcessSoup.cpp (160306 => 160307)
--- trunk/Source/WebKit2/WebProcess/soup/WebProcessSoup.cpp 2013-12-09 11:49:27 UTC (rev 160306)
+++ trunk/Source/WebKit2/WebProcess/soup/WebProcessSoup.cpp 2013-12-09 12:06:40 UTC (rev 160307)
@@ -90,10 +90,18 @@
unsigned long urlCacheMemoryCapacity = 0;
unsigned long urlCacheDiskCapacity = 0;
- SoupSession* session = WebCore::ResourceHandle::defaultSession();
- SoupCache* cache = SOUP_CACHE(soup_session_get_feature(session, SOUP_TYPE_CACHE));
- uint64_t diskFreeSize = getCacheDiskFreeSize(cache) / 1024 / 1024;
+ uint64_t diskFreeSize = 0;
+ SoupCache* cache = nullptr;
+#if ENABLE(NETWORK_PROCESS)
+ if (!m_usesNetworkProcess) {
+#endif
+ SoupSession* session = WebCore::ResourceHandle::defaultSession();
+ cache = SOUP_CACHE(soup_session_get_feature(session, SOUP_TYPE_CACHE));
+ diskFreeSize = getCacheDiskFreeSize(cache) / 1024 / 1024;
+#if ENABLE(NETWORK_PROCESS)
+ }
+#endif
uint64_t memSize = getMemorySize();
calculateCacheSizes(cacheModel, memSize, diskFreeSize,
cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval,
@@ -103,6 +111,14 @@
WebCore::memoryCache()->setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
WebCore::pageCache()->setCapacity(pageCacheCapacity);
+#if ENABLE(NETWORK_PROCESS)
+ if (!m_usesNetworkProcess) {
+#endif
+ if (urlCacheDiskCapacity > soup_cache_get_max_size(cache))
+ soup_cache_set_max_size(cache, urlCacheDiskCapacity);
+#if ENABLE(NETWORK_PROCESS)
+ }
+#endif
if (urlCacheDiskCapacity > soup_cache_get_max_size(cache))
soup_cache_set_max_size(cache, urlCacheDiskCapacity);
}
@@ -112,6 +128,11 @@
if (cachesToClear == InMemoryResourceCachesOnly)
return;
+ // If we're using the network process then it is the only one that needs to clear the disk cache.
+#if ENABLE(NETWORK_PROCESS)
+ if (m_usesNetworkProcess)
+ return;
+#endif
SoupSession* session = WebCore::ResourceHandle::defaultSession();
soup_cache_clear(SOUP_CACHE(soup_session_get_feature(session, SOUP_TYPE_CACHE)));
}
@@ -177,11 +198,16 @@
}
#endif
- ASSERT(!parameters.diskCacheDirectory.isEmpty());
- GRefPtr<SoupCache> soupCache = adoptGRef(soup_cache_new(parameters.diskCacheDirectory.utf8().data(), SOUP_CACHE_SINGLE_USER));
- soup_session_add_feature(WebCore::ResourceHandle::defaultSession(), SOUP_SESSION_FEATURE(soupCache.get()));
- soup_cache_load(soupCache.get());
-
+#if ENABLE(NETWORK_PROCESS)
+ if (!m_usesNetworkProcess) {
+#endif
+ ASSERT(!parameters.diskCacheDirectory.isEmpty());
+ GRefPtr<SoupCache> soupCache = adoptGRef(soup_cache_new(parameters.diskCacheDirectory.utf8().data(), SOUP_CACHE_SINGLE_USER));
+ soup_session_add_feature(WebCore::ResourceHandle::defaultSession(), SOUP_SESSION_FEATURE(soupCache.get()));
+ soup_cache_load(soupCache.get());
+#if ENABLE(NETWORK_PROCESS)
+ }
+#endif
if (!parameters.languages.isEmpty())
setSoupSessionAcceptLanguage(parameters.languages);