Changeset 160307 in webkit


Ignore:
Timestamp:
Dec 9, 2013 4:06:40 AM (10 years ago)
Author:
kseo@webkit.org
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 <skyul@company100.net> and Csaba Osztrogonác <Csaba Osztrogonác>.

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.

Location:
trunk/Source/WebKit2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r160304 r160307  
     12013-12-09  Kwang Yul Seo  <skyul@company100.net>
     2
     3        [WK2][Soup] Support cache model in NetworkProcess
     4        https://bugs.webkit.org/show_bug.cgi?id=118343
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        Original patch by Kwang Yul Seo <skyul@company100.net> and Csaba Osztrogonác <ossy@webkit.org>.
     9
     10        Copied cache model code from WebProcess.
     11        NetworkProcess is configured not to use the WebCore memory cache.
     12
     13        * NetworkProcess/soup/NetworkProcessSoup.cpp:
     14        (WebKit::getCacheDiskFreeSize):
     15        (WebKit::getMemorySize):
     16        (WebKit::NetworkProcess::platformInitializeNetworkProcess):
     17        Initialize soup cache.
     18        (WebKit::NetworkProcess::platformSetCacheModel):
     19        Copied code from WebProcess::platformSetCacheModel but removed
     20        WebCore memory cache initialization because NetworkProcess does not use
     21        the WebCore memory cache.
     22        (WebKit::NetworkProcess::clearCacheForAllOrigins):
     23        Copied code from WebProcess::clearCacheForAllOrigins.
     24        * NetworkProcess/unix/NetworkProcessMainUnix.cpp:
     25        Copied initialization code from WebProcessMainGtk.cpp.
     26        (WebKit::NetworkProcessMain):
     27        * WebProcess/soup/WebProcessSoup.cpp:
     28        (WebKit::WebProcess::platformSetCacheModel):
     29        Don't set the disk cache if NetworkProcess is used.
     30        (WebKit::WebProcess::platformClearResourceCaches):
     31        Don't clear the non-existing disk cache. (if NetworkProcess is used)
     32        (WebKit::WebProcess::platformInitializeWebProcess):
     33        Don't initialize the disk cache if NetworkProcess is used.
     34
    1352013-12-09  Gustavo Noronha Silva  <gns@gnome.org>
    236
  • trunk/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp

    r159647 r160307  
    3030
    3131#include "NetworkProcessCreationParameters.h"
     32#include "ResourceCachesToClear.h"
     33#include <WebCore/FileSystem.h>
    3234#include <WebCore/NotImplemented.h>
     35#include <WebCore/ResourceHandle.h>
     36#include <libsoup/soup.h>
     37#include <wtf/gobject/GOwnPtr.h>
     38#include <wtf/gobject/GRefPtr.h>
    3339
    3440using namespace WebCore;
     
    3642namespace WebKit {
    3743
    38 void NetworkProcess::platformInitializeNetworkProcess(const NetworkProcessCreationParameters&)
     44static uint64_t getCacheDiskFreeSize(SoupCache* cache)
    3945{
     46    ASSERT(cache);
     47
     48    GOwnPtr<char> cacheDir;
     49    g_object_get(G_OBJECT(cache), "cache-dir", &cacheDir.outPtr(), NULL);
     50    if (!cacheDir)
     51        return 0;
     52
     53    return WebCore::getVolumeFreeSizeForPath(cacheDir.get());
    4054}
    4155
    42 void NetworkProcess::platformSetCacheModel(CacheModel)
     56static uint64_t getMemorySize()
    4357{
    44     notImplemented();
     58    static uint64_t kDefaultMemorySize = 512;
     59#if !OS(WINDOWS)
     60    long pageSize = sysconf(_SC_PAGESIZE);
     61    if (pageSize == -1)
     62        return kDefaultMemorySize;
     63
     64    long physPages = sysconf(_SC_PHYS_PAGES);
     65    if (physPages == -1)
     66        return kDefaultMemorySize;
     67
     68    return ((pageSize / 1024) * physPages) / 1024;
     69#else
     70    // Fallback to default for other platforms.
     71    return kDefaultMemorySize;
     72#endif
     73}
     74
     75void NetworkProcess::platformInitializeNetworkProcess(const NetworkProcessCreationParameters& parameters)
     76{
     77    ASSERT(!parameters.diskCacheDirectory.isEmpty());
     78    GRefPtr<SoupCache> soupCache = adoptGRef(soup_cache_new(parameters.diskCacheDirectory.utf8().data(), SOUP_CACHE_SINGLE_USER));
     79    soup_session_add_feature(WebCore::ResourceHandle::defaultSession(), SOUP_SESSION_FEATURE(soupCache.get()));
     80    soup_cache_load(soupCache.get());
     81}
     82
     83void NetworkProcess::platformSetCacheModel(CacheModel cacheModel)
     84{
     85    unsigned cacheTotalCapacity = 0;
     86    unsigned cacheMinDeadCapacity = 0;
     87    unsigned cacheMaxDeadCapacity = 0;
     88    double deadDecodedDataDeletionInterval = 0;
     89    unsigned pageCacheCapacity = 0;
     90
     91    unsigned long urlCacheMemoryCapacity = 0;
     92    unsigned long urlCacheDiskCapacity = 0;
     93
     94    SoupSession* session = ResourceHandle::defaultSession();
     95    SoupCache* cache = SOUP_CACHE(soup_session_get_feature(session, SOUP_TYPE_CACHE));
     96    uint64_t diskFreeSize = getCacheDiskFreeSize(cache) / 1024 / 1024;
     97
     98    uint64_t memSize = getMemorySize();
     99    calculateCacheSizes(cacheModel, memSize, diskFreeSize,
     100        cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval,
     101        pageCacheCapacity, urlCacheMemoryCapacity, urlCacheDiskCapacity);
     102
     103    if (urlCacheDiskCapacity > soup_cache_get_max_size(cache))
     104        soup_cache_set_max_size(cache, urlCacheDiskCapacity);
    45105}
    46106
     
    52112void NetworkProcess::clearCacheForAllOrigins(uint32_t cachesToClear)
    53113{
    54     notImplemented();
     114    if (cachesToClear == InMemoryResourceCachesOnly)
     115        return;
     116
     117    SoupSession* session = ResourceHandle::defaultSession();
     118    soup_cache_clear(SOUP_CACHE(soup_session_get_feature(session, SOUP_TYPE_CACHE)));
    55119}
    56120
  • trunk/Source/WebKit2/NetworkProcess/unix/NetworkProcessMainUnix.cpp

    r160302 r160307  
    4646#endif
    4747
     48#if USE(SOUP)
     49#include <libsoup/soup.h>
     50#endif
     51
    4852using namespace WebCore;
    4953
     
    6670
    6771#if USE(SOUP)
    68     SoupSession* session = WebCore::ResourceHandle::defaultSession();
     72    SoupSession* session = ResourceHandle::defaultSession();
    6973#if PLATFORM(EFL)
    7074    // Only for EFL because GTK port uses the default resolver, which uses GIO's proxy resolver.
     
    8589    NetworkProcess::shared().initialize(parameters);
    8690
     91#if USE(SOUP)
     92    // Despite using system CAs to validate certificates we're
     93    // accepting invalid certificates by default. New API will be
     94    // added later to let client accept/discard invalid certificates.
     95    g_object_set(session, SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, TRUE,
     96        SOUP_SESSION_SSL_STRICT, FALSE, NULL);
     97#endif
     98
    8799    RunLoop::run();
     100
     101#if USE(SOUP)
     102    if (SoupSessionFeature* soupCache = soup_session_get_feature(session, SOUP_TYPE_CACHE)) {
     103        soup_cache_flush(SOUP_CACHE(soupCache));
     104        soup_cache_dump(SOUP_CACHE(soupCache));
     105    }
     106#endif
    88107
    89108    return 0;
  • trunk/Source/WebKit2/WebProcess/soup/WebProcessSoup.cpp

    r159647 r160307  
    9191    unsigned long urlCacheDiskCapacity = 0;
    9292
    93     SoupSession* session = WebCore::ResourceHandle::defaultSession();
    94     SoupCache* cache = SOUP_CACHE(soup_session_get_feature(session, SOUP_TYPE_CACHE));
    95     uint64_t diskFreeSize = getCacheDiskFreeSize(cache) / 1024 / 1024;
    96 
     93    uint64_t diskFreeSize = 0;
     94    SoupCache* cache = nullptr;
     95
     96#if ENABLE(NETWORK_PROCESS)
     97    if (!m_usesNetworkProcess) {
     98#endif
     99        SoupSession* session = WebCore::ResourceHandle::defaultSession();
     100        cache = SOUP_CACHE(soup_session_get_feature(session, SOUP_TYPE_CACHE));
     101        diskFreeSize = getCacheDiskFreeSize(cache) / 1024 / 1024;
     102#if ENABLE(NETWORK_PROCESS)
     103    }
     104#endif
    97105    uint64_t memSize = getMemorySize();
    98106    calculateCacheSizes(cacheModel, memSize, diskFreeSize,
     
    104112    WebCore::pageCache()->setCapacity(pageCacheCapacity);
    105113
     114#if ENABLE(NETWORK_PROCESS)
     115    if (!m_usesNetworkProcess) {
     116#endif
     117        if (urlCacheDiskCapacity > soup_cache_get_max_size(cache))
     118            soup_cache_set_max_size(cache, urlCacheDiskCapacity);
     119#if ENABLE(NETWORK_PROCESS)
     120    }
     121#endif
    106122    if (urlCacheDiskCapacity > soup_cache_get_max_size(cache))
    107123        soup_cache_set_max_size(cache, urlCacheDiskCapacity);
     
    113129        return;
    114130
     131    // If we're using the network process then it is the only one that needs to clear the disk cache.
     132#if ENABLE(NETWORK_PROCESS)
     133    if (m_usesNetworkProcess)
     134        return;
     135#endif
    115136    SoupSession* session = WebCore::ResourceHandle::defaultSession();
    116137    soup_cache_clear(SOUP_CACHE(soup_session_get_feature(session, SOUP_TYPE_CACHE)));
     
    178199#endif
    179200
    180     ASSERT(!parameters.diskCacheDirectory.isEmpty());
    181     GRefPtr<SoupCache> soupCache = adoptGRef(soup_cache_new(parameters.diskCacheDirectory.utf8().data(), SOUP_CACHE_SINGLE_USER));
    182     soup_session_add_feature(WebCore::ResourceHandle::defaultSession(), SOUP_SESSION_FEATURE(soupCache.get()));
    183     soup_cache_load(soupCache.get());
    184 
     201#if ENABLE(NETWORK_PROCESS)
     202    if (!m_usesNetworkProcess) {
     203#endif
     204        ASSERT(!parameters.diskCacheDirectory.isEmpty());
     205        GRefPtr<SoupCache> soupCache = adoptGRef(soup_cache_new(parameters.diskCacheDirectory.utf8().data(), SOUP_CACHE_SINGLE_USER));
     206        soup_session_add_feature(WebCore::ResourceHandle::defaultSession(), SOUP_SESSION_FEATURE(soupCache.get()));
     207        soup_cache_load(soupCache.get());
     208#if ENABLE(NETWORK_PROCESS)
     209    }
     210#endif
    185211    if (!parameters.languages.isEmpty())
    186212        setSoupSessionAcceptLanguage(parameters.languages);
Note: See TracChangeset for help on using the changeset viewer.