Source/WebKit2/ChangeLog

 12013-07-03 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 NOBODY (OOPS!).
 7
 8 Copied cache model code from WebProcess.
 9
 10 Moved getCacheDiskFreeSize and getMemorySize into a seperate file so
 11 they can be shared between WebProcess and NetworkProcess.
 12
 13 NetworkProcess is configured not to use the WebCore memory cache.
 14
 15 * GNUmakefile.list.am:
 16 * NetworkProcess/soup/NetworkProcessSoup.cpp:
 17 (WebKit::NetworkProcess::platformInitializeNetworkProcess):
 18 Initialize soup cache.
 19 (WebKit::NetworkProcess::platformSetCacheModel):
 20 Copied code from WebProcess::platformSetCacheModel but removed
 21 WebCore memory cache initialization because NetworkProcess does not use
 22 the WebCore memory cache.
 23 (WebKit::NetworkProcess::clearCacheForAllOrigins):
 24 Copied code from WebProcess::clearCacheForAllOrigins.
 25 * NetworkProcess/unix/NetworkProcessMainUnix.cpp:
 26 Copied initialization code from WebProcessMainGtk.cpp.
 27 (WebKit::NetworkProcessMain):
 28 * Shared/soup/CacheModelHelper.cpp: Copied from Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp.
 29 (WebKit::getCacheDiskFreeSize):
 30 Moved from WebProcessSoup.cpp to share it between WebProcess and NetworkProcess.
 31 (WebKit::getMemorySize):
 32 Moved from WebProcessSoup.cpp to share it between WebProcess and NetworkProcess.
 33 * Shared/soup/CacheModelHelper.h: Copied from Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp.
 34 * WebProcess/soup/WebProcessSoup.cpp:
 35
1362013-07-01 Kwang Yul Seo <skyul@company100.net>
237
338 Build fix: use of long long in CoreIPC::ArgumentEncoder and CoreIPC::ArgumentDecoder

Source/WebKit2/GNUmakefile.list.am

@@webkit2_sources += \
515515 Source/WebKit2/Shared/SessionState.h \
516516 Source/WebKit2/Shared/StatisticsData.cpp \
517517 Source/WebKit2/Shared/StatisticsData.h \
 518 Source/WebKit2/Shared/soup/CacheModelHelper.cpp \
 519 Source/WebKit2/Shared/soup/CacheModelHelper.h \
518520 Source/WebKit2/Shared/soup/PlatformCertificateInfo.cpp \
519521 Source/WebKit2/Shared/soup/PlatformCertificateInfo.h \
520522 Source/WebKit2/Shared/soup/SoupCookiePersistentStorageType.h \

Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp

2828#if ENABLE(NETWORK_PROCESS)
2929#include "NetworkProcess.h"
3030
 31#include "CacheModelHelper.h"
 32#include "Logging.h"
3133#include "NetworkProcessCreationParameters.h"
 34#include "ResourceCachesToClear.h"
3235#include <WebCore/NotImplemented.h>
 36#include <WebCore/ResourceHandle.h>
 37
 38#include <libsoup/soup.h>
3339
3440using namespace WebCore;
3541
3642namespace WebKit {
3743
38 void NetworkProcess::platformInitializeNetworkProcess(const NetworkProcessCreationParameters&)
 44void NetworkProcess::platformInitializeNetworkProcess(const NetworkProcessCreationParameters& parameters)
3945{
 46 ASSERT(!parameters.diskCacheDirectory.isEmpty());
 47 GRefPtr<SoupCache> soupCache = adoptGRef(soup_cache_new(parameters.diskCacheDirectory.utf8().data(), SOUP_CACHE_SINGLE_USER));
 48 soup_session_add_feature(WebCore::ResourceHandle::defaultSession(), SOUP_SESSION_FEATURE(soupCache.get()));
 49 soup_cache_load(soupCache.get());
4050}
4151
42 void NetworkProcess::platformSetCacheModel(CacheModel)
 52void NetworkProcess::platformSetCacheModel(CacheModel cacheModel)
4353{
44  notImplemented();
 54 unsigned cacheTotalCapacity = 0;
 55 unsigned cacheMinDeadCapacity = 0;
 56 unsigned cacheMaxDeadCapacity = 0;
 57 double deadDecodedDataDeletionInterval = 0;
 58 unsigned pageCacheCapacity = 0;
 59
 60 unsigned long urlCacheMemoryCapacity = 0;
 61 unsigned long urlCacheDiskCapacity = 0;
 62
 63 SoupSession* session = WebCore::ResourceHandle::defaultSession();
 64 SoupCache* cache = SOUP_CACHE(soup_session_get_feature(session, SOUP_TYPE_CACHE));
 65 uint64_t diskFreeSize = getCacheDiskFreeSize(cache) / 1024 / 1024;
 66
 67 uint64_t memSize = getMemorySize();
 68 calculateCacheSizes(cacheModel, memSize, diskFreeSize,
 69 cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval,
 70 pageCacheCapacity, urlCacheMemoryCapacity, urlCacheDiskCapacity);
 71
 72 if (urlCacheDiskCapacity > soup_cache_get_max_size(cache))
 73 soup_cache_set_max_size(cache, urlCacheDiskCapacity);
4574}
4675
4776void NetworkProcess::allowSpecificHTTPSCertificateForHost(const PlatformCertificateInfo&, const String&)

@@void NetworkProcess::allowSpecificHTTPSCertificateForHost(const PlatformCertific
5180
5281void NetworkProcess::clearCacheForAllOrigins(uint32_t cachesToClear)
5382{
54  notImplemented();
 83 if (cachesToClear == InMemoryResourceCachesOnly)
 84 return;
 85
 86 SoupSession* session = WebCore::ResourceHandle::defaultSession();
 87 soup_cache_clear(SOUP_CACHE(soup_session_get_feature(session, SOUP_TYPE_CACHE)));
5588}
5689
5790void NetworkProcess::platformTerminate()

Source/WebKit2/NetworkProcess/unix/NetworkProcessMainUnix.cpp

3131
3232#include "WKBase.h"
3333#include "WebKit2Initialize.h"
 34#include <WebCore/ResourceHandle.h>
3435#include <WebCore/RunLoop.h>
3536#include <WebKit2/NetworkProcess.h>
3637#include <error.h>
 38#include <libsoup/soup.h>
3739#include <runtime/InitializeThreading.h>
3840#include <stdlib.h>
3941#include <wtf/MainThread.h>

@@WK_EXPORT int NetworkProcessMain(int argc, char* argv[])
7173
7274 NetworkProcess::shared().initialize(parameters);
7375
 76 // Despite using system CAs to validate certificates we're
 77 // accepting invalid certificates by default. New API will be
 78 // added later to let client accept/discard invalid certificates.
 79 SoupSession* session = WebCore::ResourceHandle::defaultSession();
 80 g_object_set(session, SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, TRUE,
 81 SOUP_SESSION_SSL_STRICT, FALSE, 0);
 82
7483 RunLoop::run();
7584
 85 if (SoupSessionFeature* soupCache = soup_session_get_feature(session, SOUP_TYPE_CACHE)) {
 86 soup_cache_flush(SOUP_CACHE(soupCache));
 87 soup_cache_dump(SOUP_CACHE(soupCache));
 88 }
 89
7690 return 0;
7791}
7892

Source/WebKit2/Shared/soup/CacheModelHelper.cpp

 1/*
 2 * Copyright (C) 2010 Apple Inc. All rights reserved.
 3 * Copyright (C) 2013 Company 100 Inc.
 4 *
 5 * Redistribution and use in source and binary forms, with or without
 6 * modification, are permitted provided that the following conditions
 7 * are met:
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 *
 14 * THIS SOFTWARE IS PROVIDED BY MOTOROLA INC. AND ITS CONTRIBUTORS ``AS IS''
 15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MOTOROLA INC. OR ITS CONTRIBUTORS
 18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 24 * THE POSSIBILITY OF SUCH DAMAGE.
 25 */
 26
 27#include "config.h"
 28#include "CacheModelHelper.h"
 29
 30#include <WebCore/FileSystem.h>
 31#include <libsoup/soup.h>
 32#include <wtf/gobject/GOwnPtr.h>
 33#include <wtf/gobject/GRefPtr.h>
 34
 35using namespace WebCore;
 36
 37namespace WebKit {
 38
 39uint64_t getCacheDiskFreeSize(SoupCache* cache)
 40{
 41 ASSERT(cache);
 42
 43 GOwnPtr<char> cacheDir;
 44 g_object_get(G_OBJECT(cache), "cache-dir", &cacheDir.outPtr(), NULL);
 45 if (!cacheDir)
 46 return 0;
 47
 48 return WebCore::getVolumeFreeSizeForPath(cacheDir.get());
 49}
 50
 51uint64_t getMemorySize()
 52{
 53 static uint64_t kDefaultMemorySize = 512;
 54#if !OS(WINDOWS)
 55 long pageSize = sysconf(_SC_PAGESIZE);
 56 if (pageSize == -1)
 57 return kDefaultMemorySize;
 58
 59 long physPages = sysconf(_SC_PHYS_PAGES);
 60 if (physPages == -1)
 61 return kDefaultMemorySize;
 62
 63 return ((pageSize / 1024) * physPages) / 1024;
 64#else
 65 // Fallback to default for other platforms.
 66 return kDefaultMemorySize;
 67#endif
 68}
 69
 70} // namespace WebKit
 71

Source/WebKit2/Shared/soup/CacheModelHelper.h

 1/*
 2 * Copyright (C) 2010 Apple Inc. All rights reserved.
 3 * Copyright (C) 2013 Company 100 Inc.
 4 *
 5 * Redistribution and use in source and binary forms, with or without
 6 * modification, are permitted provided that the following conditions
 7 * are met:
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 *
 14 * THIS SOFTWARE IS PROVIDED BY MOTOROLA INC. AND ITS CONTRIBUTORS ``AS IS''
 15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MOTOROLA INC. OR ITS CONTRIBUTORS
 18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 24 * THE POSSIBILITY OF SUCH DAMAGE.
 25 */
 26
 27#ifndef CacheModelHelper_h
 28#define CacheModelHelper_h
 29
 30#include <libsoup/soup.h>
 31#include <stdint.h>
 32
 33namespace WebKit {
 34
 35uint64_t getCacheDiskFreeSize(SoupCache*);
 36uint64_t getMemorySize();
 37
 38} // namespace WebKit
 39
 40#endif // CacheModelHelper_h

Source/WebKit2/WebProcess/soup/WebProcessSoup.cpp

3131#include "SeccompFiltersWebProcessEfl.h"
3232#endif
3333
 34#include "CacheModelHelper.h"
3435#include "WebCookieManager.h"
3536#include "WebProcessCreationParameters.h"
3637#include "WebSoupRequestManager.h"

4041#include <WebCore/PageCache.h>
4142#include <WebCore/ResourceHandle.h>
4243#include <libsoup/soup.h>
43 #include <wtf/gobject/GOwnPtr.h>
4444#include <wtf/gobject/GRefPtr.h>
4545#include <wtf/text/CString.h>
4646#include <wtf/text/StringBuilder.h>
4747
4848namespace WebKit {
4949
50 static uint64_t getCacheDiskFreeSize(SoupCache* cache)
51 {
52  ASSERT(cache);
53 
54  GOwnPtr<char> cacheDir;
55  g_object_get(G_OBJECT(cache), "cache-dir", &cacheDir.outPtr(), NULL);
56  if (!cacheDir)
57  return 0;
58 
59  return WebCore::getVolumeFreeSizeForPath(cacheDir.get());
60 }
61 
62 static uint64_t getMemorySize()
63 {
64  static uint64_t kDefaultMemorySize = 512;
65 #if !OS(WINDOWS)
66  long pageSize = sysconf(_SC_PAGESIZE);
67  if (pageSize == -1)
68  return kDefaultMemorySize;
69 
70  long physPages = sysconf(_SC_PHYS_PAGES);
71  if (physPages == -1)
72  return kDefaultMemorySize;
73 
74  return ((pageSize / 1024) * physPages) / 1024;
75 #else
76  // Fallback to default for other platforms.
77  return kDefaultMemorySize;
78 #endif
79 }
80 
8150void WebProcess::platformSetCacheModel(CacheModel cacheModel)
8251{
8352 unsigned cacheTotalCapacity = 0;