tizen beta release
[framework/web/webkit-efl.git] / Source / WebKit / chromium / src / WebCache.cpp
1 /*
2  * Copyright (C) 2009 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #include "config.h"
32 #include "WebCache.h"
33
34 // Instead of providing accessors, we make all members of MemoryCache public.
35 // This will make it easier to track WebCore changes to the MemoryCache class.
36 // FIXME: We should introduce public getters on the MemoryCache class.
37 #define private public
38 #include "MemoryCache.h"
39 #undef private
40
41 using namespace WebCore;
42
43 namespace WebKit {
44
45 // A helper method for coverting a MemoryCache::TypeStatistic to a
46 // WebCache::ResourceTypeStat.
47 static void ToResourceTypeStat(const MemoryCache::TypeStatistic& from,
48                                WebCache::ResourceTypeStat& to)
49 {
50     to.count = static_cast<size_t>(from.count);
51     to.size = static_cast<size_t>(from.size);
52     to.liveSize = static_cast<size_t>(from.liveSize);
53     to.decodedSize = static_cast<size_t>(from.decodedSize);
54 }
55
56 void WebCache::setCapacities(
57     size_t minDeadCapacity, size_t maxDeadCapacity, size_t capacity)
58 {
59     MemoryCache* cache = WebCore::memoryCache();
60     if (cache)
61         cache->setCapacities(static_cast<unsigned int>(minDeadCapacity),
62                              static_cast<unsigned int>(maxDeadCapacity),
63                              static_cast<unsigned int>(capacity));
64 }
65
66 void WebCache::clear()
67 {
68     MemoryCache* cache = WebCore::memoryCache();
69     if (cache)
70         cache->evictResources();
71 }
72
73 void WebCache::prune()
74 {
75     MemoryCache* cache = WebCore::memoryCache();
76     if (cache)
77         cache->prune();
78 }
79
80 void WebCache::getUsageStats(UsageStats* result)
81 {
82     ASSERT(result);
83
84     MemoryCache* cache = WebCore::memoryCache();
85     if (cache) {
86         result->minDeadCapacity = cache->m_minDeadCapacity;
87         result->maxDeadCapacity = cache->m_maxDeadCapacity;
88         result->capacity = cache->m_capacity;
89         result->liveSize = cache->m_liveSize;
90         result->deadSize = cache->m_deadSize;
91     } else
92         memset(result, 0, sizeof(UsageStats));
93 }
94
95 void WebCache::getResourceTypeStats(ResourceTypeStats* result)
96 {
97     MemoryCache* cache = WebCore::memoryCache();
98     if (cache) {
99         MemoryCache::Statistics stats = cache->getStatistics();
100         ToResourceTypeStat(stats.images, result->images);
101         ToResourceTypeStat(stats.cssStyleSheets, result->cssStyleSheets);
102         ToResourceTypeStat(stats.scripts, result->scripts);
103 #if ENABLE(XSLT)
104         ToResourceTypeStat(stats.xslStyleSheets, result->xslStyleSheets);
105 #else
106         memset(&result->xslStyleSheets, 0, sizeof(result->xslStyleSheets));
107 #endif
108         ToResourceTypeStat(stats.fonts, result->fonts);
109     } else
110         memset(result, 0, sizeof(WebCache::ResourceTypeStats));
111 }
112
113 }  // namespace WebKit