2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
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"
41 using namespace WebCore;
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)
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);
56 void WebCache::setCapacities(
57 size_t minDeadCapacity, size_t maxDeadCapacity, size_t capacity)
59 MemoryCache* cache = WebCore::memoryCache();
61 cache->setCapacities(static_cast<unsigned int>(minDeadCapacity),
62 static_cast<unsigned int>(maxDeadCapacity),
63 static_cast<unsigned int>(capacity));
66 void WebCache::clear()
68 MemoryCache* cache = WebCore::memoryCache();
70 cache->evictResources();
73 void WebCache::prune()
75 MemoryCache* cache = WebCore::memoryCache();
80 void WebCache::getUsageStats(UsageStats* result)
84 MemoryCache* cache = WebCore::memoryCache();
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;
92 memset(result, 0, sizeof(UsageStats));
95 void WebCache::getResourceTypeStats(ResourceTypeStats* result)
97 MemoryCache* cache = WebCore::memoryCache();
99 MemoryCache::Statistics stats = cache->getStatistics();
100 ToResourceTypeStat(stats.images, result->images);
101 ToResourceTypeStat(stats.cssStyleSheets, result->cssStyleSheets);
102 ToResourceTypeStat(stats.scripts, result->scripts);
104 ToResourceTypeStat(stats.xslStyleSheets, result->xslStyleSheets);
106 memset(&result->xslStyleSheets, 0, sizeof(result->xslStyleSheets));
108 ToResourceTypeStat(stats.fonts, result->fonts);
110 memset(result, 0, sizeof(WebCache::ResourceTypeStats));
113 } // namespace WebKit