OLD | NEW |
1 /* | 1 /* |
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
3 Copyright (C) 2001 Dirk Mueller <mueller@kde.org> | 3 Copyright (C) 2001 Dirk Mueller <mueller@kde.org> |
4 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 4 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
5 | 5 |
6 This library is free software; you can redistribute it and/or | 6 This library is free software; you can redistribute it and/or |
7 modify it under the terms of the GNU Library General Public | 7 modify it under the terms of the GNU Library General Public |
8 License as published by the Free Software Foundation; either | 8 License as published by the Free Software Foundation; either |
9 version 2 of the License, or (at your option) any later version. | 9 version 2 of the License, or (at your option) any later version. |
10 | 10 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 struct Statistics { | 163 struct Statistics { |
164 TypeStatistic images; | 164 TypeStatistic images; |
165 TypeStatistic cssStyleSheets; | 165 TypeStatistic cssStyleSheets; |
166 TypeStatistic scripts; | 166 TypeStatistic scripts; |
167 TypeStatistic xslStyleSheets; | 167 TypeStatistic xslStyleSheets; |
168 TypeStatistic fonts; | 168 TypeStatistic fonts; |
169 TypeStatistic other; | 169 TypeStatistic other; |
170 }; | 170 }; |
171 | 171 |
172 Resource* resourceForURL(const KURL&); | 172 Resource* resourceForURL(const KURL&); |
| 173 Resource* resourceForURL(const KURL&, const String& cacheIdentifier); |
| 174 WillBeHeapVector<Member<Resource>> resourcesForURL(const KURL&); |
173 | 175 |
174 void add(Resource*); | 176 void add(Resource*); |
175 void replace(Resource* newResource, Resource* oldResource); | 177 void replace(Resource* newResource, Resource* oldResource); |
176 void remove(Resource*); | 178 void remove(Resource*); |
177 bool contains(const Resource*) const; | 179 bool contains(const Resource*) const; |
178 | 180 |
179 static KURL removeFragmentIdentifierIfNeeded(const KURL& originalURL); | 181 static KURL removeFragmentIdentifierIfNeeded(const KURL& originalURL); |
180 | 182 |
| 183 static String defaultCacheIdentifier(); |
| 184 |
181 // Sets the cache's memory capacities, in bytes. These will hold only approx
imately, | 185 // Sets the cache's memory capacities, in bytes. These will hold only approx
imately, |
182 // since the decoded cost of resources like scripts and stylesheets is not k
nown. | 186 // since the decoded cost of resources like scripts and stylesheets is not k
nown. |
183 // - minDeadBytes: The maximum number of bytes that dead resources should c
onsume when the cache is under pressure. | 187 // - minDeadBytes: The maximum number of bytes that dead resources should c
onsume when the cache is under pressure. |
184 // - maxDeadBytes: The maximum number of bytes that dead resources should c
onsume when the cache is not under pressure. | 188 // - maxDeadBytes: The maximum number of bytes that dead resources should c
onsume when the cache is not under pressure. |
185 // - totalBytes: The maximum number of bytes that the cache should consume
overall. | 189 // - totalBytes: The maximum number of bytes that the cache should consume
overall. |
186 void setCapacities(size_t minDeadBytes, size_t maxDeadBytes, size_t totalByt
es); | 190 void setCapacities(size_t minDeadBytes, size_t maxDeadBytes, size_t totalByt
es); |
187 void setDelayBeforeLiveDecodedPrune(double seconds) { m_delayBeforeLiveDecod
edPrune = seconds; } | 191 void setDelayBeforeLiveDecodedPrune(double seconds) { m_delayBeforeLiveDecod
edPrune = seconds; } |
188 void setMaxPruneDeferralDelay(double seconds) { m_maxPruneDeferralDelay = se
conds; } | 192 void setMaxPruneDeferralDelay(double seconds) { m_maxPruneDeferralDelay = se
conds; } |
189 | 193 |
190 void evictResources(); | 194 void evictResources(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 size_t deadCapacity() const; | 249 size_t deadCapacity() const; |
246 | 250 |
247 // pruneDeadResources() - Flush decoded and encoded data from resources not
referenced by Web pages. | 251 // pruneDeadResources() - Flush decoded and encoded data from resources not
referenced by Web pages. |
248 // pruneLiveResources() - Flush decoded data from resources still referenced
by Web pages. | 252 // pruneLiveResources() - Flush decoded data from resources still referenced
by Web pages. |
249 void pruneDeadResources(); // Automatically decide how much to prune. | 253 void pruneDeadResources(); // Automatically decide how much to prune. |
250 void pruneLiveResources(); | 254 void pruneLiveResources(); |
251 void pruneNow(double currentTime); | 255 void pruneNow(double currentTime); |
252 | 256 |
253 bool evict(MemoryCacheEntry*); | 257 bool evict(MemoryCacheEntry*); |
254 | 258 |
| 259 MemoryCacheEntry* getEntryForResource(const Resource*) const; |
| 260 |
255 static void removeURLFromCacheInternal(ExecutionContext*, const KURL&); | 261 static void removeURLFromCacheInternal(ExecutionContext*, const KURL&); |
256 | 262 |
257 bool m_inPruneResources; | 263 bool m_inPruneResources; |
258 bool m_prunePending; | 264 bool m_prunePending; |
259 double m_maxPruneDeferralDelay; | 265 double m_maxPruneDeferralDelay; |
260 double m_pruneTimeStamp; | 266 double m_pruneTimeStamp; |
261 double m_pruneFrameTimeStamp; | 267 double m_pruneFrameTimeStamp; |
262 | 268 |
263 size_t m_capacity; | 269 size_t m_capacity; |
264 size_t m_minDeadCapacity; | 270 size_t m_minDeadCapacity; |
265 size_t m_maxDeadCapacity; | 271 size_t m_maxDeadCapacity; |
266 size_t m_maxDeferredPruneDeadCapacity; | 272 size_t m_maxDeferredPruneDeadCapacity; |
267 double m_delayBeforeLiveDecodedPrune; | 273 double m_delayBeforeLiveDecodedPrune; |
268 | 274 |
269 size_t m_liveSize; // The number of bytes currently consumed by "live" resou
rces in the cache. | 275 size_t m_liveSize; // The number of bytes currently consumed by "live" resou
rces in the cache. |
270 size_t m_deadSize; // The number of bytes currently consumed by "dead" resou
rces in the cache. | 276 size_t m_deadSize; // The number of bytes currently consumed by "dead" resou
rces in the cache. |
271 | 277 |
272 // Size-adjusted and popularity-aware LRU list collection for cache objects.
This collection can hold | 278 // Size-adjusted and popularity-aware LRU list collection for cache objects.
This collection can hold |
273 // more resources than the cached resource map, since it can also hold "stal
e" multiple versions of objects that are | 279 // more resources than the cached resource map, since it can also hold "stal
e" multiple versions of objects that are |
274 // waiting to die when the clients referencing them go away. | 280 // waiting to die when the clients referencing them go away. |
275 WillBeHeapVector<MemoryCacheLRUList, 32> m_allResources; | 281 WillBeHeapVector<MemoryCacheLRUList, 32> m_allResources; |
276 | 282 |
277 // Lists just for live resources with decoded data. Access to this list is b
ased off of painting the resource. | 283 // Lists just for live resources with decoded data. Access to this list is b
ased off of painting the resource. |
278 // The lists are ordered by decode priority, with higher indices having high
er priorities. | 284 // The lists are ordered by decode priority, with higher indices having high
er priorities. |
279 MemoryCacheLRUList m_liveDecodedResources[MemoryCacheLiveResourcePriorityHig
h + 1]; | 285 MemoryCacheLRUList m_liveDecodedResources[MemoryCacheLiveResourcePriorityHig
h + 1]; |
280 | 286 |
281 // A URL-based map of all resources that are in the cache (including the fre
shest version of objects that are currently being | 287 // A URL-based map of all resources that are in the cache (including the fre
shest version of objects that are currently being |
282 // referenced by a Web page). | 288 // referenced by a Web page). |
283 typedef WillBeHeapHashMap<String, OwnPtrWillBeMember<MemoryCacheEntry>> Reso
urceMap; | 289 using ResourceMap = WillBeHeapHashMap<String, OwnPtrWillBeMember<MemoryCache
Entry>>; |
284 ResourceMap m_resources; | 290 using ResourceMapIndex = WillBeHeapHashMap<String, OwnPtrWillBeMember<Resour
ceMap>>; |
| 291 ResourceMap* ensureResourceMap(const String& cacheIdentifier); |
| 292 ResourceMapIndex m_resourceMaps; |
285 | 293 |
286 #if ENABLE(OILPAN) | 294 #if ENABLE(OILPAN) |
287 // Unlike m_allResources, m_liveResources is a set of Resource objects which | 295 // Unlike m_allResources, m_liveResources is a set of Resource objects which |
288 // should not be deleted. m_allResources only contains on-cache Resource | 296 // should not be deleted. m_allResources only contains on-cache Resource |
289 // objects. | 297 // objects. |
290 // FIXME: Can we remove manual lifetime management of Resource and this? | 298 // FIXME: Can we remove manual lifetime management of Resource and this? |
291 HeapHashSet<Member<Resource>> m_liveResources; | 299 HeapHashSet<Member<Resource>> m_liveResources; |
292 friend RawPtr<MemoryCache> replaceMemoryCacheForTesting(RawPtr<MemoryCache>)
; | 300 friend RawPtr<MemoryCache> replaceMemoryCacheForTesting(RawPtr<MemoryCache>)
; |
293 #endif | 301 #endif |
294 | 302 |
295 friend class MemoryCacheTest; | 303 friend class MemoryCacheTest; |
296 #ifdef MEMORY_CACHE_STATS | 304 #ifdef MEMORY_CACHE_STATS |
297 Timer<MemoryCache> m_statsTimer; | 305 Timer<MemoryCache> m_statsTimer; |
298 #endif | 306 #endif |
299 }; | 307 }; |
300 | 308 |
301 // Returns the global cache. | 309 // Returns the global cache. |
302 MemoryCache* memoryCache(); | 310 MemoryCache* memoryCache(); |
303 | 311 |
304 // Sets the global cache, used to swap in a test instance. Returns the old | 312 // Sets the global cache, used to swap in a test instance. Returns the old |
305 // MemoryCache object. | 313 // MemoryCache object. |
306 PassOwnPtrWillBeRawPtr<MemoryCache> replaceMemoryCacheForTesting(PassOwnPtrWillB
eRawPtr<MemoryCache>); | 314 PassOwnPtrWillBeRawPtr<MemoryCache> replaceMemoryCacheForTesting(PassOwnPtrWillB
eRawPtr<MemoryCache>); |
307 | 315 |
308 } | 316 } |
309 | 317 |
310 #endif | 318 #endif |
OLD | NEW |