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