- Revision
- 183255
- Author
- [email protected]
- Date
- 2015-04-24 00:17:07 -0700 (Fri, 24 Apr 2015)
Log Message
[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: trunk/Source/WebCore/ChangeLog (183254 => 183255)
--- trunk/Source/WebCore/ChangeLog 2015-04-24 07:05:35 UTC (rev 183254)
+++ trunk/Source/WebCore/ChangeLog 2015-04-24 07:17:07 UTC (rev 183255)
@@ -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 Andy Estes <[email protected]>
Fix the iOS build after r183234.
Modified: trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.cpp (183254 => 183255)
--- trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.cpp 2015-04-24 07:05:35 UTC (rev 183254)
+++ trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.cpp 2015-04-24 07:17:07 UTC (rev 183255)
@@ -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: trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.h (183254 => 183255)
--- trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.h 2015-04-24 07:05:35 UTC (rev 183254)
+++ trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.h 2015-04-24 07:17:07 UTC (rev 183255)
@@ -60,6 +60,7 @@
void setCache(SoupCache*);
SoupCache* cache() const;
+ static void clearCache(const String& cacheDirectory);
void setSSLPolicy(SSLPolicy);
SSLPolicy sslPolicy() const;
Modified: trunk/Source/WebKit2/ChangeLog (183254 => 183255)
--- trunk/Source/WebKit2/ChangeLog 2015-04-24 07:05:35 UTC (rev 183254)
+++ trunk/Source/WebKit2/ChangeLog 2015-04-24 07:17:07 UTC (rev 183255)
@@ -1,5 +1,27 @@
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-24 Carlos Garcia Campos <[email protected]>
+
Unreviewed. Remove incorrect ASSERT added in r183176.
We allow to encode null attachments.
Modified: trunk/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp (183254 => 183255)
--- trunk/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp 2015-04-24 07:05:35 UTC (rev 183254)
+++ trunk/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp 2015-04-24 07:17:07 UTC (rev 183255)
@@ -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: trunk/Source/WebKit2/WebProcess/soup/WebProcessSoup.cpp (183254 => 183255)
--- trunk/Source/WebKit2/WebProcess/soup/WebProcessSoup.cpp 2015-04-24 07:05:35 UTC (rev 183254)
+++ trunk/Source/WebKit2/WebProcess/soup/WebProcessSoup.cpp 2015-04-24 07:17:07 UTC (rev 183255)
@@ -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().