Changeset 184096 in webkit


Ignore:
Timestamp:
May 11, 2015, 7:00:44 AM (10 years ago)
Author:
Carlos Garcia Campos
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.

Location:
releases/WebKitGTK/webkit-2.8/Source
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • releases/WebKitGTK/webkit-2.8/Source/WebCore/ChangeLog

    r184095 r184096  
     12015-04-24  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [SOUP] Use a webkit subdirectory for the disk cache
     4        https://bugs.webkit.org/show_bug.cgi?id=144048
     5
     6        Reviewed by Martin Robinson.
     7
     8        Add a static method to SoupNetworkSession to clear a soup cache
     9        given its directory.
     10
     11        * platform/network/soup/SoupNetworkSession.cpp:
     12        (WebCore::strIsNumeric):
     13        (WebCore::SoupNetworkSession::clearCache):
     14        * platform/network/soup/SoupNetworkSession.h:
     15
    1162015-04-23  Chris Dumez  <cdumez@apple.com>
    217
  • releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/network/soup/SoupNetworkSession.cpp

    r180931 r184096  
    3232#include "AuthenticationChallenge.h"
    3333#include "CookieJarSoup.h"
     34#include "FileSystem.h"
    3435#include "GUniquePtrSoup.h"
    3536#include "Logging.h"
    3637#include "ResourceHandle.h"
     38#include <glib/gstdio.h>
    3739#include <libsoup/soup.h>
    3840#include <wtf/text/CString.h>
     
    166168}
    167169
     170static inline bool stringIsNumeric(const char* str)
     171{
     172    while (*str) {
     173        if (!g_ascii_isdigit(*str))
     174            return false;
     175        str++;
     176    }
     177    return true;
     178}
     179
     180void SoupNetworkSession::clearCache(const String& cacheDirectory)
     181{
     182    CString cachePath = fileSystemRepresentation(cacheDirectory);
     183    GUniquePtr<char> cacheFile(g_build_filename(cachePath.data(), "soup.cache2", nullptr));
     184    if (!g_file_test(cacheFile.get(), G_FILE_TEST_IS_REGULAR))
     185        return;
     186
     187    GUniquePtr<GDir> dir(g_dir_open(cachePath.data(), 0, nullptr));
     188    if (!dir)
     189        return;
     190
     191    while (const char* name = g_dir_read_name(dir.get())) {
     192        if (!g_str_has_prefix(name, "soup.cache") && !stringIsNumeric(name))
     193            continue;
     194
     195        GUniquePtr<gchar> filename(g_build_filename(cachePath.data(), name, nullptr));
     196        if (g_file_test(filename.get(), G_FILE_TEST_IS_REGULAR))
     197            g_unlink(filename.get());
     198    }
     199}
     200
    168201void SoupNetworkSession::setSSLPolicy(SSLPolicy flags)
    169202{
  • releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/network/soup/SoupNetworkSession.h

    r165676 r184096  
    6161    void setCache(SoupCache*);
    6262    SoupCache* cache() const;
     63    static void clearCache(const String& cacheDirectory);
    6364
    6465    void setSSLPolicy(SSLPolicy);
  • releases/WebKitGTK/webkit-2.8/Source/WebKit2/ChangeLog

    r184095 r184096  
     12015-04-24  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [SOUP] Use a webkit subdirectory for the disk cache
     4        https://bugs.webkit.org/show_bug.cgi?id=144048
     5
     6        Reviewed by Martin Robinson.
     7
     8        Recent versions of libsoup remove any file in cache dir not
     9        referenced by the index when the cache is loaded to workaround
     10        leaked resources when load/dump is unbalanced for whatever reason,
     11        like a crash. We currently use $XDG_CACHE_HOME/app-name as default
     12        disk cache directory, but that directory could be used by apps to
     13        cache other things, and the soup cache might end up deleting other
     14        stuff. The soup cache assumes the given directory is only for the
     15        disk cache, so we should ensure that.
     16
     17        * NetworkProcess/soup/NetworkProcessSoup.cpp:
     18        (WebKit::NetworkProcess::platformInitializeNetworkProcess): Append
     19        webkit to the given disk cache and clear the previous soup cache if it exists.
     20        * WebProcess/soup/WebProcessSoup.cpp:
     21        (WebKit::WebProcess::platformInitializeWebProcess): Ditto.
     22
    1232015-04-23  Chris Dumez  <cdumez@apple.com>
    224
  • releases/WebKitGTK/webkit-2.8/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp

    r177145 r184096  
    8484{
    8585    ASSERT(!parameters.diskCacheDirectory.isEmpty());
    86     GRefPtr<SoupCache> soupCache = adoptGRef(soup_cache_new(parameters.diskCacheDirectory.utf8().data(), SOUP_CACHE_SINGLE_USER));
     86
     87    // We used to use the given cache directory for the soup cache, but now we use a subdirectory to avoid
     88    // conflicts with other cache files in the same directory. Remove the old cache files if they still exist.
     89    SoupNetworkSession::defaultSession().clearCache(parameters.diskCacheDirectory);
     90
     91    String diskCachePath = WebCore::pathByAppendingComponent(parameters.diskCacheDirectory, "webkit");
     92    GRefPtr<SoupCache> soupCache = adoptGRef(soup_cache_new(diskCachePath.utf8().data(), SOUP_CACHE_SINGLE_USER));
    8793    SoupNetworkSession::defaultSession().setCache(soupCache.get());
    8894    // Set an initial huge max_size for the SoupCache so the call to soup_cache_load() won't evict any cached
  • releases/WebKitGTK/webkit-2.8/Source/WebKit2/WebProcess/soup/WebProcessSoup.cpp

    r179489 r184096  
    155155
    156156    ASSERT(!parameters.diskCacheDirectory.isEmpty());
    157     GRefPtr<SoupCache> soupCache = adoptGRef(soup_cache_new(parameters.diskCacheDirectory.utf8().data(), SOUP_CACHE_SINGLE_USER));
     157
     158    // We used to use the given cache directory for the soup cache, but now we use a subdirectory to avoid
     159    // conflicts with other cache files in the same directory. Remove the old cache files if they still exist.
     160    WebCore::SoupNetworkSession::defaultSession().clearCache(parameters.diskCacheDirectory);
     161
     162    String diskCachePath = WebCore::pathByAppendingComponent(parameters.diskCacheDirectory, "webkit");
     163    GRefPtr<SoupCache> soupCache = adoptGRef(soup_cache_new(diskCachePath.utf8().data(), SOUP_CACHE_SINGLE_USER));
    158164    WebCore::SoupNetworkSession::defaultSession().setCache(soupCache.get());
    159165    // Set an initial huge max_size for the SoupCache so the call to soup_cache_load() won't evict any cached
Note: See TracChangeset for help on using the changeset viewer.