Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: Source/core/fetch/MemoryCache.h

Issue 174523002: Reland "Move MemoryCache implementation details out of Resource" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/fetch/ImageResource.cpp ('k') | Source/core/fetch/MemoryCache.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/fetch/Resource.h" 28 #include "core/fetch/Resource.h"
29 #include "core/fetch/ResourcePtr.h"
29 #include "public/platform/WebThread.h" 30 #include "public/platform/WebThread.h"
30 #include "wtf/HashMap.h" 31 #include "wtf/HashMap.h"
31 #include "wtf/Noncopyable.h" 32 #include "wtf/Noncopyable.h"
32 #include "wtf/Vector.h" 33 #include "wtf/Vector.h"
33 #include "wtf/text/StringHash.h" 34 #include "wtf/text/StringHash.h"
34 #include "wtf/text/WTFString.h" 35 #include "wtf/text/WTFString.h"
35 36
36 namespace WebCore { 37 namespace WebCore {
37 38
38 class CSSStyleSheetResource; 39 class CSSStyleSheetResource;
(...skipping 19 matching lines...) Expand all
58 59
59 // Enable this macro to periodically log information about the memory cache. 60 // Enable this macro to periodically log information about the memory cache.
60 #undef MEMORY_CACHE_STATS 61 #undef MEMORY_CACHE_STATS
61 62
62 class MemoryCache FINAL : public blink::WebThread::TaskObserver { 63 class MemoryCache FINAL : public blink::WebThread::TaskObserver {
63 WTF_MAKE_NONCOPYABLE(MemoryCache); WTF_MAKE_FAST_ALLOCATED; 64 WTF_MAKE_NONCOPYABLE(MemoryCache); WTF_MAKE_FAST_ALLOCATED;
64 public: 65 public:
65 MemoryCache(); 66 MemoryCache();
66 virtual ~MemoryCache(); 67 virtual ~MemoryCache();
67 68
68 typedef HashMap<String, Resource*> ResourceMap; 69 class MemoryCacheEntry {
70 public:
71 static PassOwnPtr<MemoryCacheEntry> create(Resource* resource) { return adoptPtr(new MemoryCacheEntry(resource)); }
72
73 ResourcePtr<Resource> m_resource;
74 bool m_inLiveDecodedResourcesList;
75
76 MemoryCacheEntry* m_previousInLiveResourcesList;
77 MemoryCacheEntry* m_nextInLiveResourcesList;
78 MemoryCacheEntry* m_previousInAllResourcesList;
79 MemoryCacheEntry* m_nextInAllResourcesList;
80
81 private:
82 MemoryCacheEntry(Resource* resource)
83 : m_resource(resource)
84 , m_inLiveDecodedResourcesList(false)
85 , m_previousInLiveResourcesList(0)
86 , m_nextInLiveResourcesList(0)
87 , m_previousInAllResourcesList(0)
88 , m_nextInAllResourcesList(0)
89 {
90 }
91 };
69 92
70 struct LRUList { 93 struct LRUList {
71 Resource* m_head; 94 MemoryCacheEntry* m_head;
72 Resource* m_tail; 95 MemoryCacheEntry* m_tail;
73 LRUList() : m_head(0), m_tail(0) { } 96 LRUList() : m_head(0), m_tail(0) { }
74 }; 97 };
75 98
76 struct TypeStatistic { 99 struct TypeStatistic {
77 int count; 100 int count;
78 int size; 101 int size;
79 int liveSize; 102 int liveSize;
80 int decodedSize; 103 int decodedSize;
81 int encodedSize; 104 int encodedSize;
82 int encodedSizeDuplicatedInDataURLs; 105 int encodedSizeDuplicatedInDataURLs;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // Calls to put the cached resource into and out of LRU lists. 154 // Calls to put the cached resource into and out of LRU lists.
132 void insertInLRUList(Resource*); 155 void insertInLRUList(Resource*);
133 void removeFromLRUList(Resource*); 156 void removeFromLRUList(Resource*);
134 157
135 // Called to adjust the cache totals when a resource changes size. 158 // Called to adjust the cache totals when a resource changes size.
136 void adjustSize(bool live, ptrdiff_t delta); 159 void adjustSize(bool live, ptrdiff_t delta);
137 160
138 // Track decoded resources that are in the cache and referenced by a Web pag e. 161 // Track decoded resources that are in the cache and referenced by a Web pag e.
139 void insertInLiveDecodedResourcesList(Resource*); 162 void insertInLiveDecodedResourcesList(Resource*);
140 void removeFromLiveDecodedResourcesList(Resource*); 163 void removeFromLiveDecodedResourcesList(Resource*);
164 bool isInLiveDecodedResourcesList(Resource*);
141 165
142 void addToLiveResourcesSize(Resource*); 166 void addToLiveResourcesSize(Resource*);
143 void removeFromLiveResourcesSize(Resource*); 167 void removeFromLiveResourcesSize(Resource*);
144 168
145 static void removeURLFromCache(ExecutionContext*, const KURL&); 169 static void removeURLFromCache(ExecutionContext*, const KURL&);
146 170
147 Statistics getStatistics(); 171 Statistics getStatistics();
148 172
149 size_t minDeadCapacity() const { return m_minDeadCapacity; } 173 size_t minDeadCapacity() const { return m_minDeadCapacity; }
150 size_t maxDeadCapacity() const { return m_maxDeadCapacity; } 174 size_t maxDeadCapacity() const { return m_maxDeadCapacity; }
151 size_t capacity() const { return m_capacity; } 175 size_t capacity() const { return m_capacity; }
152 size_t liveSize() const { return m_liveSize; } 176 size_t liveSize() const { return m_liveSize; }
153 size_t deadSize() const { return m_deadSize; } 177 size_t deadSize() const { return m_deadSize; }
154 178
155 // TaskObserver implementation 179 // TaskObserver implementation
156 virtual void willProcessTask() OVERRIDE; 180 virtual void willProcessTask() OVERRIDE;
157 virtual void didProcessTask() OVERRIDE; 181 virtual void didProcessTask() OVERRIDE;
158 182
159 private: 183 private:
160 LRUList* lruListFor(Resource*); 184 LRUList* lruListFor(MemoryCacheEntry*);
161 185
162 #ifdef MEMORY_CACHE_STATS 186 #ifdef MEMORY_CACHE_STATS
163 void dumpStats(Timer<MemoryCache>*); 187 void dumpStats(Timer<MemoryCache>*);
164 void dumpLRULists(bool includeLive) const; 188 void dumpLRULists(bool includeLive) const;
165 #endif 189 #endif
166 190
167 size_t liveCapacity() const; 191 size_t liveCapacity() const;
168 size_t deadCapacity() const; 192 size_t deadCapacity() const;
169 193
170 // pruneDeadResources() - Flush decoded and encoded data from resources not referenced by Web pages. 194 // pruneDeadResources() - Flush decoded and encoded data from resources not referenced by Web pages.
(...skipping 25 matching lines...) Expand all
196 // more resources than the cached resource map, since it can also hold "stal e" multiple versions of objects that are 220 // more resources than the cached resource map, since it can also hold "stal e" multiple versions of objects that are
197 // waiting to die when the clients referencing them go away. 221 // waiting to die when the clients referencing them go away.
198 Vector<LRUList, 32> m_allResources; 222 Vector<LRUList, 32> m_allResources;
199 223
200 // Lists just for live resources with decoded data. Access to this list is b ased off of painting the resource. 224 // Lists just for live resources with decoded data. Access to this list is b ased off of painting the resource.
201 // The lists are ordered by decode priority, with higher indices having high er priorities. 225 // The lists are ordered by decode priority, with higher indices having high er priorities.
202 LRUList m_liveDecodedResources[Resource::CacheLiveResourcePriorityHigh + 1]; 226 LRUList m_liveDecodedResources[Resource::CacheLiveResourcePriorityHigh + 1];
203 227
204 // A URL-based map of all resources that are in the cache (including the fre shest version of objects that are currently being 228 // A URL-based map of all resources that are in the cache (including the fre shest version of objects that are currently being
205 // referenced by a Web page). 229 // referenced by a Web page).
206 HashMap<String, Resource*> m_resources; 230 typedef HashMap<String, OwnPtr<MemoryCacheEntry> > ResourceMap;
231 ResourceMap m_resources;
207 232
208 friend class MemoryCacheTest; 233 friend class MemoryCacheTest;
209 #ifdef MEMORY_CACHE_STATS 234 #ifdef MEMORY_CACHE_STATS
210 Timer<MemoryCache> m_statsTimer; 235 Timer<MemoryCache> m_statsTimer;
211 #endif 236 #endif
212 }; 237 };
213 238
214 // Returns the global cache. 239 // Returns the global cache.
215 MemoryCache* memoryCache(); 240 MemoryCache* memoryCache();
216 241
217 // Sets the global cache, used to swap in a test instance. 242 // Sets the global cache, used to swap in a test instance.
218 void setMemoryCacheForTesting(MemoryCache*); 243 void setMemoryCacheForTesting(MemoryCache*);
219 244
220 } 245 }
221 246
222 #endif 247 #endif
OLDNEW
« no previous file with comments | « Source/core/fetch/ImageResource.cpp ('k') | Source/core/fetch/MemoryCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698