- Revision
- 184096
- Author
- [email protected]
- Date
- 2015-05-11 07:00:44 -0700 (Mon, 11 May 2015)
Log Message
Merge r183255 - [SOUP] Use a webkit subdirectory for the disk cache
https://bugs.webkit.org/show_bug.cgi?id=144048
Reviewed by Martin Robinson.
Source/WebCore:
Add a static method to SoupNetworkSession to clear a soup cache
given its directory.
* platform/network/soup/SoupNetworkSession.cpp:
(WebCore::strIsNumeric):
(WebCore::SoupNetworkSession::clearCache):
* platform/network/soup/SoupNetworkSession.h:
Source/WebKit2:
Recent versions of libsoup remove any file in cache dir not
referenced by the index when the cache is loaded to workaround
leaked resources when load/dump is unbalanced for whatever reason,
like a crash. We currently use $XDG_CACHE_HOME/app-name as default
disk cache directory, but that directory could be used by apps to
cache other things, and the soup cache might end up deleting other
stuff. The soup cache assumes the given directory is only for the
disk cache, so we should ensure that.
* NetworkProcess/soup/NetworkProcessSoup.cpp:
(WebKit::NetworkProcess::platformInitializeNetworkProcess): Append
webkit to the given disk cache and clear the previous soup cache if it exists.
* WebProcess/soup/WebProcessSoup.cpp:
(WebKit::WebProcess::platformInitializeWebProcess): Ditto.
Modified Paths
Diff
Modified: releases/WebKitGTK/webkit-2.8/Source/WebCore/ChangeLog (184095 => 184096)
--- releases/WebKitGTK/webkit-2.8/Source/WebCore/ChangeLog 2015-05-11 13:43:33 UTC (rev 184095)
+++ releases/WebKitGTK/webkit-2.8/Source/WebCore/ChangeLog 2015-05-11 14:00:44 UTC (rev 184096)
@@ -1,3 +1,18 @@
+2015-04-24 Carlos Garcia Campos <[email protected]>
+
+ [SOUP] Use a webkit subdirectory for the disk cache
+ https://bugs.webkit.org/show_bug.cgi?id=144048
+
+ Reviewed by Martin Robinson.
+
+ Add a static method to SoupNetworkSession to clear a soup cache
+ given its directory.
+
+ * platform/network/soup/SoupNetworkSession.cpp:
+ (WebCore::strIsNumeric):
+ (WebCore::SoupNetworkSession::clearCache):
+ * platform/network/soup/SoupNetworkSession.h:
+
2015-04-23 Chris Dumez <[email protected]>
[WK2] WebDiagnosticLoggingClient is leaking
Modified: releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/network/soup/SoupNetworkSession.cpp (184095 => 184096)
--- releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/network/soup/SoupNetworkSession.cpp 2015-05-11 13:43:33 UTC (rev 184095)
+++ releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/network/soup/SoupNetworkSession.cpp 2015-05-11 14:00:44 UTC (rev 184096)
@@ -31,9 +31,11 @@
#include "AuthenticationChallenge.h"
#include "CookieJarSoup.h"
+#include "FileSystem.h"
#include "GUniquePtrSoup.h"
#include "Logging.h"
#include "ResourceHandle.h"
+#include <glib/gstdio.h>
#include <libsoup/soup.h>
#include <wtf/text/CString.h>
#include <wtf/text/StringBuilder.h>
@@ -165,6 +167,37 @@
return soupCache ? SOUP_CACHE(soupCache) : nullptr;
}
+static inline bool stringIsNumeric(const char* str)
+{
+ while (*str) {
+ if (!g_ascii_isdigit(*str))
+ return false;
+ str++;
+ }
+ return true;
+}
+
+void SoupNetworkSession::clearCache(const String& cacheDirectory)
+{
+ CString cachePath = fileSystemRepresentation(cacheDirectory);
+ GUniquePtr<char> cacheFile(g_build_filename(cachePath.data(), "soup.cache2", nullptr));
+ if (!g_file_test(cacheFile.get(), G_FILE_TEST_IS_REGULAR))
+ return;
+
+ GUniquePtr<GDir> dir(g_dir_open(cachePath.data(), 0, nullptr));
+ if (!dir)
+ return;
+
+ while (const char* name = g_dir_read_name(dir.get())) {
+ if (!g_str_has_prefix(name, "soup.cache") && !stringIsNumeric(name))
+ continue;
+
+ GUniquePtr<gchar> filename(g_build_filename(cachePath.data(), name, nullptr));
+ if (g_file_test(filename.get(), G_FILE_TEST_IS_REGULAR))
+ g_unlink(filename.get());
+ }
+}
+
void SoupNetworkSession::setSSLPolicy(SSLPolicy flags)
{
g_object_set(m_soupSession.get(),
Modified: releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/network/soup/SoupNetworkSession.h (184095 => 184096)
--- releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/network/soup/SoupNetworkSession.h 2015-05-11 13:43:33 UTC (rev 184095)
+++ releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/network/soup/SoupNetworkSession.h 2015-05-11 14:00:44 UTC (rev 184096)
@@ -60,6 +60,7 @@
void setCache(SoupCache*);
SoupCache* cache() const;
+ static void clearCache(const String& cacheDirectory);
void setSSLPolicy(SSLPolicy);
SSLPolicy sslPolicy() const;
Modified: releases/WebKitGTK/webkit-2.8/Source/WebKit2/ChangeLog (184095 => 184096)
--- releases/WebKitGTK/webkit-2.8/Source/WebKit2/ChangeLog 2015-05-11 13:43:33 UTC (rev 184095)
+++ releases/WebKitGTK/webkit-2.8/Source/WebKit2/ChangeLog 2015-05-11 14:00:44 UTC (rev 184096)
@@ -1,3 +1,25 @@
+2015-04-24 Carlos Garcia Campos <[email protected]>
+
+ [SOUP] Use a webkit subdirectory for the disk cache
+ https://bugs.webkit.org/show_bug.cgi?id=144048
+
+ Reviewed by Martin Robinson.
+
+ Recent versions of libsoup remove any file in cache dir not
+ referenced by the index when the cache is loaded to workaround
+ leaked resources when load/dump is unbalanced for whatever reason,
+ like a crash. We currently use $XDG_CACHE_HOME/app-name as default
+ disk cache directory, but that directory could be used by apps to
+ cache other things, and the soup cache might end up deleting other
+ stuff. The soup cache assumes the given directory is only for the
+ disk cache, so we should ensure that.
+
+ * NetworkProcess/soup/NetworkProcessSoup.cpp:
+ (WebKit::NetworkProcess::platformInitializeNetworkProcess): Append
+ webkit to the given disk cache and clear the previous soup cache if it exists.
+ * WebProcess/soup/WebProcessSoup.cpp:
+ (WebKit::WebProcess::platformInitializeWebProcess): Ditto.
+
2015-04-23 Chris Dumez <[email protected]>
[WK2] WebDiagnosticLoggingClient is leaking
Modified: releases/WebKitGTK/webkit-2.8/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp (184095 => 184096)
--- releases/WebKitGTK/webkit-2.8/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp 2015-05-11 13:43:33 UTC (rev 184095)
+++ releases/WebKitGTK/webkit-2.8/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp 2015-05-11 14:00:44 UTC (rev 184096)
@@ -83,7 +83,13 @@
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));
+
+ // We used to use the given cache directory for the soup cache, but now we use a subdirectory to avoid
+ // conflicts with other cache files in the same directory. Remove the old cache files if they still exist.
+ SoupNetworkSession::defaultSession().clearCache(parameters.diskCacheDirectory);
+
+ String diskCachePath = WebCore::pathByAppendingComponent(parameters.diskCacheDirectory, "webkit");
+ GRefPtr<SoupCache> soupCache = adoptGRef(soup_cache_new(diskCachePath.utf8().data(), SOUP_CACHE_SINGLE_USER));
SoupNetworkSession::defaultSession().setCache(soupCache.get());
// Set an initial huge max_size for the SoupCache so the call to soup_cache_load() won't evict any cached
// resource. The final size of the cache will be set by NetworkProcess::platformSetCacheModel().
Modified: releases/WebKitGTK/webkit-2.8/Source/WebKit2/WebProcess/soup/WebProcessSoup.cpp (184095 => 184096)
--- releases/WebKitGTK/webkit-2.8/Source/WebKit2/WebProcess/soup/WebProcessSoup.cpp 2015-05-11 13:43:33 UTC (rev 184095)
+++ releases/WebKitGTK/webkit-2.8/Source/WebKit2/WebProcess/soup/WebProcessSoup.cpp 2015-05-11 14:00:44 UTC (rev 184096)
@@ -154,7 +154,13 @@
return;
ASSERT(!parameters.diskCacheDirectory.isEmpty());
- GRefPtr<SoupCache> soupCache = adoptGRef(soup_cache_new(parameters.diskCacheDirectory.utf8().data(), SOUP_CACHE_SINGLE_USER));
+
+ // We used to use the given cache directory for the soup cache, but now we use a subdirectory to avoid
+ // conflicts with other cache files in the same directory. Remove the old cache files if they still exist.
+ WebCore::SoupNetworkSession::defaultSession().clearCache(parameters.diskCacheDirectory);
+
+ String diskCachePath = WebCore::pathByAppendingComponent(parameters.diskCacheDirectory, "webkit");
+ GRefPtr<SoupCache> soupCache = adoptGRef(soup_cache_new(diskCachePath.utf8().data(), SOUP_CACHE_SINGLE_USER));
WebCore::SoupNetworkSession::defaultSession().setCache(soupCache.get());
// Set an initial huge max_size for the SoupCache so the call to soup_cache_load() won't evict any cached
// resource. The final size of the cache will be set by NetworkProcess::platformSetCacheModel().