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

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

Issue 2389643002: Reflow comments in core/fetch (Closed)
Patch Set: update some comments near copyright Created 4 years, 2 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
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
22 sheets and html
22 pages from the web. It has a memory cache for these objects. 23 pages from the web. It has a memory cache for these objects.
23 */ 24 */
24 25
25 #ifndef MemoryCache_h 26 #ifndef MemoryCache_h
26 #define MemoryCache_h 27 #define MemoryCache_h
27 28
28 #include "core/CoreExport.h" 29 #include "core/CoreExport.h"
29 #include "core/fetch/Resource.h" 30 #include "core/fetch/Resource.h"
30 #include "platform/MemoryCacheDumpProvider.h" 31 #include "platform/MemoryCacheDumpProvider.h"
31 #include "platform/MemoryCoordinator.h" 32 #include "platform/MemoryCoordinator.h"
32 #include "public/platform/WebThread.h" 33 #include "public/platform/WebThread.h"
33 #include "wtf/Allocator.h" 34 #include "wtf/Allocator.h"
34 #include "wtf/HashMap.h" 35 #include "wtf/HashMap.h"
35 #include "wtf/Noncopyable.h" 36 #include "wtf/Noncopyable.h"
36 #include "wtf/Vector.h" 37 #include "wtf/Vector.h"
37 #include "wtf/text/StringHash.h" 38 #include "wtf/text/StringHash.h"
38 #include "wtf/text/WTFString.h" 39 #include "wtf/text/WTFString.h"
39 40
40 namespace blink { 41 namespace blink {
41 42
42 class Resource; 43 class Resource;
43 class KURL; 44 class KURL;
44 class ExecutionContext; 45 class ExecutionContext;
45 46
46 // This cache holds subresources used by Web pages: images, scripts, stylesheets , etc. 47 // This cache holds subresources used by Web pages: images, scripts,
48 // stylesheets, etc.
47 49
48 // The cache keeps a flexible but bounded window of dead resources that grows/sh rinks 50 // The cache keeps a flexible but bounded window of dead resources that
49 // depending on the live resource load. Here's an example of cache growth over t ime, 51 // grows/shrinks depending on the live resource load. Here's an example of cache
50 // with a min dead resource capacity of 25% and a max dead resource capacity of 50%: 52 // growth over time, with a min dead resource capacity of 25% and a max dead
51 53 // resource capacity of 50%:
52 // |-----| Dead: - 54 //
53 // |----------| Live: + 55 // Dead: -
54 // --|----------| Cache boundary: | (objects outsid e this mark have been evicted) 56 // Live: +
57 // Cache boundary: | (objects outside this mark have been evicted)
58 //
59 // |-----|
60 // |----------|
61 // --|----------|
55 // --|----------++++++++++| 62 // --|----------++++++++++|
56 // -------|-----+++++++++++++++| 63 // -------|-----+++++++++++++++|
57 // -------|-----+++++++++++++++|+++++ 64 // -------|-----+++++++++++++++|+++++
58 65
59 enum UpdateReason { UpdateForAccess, UpdateForPropertyChange }; 66 enum UpdateReason { UpdateForAccess, UpdateForPropertyChange };
60 67
61 // MemoryCacheEntry class is used only in MemoryCache class, but we don't make 68 // MemoryCacheEntry class is used only in MemoryCache class, but we don't make
62 // MemoryCacheEntry class an inner class of MemoryCache because of dependency 69 // MemoryCacheEntry class an inner class of MemoryCache because of dependency
63 // from MemoryCacheLRUList. 70 // from MemoryCacheLRUList.
64 class MemoryCacheEntry final : public GarbageCollected<MemoryCacheEntry> { 71 class MemoryCacheEntry final : public GarbageCollected<MemoryCacheEntry> {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 HeapVector<Member<Resource>> resourcesForURL(const KURL&); 174 HeapVector<Member<Resource>> resourcesForURL(const KURL&);
168 175
169 void add(Resource*); 176 void add(Resource*);
170 void remove(Resource*); 177 void remove(Resource*);
171 bool contains(const Resource*) const; 178 bool contains(const Resource*) const;
172 179
173 static KURL removeFragmentIdentifierIfNeeded(const KURL& originalURL); 180 static KURL removeFragmentIdentifierIfNeeded(const KURL& originalURL);
174 181
175 static String defaultCacheIdentifier(); 182 static String defaultCacheIdentifier();
176 183
177 // Sets the cache's memory capacities, in bytes. These will hold only approxim ately, 184 // Sets the cache's memory capacities, in bytes. These will hold only
178 // since the decoded cost of resources like scripts and stylesheets is not kno wn. 185 // approximately, since the decoded cost of resources like scripts and
179 // - minDeadBytes: The maximum number of bytes that dead resources should con sume when the cache is under pressure. 186 // stylesheets is not known.
180 // - maxDeadBytes: The maximum number of bytes that dead resources should con sume when the cache is not under pressure. 187 // - minDeadBytes: The maximum number of bytes that dead resources should
181 // - totalBytes: The maximum number of bytes that the cache should consume ov erall. 188 // consume when the cache is under pressure.
Yoav Weiss 2016/10/03 08:52:20 Indentation?
Charlie Harrison 2016/10/03 12:36:54 Done.
189 // - maxDeadBytes: The maximum number of bytes that dead resources should
190 // consume when the cache is not under pressure.
191 // - totalBytes: The maximum number of bytes that the cache should consume
192 // overall.
182 void setCapacities(size_t minDeadBytes, 193 void setCapacities(size_t minDeadBytes,
183 size_t maxDeadBytes, 194 size_t maxDeadBytes,
184 size_t totalBytes); 195 size_t totalBytes);
185 void setDelayBeforeLiveDecodedPrune(double seconds) { 196 void setDelayBeforeLiveDecodedPrune(double seconds) {
186 m_delayBeforeLiveDecodedPrune = seconds; 197 m_delayBeforeLiveDecodedPrune = seconds;
187 } 198 }
188 void setMaxPruneDeferralDelay(double seconds) { 199 void setMaxPruneDeferralDelay(double seconds) {
189 m_maxPruneDeferralDelay = seconds; 200 m_maxPruneDeferralDelay = seconds;
190 } 201 }
191 202
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 bool containedInLRUList(MemoryCacheEntry*, MemoryCacheLRUList*); 260 bool containedInLRUList(MemoryCacheEntry*, MemoryCacheLRUList*);
250 261
251 // Track decoded resources that are in the cache and referenced by a Web page. 262 // Track decoded resources that are in the cache and referenced by a Web page.
252 void insertInLiveDecodedResourcesList(MemoryCacheEntry*); 263 void insertInLiveDecodedResourcesList(MemoryCacheEntry*);
253 void removeFromLiveDecodedResourcesList(MemoryCacheEntry*); 264 void removeFromLiveDecodedResourcesList(MemoryCacheEntry*);
254 bool containedInLiveDecodedResourcesList(MemoryCacheEntry*); 265 bool containedInLiveDecodedResourcesList(MemoryCacheEntry*);
255 266
256 size_t liveCapacity() const; 267 size_t liveCapacity() const;
257 size_t deadCapacity() const; 268 size_t deadCapacity() const;
258 269
259 // pruneDeadResources() - Flush decoded and encoded data from resources not re ferenced by Web pages. 270 // pruneDeadResources() - Flush decoded and encoded data from resources not
260 // pruneLiveResources() - Flush decoded data from resources still referenced b y Web pages. 271 // referenced by Web pages.
272 // pruneLiveResources() - Flush decoded data from resources still referenced
273 // by Web pages.
261 void pruneDeadResources(PruneStrategy); 274 void pruneDeadResources(PruneStrategy);
262 void pruneLiveResources(PruneStrategy); 275 void pruneLiveResources(PruneStrategy);
263 void pruneNow(double currentTime, PruneStrategy); 276 void pruneNow(double currentTime, PruneStrategy);
264 277
265 void evict(MemoryCacheEntry*); 278 void evict(MemoryCacheEntry*);
266 279
267 MemoryCacheEntry* getEntryForResource(const Resource*) const; 280 MemoryCacheEntry* getEntryForResource(const Resource*) const;
268 281
269 static void removeURLFromCacheInternal(ExecutionContext*, const KURL&); 282 static void removeURLFromCacheInternal(ExecutionContext*, const KURL&);
270 283
271 bool m_inPruneResources; 284 bool m_inPruneResources;
272 bool m_prunePending; 285 bool m_prunePending;
273 double m_maxPruneDeferralDelay; 286 double m_maxPruneDeferralDelay;
274 double m_pruneTimeStamp; 287 double m_pruneTimeStamp;
275 double m_pruneFrameTimeStamp; 288 double m_pruneFrameTimeStamp;
276 double 289 double m_lastFramePaintTimeStamp; // used for detecting decoded resource
277 m_lastFramePaintTimeStamp; // used for detecting decoded resource thrash in the cache 290 // thrash in the cache
278 291
279 size_t m_capacity; 292 size_t m_capacity;
280 size_t m_minDeadCapacity; 293 size_t m_minDeadCapacity;
281 size_t m_maxDeadCapacity; 294 size_t m_maxDeadCapacity;
282 size_t m_maxDeferredPruneDeadCapacity; 295 size_t m_maxDeferredPruneDeadCapacity;
283 double m_delayBeforeLiveDecodedPrune; 296 double m_delayBeforeLiveDecodedPrune;
284 297
285 size_t 298 // The number of bytes currently consumed by "live" resources in the cache.
286 m_liveSize; // The number of bytes currently consumed by "live" resources in the cache. 299 size_t m_liveSize;
287 size_t 300 // The number of bytes currently consumed by "dead" resources in the cache.
288 m_deadSize; // The number of bytes currently consumed by "dead" resources in the cache. 301 size_t m_deadSize;
289 302
290 // Size-adjusted and popularity-aware LRU list collection for cache objects. T his collection can hold 303 // Size-adjusted and popularity-aware LRU list collection for cache objects.
291 // more resources than the cached resource map, since it can also hold "stale" multiple versions of objects that are 304 // This collection can hold more resources than the cached resource map, since
292 // waiting to die when the clients referencing them go away. 305 // it can also hold "stale" multiple versions of objects that are waiting to
306 // die when the clients referencing them go away.
293 HeapVector<MemoryCacheLRUList, 32> m_allResources; 307 HeapVector<MemoryCacheLRUList, 32> m_allResources;
294 308
295 // Lists just for live resources with decoded data. Access to this list is bas ed off of painting the resource. 309 // Lists just for live resources with decoded data. Access to this list is
310 // based off of painting the resource.
296 MemoryCacheLRUList m_liveDecodedResources; 311 MemoryCacheLRUList m_liveDecodedResources;
297 312
298 // A URL-based map of all resources that are in the cache (including the fresh est version of objects that are currently being 313 // A URL-based map of all resources that are in the cache (including the
299 // referenced by a Web page). 314 // freshest version of objects that are currently being referenced by a Web
300 // removeFragmentIdentifierIfNeeded() should be called for the url before usin g it as a key for the map. 315 // page). removeFragmentIdentifierIfNeeded() should be called for the url
316 // before using it as a key for the map.
301 using ResourceMap = HeapHashMap<String, Member<MemoryCacheEntry>>; 317 using ResourceMap = HeapHashMap<String, Member<MemoryCacheEntry>>;
302 using ResourceMapIndex = HeapHashMap<String, Member<ResourceMap>>; 318 using ResourceMapIndex = HeapHashMap<String, Member<ResourceMap>>;
303 ResourceMap* ensureResourceMap(const String& cacheIdentifier); 319 ResourceMap* ensureResourceMap(const String& cacheIdentifier);
304 ResourceMapIndex m_resourceMaps; 320 ResourceMapIndex m_resourceMaps;
305 321
306 friend class MemoryCacheTest; 322 friend class MemoryCacheTest;
307 }; 323 };
308 324
309 // Returns the global cache. 325 // Returns the global cache.
310 CORE_EXPORT MemoryCache* memoryCache(); 326 CORE_EXPORT MemoryCache* memoryCache();
311 327
312 // Sets the global cache, used to swap in a test instance. Returns the old 328 // Sets the global cache, used to swap in a test instance. Returns the old
313 // MemoryCache object. 329 // MemoryCache object.
314 CORE_EXPORT MemoryCache* replaceMemoryCacheForTesting(MemoryCache*); 330 CORE_EXPORT MemoryCache* replaceMemoryCacheForTesting(MemoryCache*);
315 331
316 } // namespace blink 332 } // namespace blink
317 333
318 #endif 334 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698