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 |
11 This library is distributed in the hope that it will be useful, | 11 This library is distributed in the hope that it will be useful, |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 Library General Public License for more details. | 14 Library General Public License for more details. |
15 | 15 |
16 You should have received a copy of the GNU Library General Public License | 16 You should have received a copy of the GNU Library General Public License |
17 along with this library; see the file COPYING.LIB. If not, write to | 17 along with this library; see the file COPYING.LIB. If not, write to |
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 Boston, MA 02110-1301, USA. | 19 Boston, MA 02110-1301, USA. |
20 | 20 |
21 This class provides all functionality needed for loading images, style sheet
s and html | 21 This class provides all functionality needed for loading images, style sheet
s and html |
22 pages from the web. It has a memory cache for these objects. | 22 pages from the web. It has a memory cache for these objects. |
23 */ | 23 */ |
24 | 24 |
25 #ifndef MemoryCache_h | 25 #ifndef MemoryCache_h |
26 #define MemoryCache_h | 26 #define MemoryCache_h |
27 | 27 |
28 #include "core/CoreExport.h" | 28 #include "core/CoreExport.h" |
29 #include "core/fetch/Resource.h" | 29 #include "core/fetch/Resource.h" |
30 #include "core/fetch/ResourcePtr.h" | |
31 #include "public/platform/WebMemoryDumpProvider.h" | 30 #include "public/platform/WebMemoryDumpProvider.h" |
32 #include "public/platform/WebThread.h" | 31 #include "public/platform/WebThread.h" |
33 #include "wtf/Allocator.h" | 32 #include "wtf/Allocator.h" |
34 #include "wtf/HashMap.h" | 33 #include "wtf/HashMap.h" |
35 #include "wtf/Noncopyable.h" | 34 #include "wtf/Noncopyable.h" |
36 #include "wtf/Vector.h" | 35 #include "wtf/Vector.h" |
37 #include "wtf/text/StringHash.h" | 36 #include "wtf/text/StringHash.h" |
38 #include "wtf/text/WTFString.h" | 37 #include "wtf/text/WTFString.h" |
39 | 38 |
40 namespace blink { | 39 namespace blink { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // from MemoryCacheLRUList. | 76 // from MemoryCacheLRUList. |
78 class MemoryCacheEntry final : public GarbageCollectedFinalized<MemoryCacheEntry
> { | 77 class MemoryCacheEntry final : public GarbageCollectedFinalized<MemoryCacheEntry
> { |
79 public: | 78 public: |
80 static MemoryCacheEntry* create(Resource* resource) | 79 static MemoryCacheEntry* create(Resource* resource) |
81 { | 80 { |
82 return new MemoryCacheEntry(resource); | 81 return new MemoryCacheEntry(resource); |
83 } | 82 } |
84 DECLARE_TRACE(); | 83 DECLARE_TRACE(); |
85 void dispose(); | 84 void dispose(); |
86 | 85 |
87 ResourcePtr<Resource> m_resource; | 86 RefPtrWillBeMember<Resource> m_resource; |
88 bool m_inLiveDecodedResourcesList; | 87 bool m_inLiveDecodedResourcesList; |
89 unsigned m_accessCount; | 88 unsigned m_accessCount; |
90 MemoryCacheLiveResourcePriority m_liveResourcePriority; | 89 MemoryCacheLiveResourcePriority m_liveResourcePriority; |
91 double m_lastDecodedAccessTime; // Used as a thrash guard | 90 double m_lastDecodedAccessTime; // Used as a thrash guard |
92 | 91 |
93 Member<MemoryCacheEntry> m_previousInLiveResourcesList; | 92 Member<MemoryCacheEntry> m_previousInLiveResourcesList; |
94 Member<MemoryCacheEntry> m_nextInLiveResourcesList; | 93 Member<MemoryCacheEntry> m_nextInLiveResourcesList; |
95 Member<MemoryCacheEntry> m_previousInAllResourcesList; | 94 Member<MemoryCacheEntry> m_previousInAllResourcesList; |
96 Member<MemoryCacheEntry> m_nextInAllResourcesList; | 95 Member<MemoryCacheEntry> m_nextInAllResourcesList; |
97 | 96 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 | 265 |
267 size_t liveCapacity() const; | 266 size_t liveCapacity() const; |
268 size_t deadCapacity() const; | 267 size_t deadCapacity() const; |
269 | 268 |
270 // pruneDeadResources() - Flush decoded and encoded data from resources not
referenced by Web pages. | 269 // pruneDeadResources() - Flush decoded and encoded data from resources not
referenced by Web pages. |
271 // pruneLiveResources() - Flush decoded data from resources still referenced
by Web pages. | 270 // pruneLiveResources() - Flush decoded data from resources still referenced
by Web pages. |
272 void pruneDeadResources(PruneStrategy); | 271 void pruneDeadResources(PruneStrategy); |
273 void pruneLiveResources(PruneStrategy); | 272 void pruneLiveResources(PruneStrategy); |
274 void pruneNow(double currentTime, PruneStrategy); | 273 void pruneNow(double currentTime, PruneStrategy); |
275 | 274 |
276 bool evict(MemoryCacheEntry*); | 275 void evict(MemoryCacheEntry*); |
277 | 276 |
278 MemoryCacheEntry* getEntryForResource(const Resource*) const; | 277 MemoryCacheEntry* getEntryForResource(const Resource*) const; |
279 | 278 |
280 static void removeURLFromCacheInternal(ExecutionContext*, const KURL&); | 279 static void removeURLFromCacheInternal(ExecutionContext*, const KURL&); |
281 | 280 |
282 bool m_inPruneResources; | 281 bool m_inPruneResources; |
283 bool m_prunePending; | 282 bool m_prunePending; |
284 double m_maxPruneDeferralDelay; | 283 double m_maxPruneDeferralDelay; |
285 double m_pruneTimeStamp; | 284 double m_pruneTimeStamp; |
286 double m_pruneFrameTimeStamp; | 285 double m_pruneFrameTimeStamp; |
(...skipping 17 matching lines...) Expand all Loading... |
304 // The lists are ordered by decode priority, with higher indices having high
er priorities. | 303 // The lists are ordered by decode priority, with higher indices having high
er priorities. |
305 MemoryCacheLRUList m_liveDecodedResources[MemoryCacheLiveResourcePriorityHig
h + 1]; | 304 MemoryCacheLRUList m_liveDecodedResources[MemoryCacheLiveResourcePriorityHig
h + 1]; |
306 | 305 |
307 // A URL-based map of all resources that are in the cache (including the fre
shest version of objects that are currently being | 306 // A URL-based map of all resources that are in the cache (including the fre
shest version of objects that are currently being |
308 // referenced by a Web page). | 307 // referenced by a Web page). |
309 using ResourceMap = HeapHashMap<String, Member<MemoryCacheEntry>>; | 308 using ResourceMap = HeapHashMap<String, Member<MemoryCacheEntry>>; |
310 using ResourceMapIndex = HeapHashMap<String, Member<ResourceMap>>; | 309 using ResourceMapIndex = HeapHashMap<String, Member<ResourceMap>>; |
311 ResourceMap* ensureResourceMap(const String& cacheIdentifier); | 310 ResourceMap* ensureResourceMap(const String& cacheIdentifier); |
312 ResourceMapIndex m_resourceMaps; | 311 ResourceMapIndex m_resourceMaps; |
313 | 312 |
314 #if ENABLE(OILPAN) | |
315 // Unlike m_allResources, m_liveResources is a set of Resource objects which | |
316 // should not be deleted. m_allResources only contains on-cache Resource | |
317 // objects. | |
318 // FIXME: Can we remove manual lifetime management of Resource and this? | |
319 HeapHashSet<Member<Resource>> m_liveResources; | |
320 friend CORE_EXPORT MemoryCache* replaceMemoryCacheForTesting(MemoryCache*); | |
321 #endif | |
322 | |
323 friend class MemoryCacheTest; | 313 friend class MemoryCacheTest; |
324 #ifdef MEMORY_CACHE_STATS | 314 #ifdef MEMORY_CACHE_STATS |
325 Timer<MemoryCache> m_statsTimer; | 315 Timer<MemoryCache> m_statsTimer; |
326 #endif | 316 #endif |
327 }; | 317 }; |
328 | 318 |
329 // Returns the global cache. | 319 // Returns the global cache. |
330 CORE_EXPORT MemoryCache* memoryCache(); | 320 CORE_EXPORT MemoryCache* memoryCache(); |
331 | 321 |
332 // Sets the global cache, used to swap in a test instance. Returns the old | 322 // Sets the global cache, used to swap in a test instance. Returns the old |
333 // MemoryCache object. | 323 // MemoryCache object. |
334 CORE_EXPORT MemoryCache* replaceMemoryCacheForTesting(MemoryCache*); | 324 CORE_EXPORT MemoryCache* replaceMemoryCacheForTesting(MemoryCache*); |
335 | 325 |
336 } // namespace blink | 326 } // namespace blink |
337 | 327 |
338 #endif | 328 #endif |
OLD | NEW |