OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 15 matching lines...) Expand all Loading... |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "public/web/WebCache.h" | 32 #include "public/web/WebCache.h" |
33 | 33 |
34 #include "core/fetch/MemoryCache.h" | 34 #include "core/fetch/MemoryCache.h" |
35 | 35 |
36 using blink::MemoryCache; | |
37 | |
38 namespace blink { | 36 namespace blink { |
39 | 37 |
40 // A helper method for coverting a MemoryCache::TypeStatistic to a | 38 // A helper method for coverting a MemoryCache::TypeStatistic to a |
41 // WebCache::ResourceTypeStat. | 39 // WebCache::ResourceTypeStat. |
42 static void ToResourceTypeStat(const MemoryCache::TypeStatistic& from, | 40 static void ToResourceTypeStat(const MemoryCache::TypeStatistic& from, |
43 WebCache::ResourceTypeStat& to) | 41 WebCache::ResourceTypeStat& to) |
44 { | 42 { |
45 to.count = static_cast<size_t>(from.count); | 43 to.count = static_cast<size_t>(from.count); |
46 to.size = static_cast<size_t>(from.size); | 44 to.size = static_cast<size_t>(from.size); |
47 to.liveSize = static_cast<size_t>(from.liveSize); | 45 to.liveSize = static_cast<size_t>(from.liveSize); |
48 to.decodedSize = static_cast<size_t>(from.decodedSize); | 46 to.decodedSize = static_cast<size_t>(from.decodedSize); |
49 } | 47 } |
50 | 48 |
51 void WebCache::setCapacities( | 49 void WebCache::setCapacities( |
52 size_t minDeadCapacity, size_t maxDeadCapacity, size_t capacity) | 50 size_t minDeadCapacity, size_t maxDeadCapacity, size_t capacity) |
53 { | 51 { |
54 MemoryCache* cache = blink::memoryCache(); | 52 MemoryCache* cache = memoryCache(); |
55 if (cache) | 53 if (cache) |
56 cache->setCapacities(static_cast<unsigned>(minDeadCapacity), static_cast
<unsigned>(maxDeadCapacity), static_cast<unsigned>(capacity)); | 54 cache->setCapacities(static_cast<unsigned>(minDeadCapacity), static_cast
<unsigned>(maxDeadCapacity), static_cast<unsigned>(capacity)); |
57 } | 55 } |
58 | 56 |
59 void WebCache::clear() | 57 void WebCache::clear() |
60 { | 58 { |
61 MemoryCache* cache = blink::memoryCache(); | 59 MemoryCache* cache = memoryCache(); |
62 if (cache) | 60 if (cache) |
63 cache->evictResources(); | 61 cache->evictResources(); |
64 } | 62 } |
65 | 63 |
66 void WebCache::getUsageStats(UsageStats* result) | 64 void WebCache::getUsageStats(UsageStats* result) |
67 { | 65 { |
68 ASSERT(result); | 66 ASSERT(result); |
69 | 67 |
70 MemoryCache* cache = blink::memoryCache(); | 68 MemoryCache* cache = memoryCache(); |
71 if (cache) { | 69 if (cache) { |
72 result->minDeadCapacity = cache->minDeadCapacity(); | 70 result->minDeadCapacity = cache->minDeadCapacity(); |
73 result->maxDeadCapacity = cache->maxDeadCapacity(); | 71 result->maxDeadCapacity = cache->maxDeadCapacity(); |
74 result->capacity = cache->capacity(); | 72 result->capacity = cache->capacity(); |
75 result->liveSize = cache->liveSize(); | 73 result->liveSize = cache->liveSize(); |
76 result->deadSize = cache->deadSize(); | 74 result->deadSize = cache->deadSize(); |
77 } else | 75 } else |
78 memset(result, 0, sizeof(UsageStats)); | 76 memset(result, 0, sizeof(UsageStats)); |
79 } | 77 } |
80 | 78 |
81 void WebCache::getResourceTypeStats(ResourceTypeStats* result) | 79 void WebCache::getResourceTypeStats(ResourceTypeStats* result) |
82 { | 80 { |
83 MemoryCache* cache = blink::memoryCache(); | 81 MemoryCache* cache = memoryCache(); |
84 if (cache) { | 82 if (cache) { |
85 MemoryCache::Statistics stats = cache->getStatistics(); | 83 MemoryCache::Statistics stats = cache->getStatistics(); |
86 ToResourceTypeStat(stats.images, result->images); | 84 ToResourceTypeStat(stats.images, result->images); |
87 ToResourceTypeStat(stats.cssStyleSheets, result->cssStyleSheets); | 85 ToResourceTypeStat(stats.cssStyleSheets, result->cssStyleSheets); |
88 ToResourceTypeStat(stats.scripts, result->scripts); | 86 ToResourceTypeStat(stats.scripts, result->scripts); |
89 ToResourceTypeStat(stats.xslStyleSheets, result->xslStyleSheets); | 87 ToResourceTypeStat(stats.xslStyleSheets, result->xslStyleSheets); |
90 ToResourceTypeStat(stats.fonts, result->fonts); | 88 ToResourceTypeStat(stats.fonts, result->fonts); |
91 } else | 89 } else |
92 memset(result, 0, sizeof(WebCache::ResourceTypeStats)); | 90 memset(result, 0, sizeof(WebCache::ResourceTypeStats)); |
93 } | 91 } |
94 | 92 |
95 } // namespace blink | 93 } // namespace blink |
OLD | NEW |