Chromium Code Reviews| 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 | 162 |
| 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 String& cacheIdentifier, const KURL&); |
|
Mike West
2014/10/24 12:43:00
If you make |cacheIdentifier| the second argument,
nhiroki
2014/10/27 14:30:13
Done.
| |
| 173 WillBeHeapVector<Member<Resource>> resourcesForURL(const KURL&); | |
| 173 | 174 |
| 174 void add(Resource*); | 175 void add(Resource*); |
| 175 void replace(Resource* newResource, Resource* oldResource); | 176 void replace(Resource* newResource, Resource* oldResource); |
| 176 void remove(Resource*); | 177 void remove(Resource*); |
| 177 bool contains(const Resource*) const; | 178 bool contains(const Resource*) const; |
| 178 | 179 |
| 179 static KURL removeFragmentIdentifierIfNeeded(const KURL& originalURL); | 180 static KURL removeFragmentIdentifierIfNeeded(const KURL& originalURL); |
| 180 | 181 |
| 182 static String defaultCacheIdentifier(); | |
| 183 | |
| 181 // Sets the cache's memory capacities, in bytes. These will hold only approx imately, | 184 // 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. | 185 // 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. | 186 // - 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. | 187 // - 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. | 188 // - 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); | 189 void setCapacities(size_t minDeadBytes, size_t maxDeadBytes, size_t totalByt es); |
| 187 void setDelayBeforeLiveDecodedPrune(double seconds) { m_delayBeforeLiveDecod edPrune = seconds; } | 190 void setDelayBeforeLiveDecodedPrune(double seconds) { m_delayBeforeLiveDecod edPrune = seconds; } |
| 188 void setMaxPruneDeferralDelay(double seconds) { m_maxPruneDeferralDelay = se conds; } | 191 void setMaxPruneDeferralDelay(double seconds) { m_maxPruneDeferralDelay = se conds; } |
| 189 | 192 |
| 190 void evictResources(); | 193 void evictResources(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 size_t deadCapacity() const; | 248 size_t deadCapacity() const; |
| 246 | 249 |
| 247 // pruneDeadResources() - Flush decoded and encoded data from resources not referenced by Web pages. | 250 // 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. | 251 // pruneLiveResources() - Flush decoded data from resources still referenced by Web pages. |
| 249 void pruneDeadResources(); // Automatically decide how much to prune. | 252 void pruneDeadResources(); // Automatically decide how much to prune. |
| 250 void pruneLiveResources(); | 253 void pruneLiveResources(); |
| 251 void pruneNow(double currentTime); | 254 void pruneNow(double currentTime); |
| 252 | 255 |
| 253 bool evict(MemoryCacheEntry*); | 256 bool evict(MemoryCacheEntry*); |
| 254 | 257 |
| 258 MemoryCacheEntry* getEntryForResource(const Resource*) const; | |
| 259 | |
| 255 static void removeURLFromCacheInternal(ExecutionContext*, const KURL&); | 260 static void removeURLFromCacheInternal(ExecutionContext*, const KURL&); |
| 256 | 261 |
| 257 bool m_inPruneResources; | 262 bool m_inPruneResources; |
| 258 bool m_prunePending; | 263 bool m_prunePending; |
| 259 double m_maxPruneDeferralDelay; | 264 double m_maxPruneDeferralDelay; |
| 260 double m_pruneTimeStamp; | 265 double m_pruneTimeStamp; |
| 261 double m_pruneFrameTimeStamp; | 266 double m_pruneFrameTimeStamp; |
| 262 | 267 |
| 263 size_t m_capacity; | 268 size_t m_capacity; |
| 264 size_t m_minDeadCapacity; | 269 size_t m_minDeadCapacity; |
| 265 size_t m_maxDeadCapacity; | 270 size_t m_maxDeadCapacity; |
| 266 size_t m_maxDeferredPruneDeadCapacity; | 271 size_t m_maxDeferredPruneDeadCapacity; |
| 267 double m_delayBeforeLiveDecodedPrune; | 272 double m_delayBeforeLiveDecodedPrune; |
| 268 | 273 |
| 269 size_t m_liveSize; // The number of bytes currently consumed by "live" resou rces in the cache. | 274 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. | 275 size_t m_deadSize; // The number of bytes currently consumed by "dead" resou rces in the cache. |
| 271 | 276 |
| 272 // Size-adjusted and popularity-aware LRU list collection for cache objects. This collection can hold | 277 // 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 | 278 // 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. | 279 // waiting to die when the clients referencing them go away. |
| 275 WillBeHeapVector<MemoryCacheLRUList, 32> m_allResources; | 280 WillBeHeapVector<MemoryCacheLRUList, 32> m_allResources; |
| 276 | 281 |
| 277 // Lists just for live resources with decoded data. Access to this list is b ased off of painting the resource. | 282 // 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. | 283 // The lists are ordered by decode priority, with higher indices having high er priorities. |
| 279 MemoryCacheLRUList m_liveDecodedResources[MemoryCacheLiveResourcePriorityHig h + 1]; | 284 MemoryCacheLRUList m_liveDecodedResources[MemoryCacheLiveResourcePriorityHig h + 1]; |
| 280 | 285 |
| 281 // A URL-based map of all resources that are in the cache (including the fre shest version of objects that are currently being | 286 // 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). | 287 // referenced by a Web page). |
| 283 typedef WillBeHeapHashMap<String, OwnPtrWillBeMember<MemoryCacheEntry>> Reso urceMap; | 288 typedef WillBeHeapHashMap<String, OwnPtrWillBeMember<MemoryCacheEntry>> Reso urceMap; |
| 284 ResourceMap m_resources; | 289 typedef WillBeHeapHashMap<String, OwnPtrWillBeMember<ResourceMap>> ResourceM apIndex; |
|
Mike West
2014/10/24 12:43:00
Nit: These should be converted to the new `using`
nhiroki
2014/10/27 14:30:13
Done.
| |
| 290 ResourceMap* getResourceMap(const String& cacheIdentifier); | |
| 291 ResourceMapIndex m_resources; | |
|
Mike West
2014/10/24 12:43:00
Nit: Perhaps `m_resourceMaps`, now?
nhiroki
2014/10/27 14:30:13
Done.
| |
| 285 | 292 |
| 286 #if ENABLE(OILPAN) | 293 #if ENABLE(OILPAN) |
| 287 // Unlike m_allResources, m_liveResources is a set of Resource objects which | 294 // Unlike m_allResources, m_liveResources is a set of Resource objects which |
| 288 // should not be deleted. m_allResources only contains on-cache Resource | 295 // should not be deleted. m_allResources only contains on-cache Resource |
| 289 // objects. | 296 // objects. |
| 290 // FIXME: Can we remove manual lifetime management of Resource and this? | 297 // FIXME: Can we remove manual lifetime management of Resource and this? |
| 291 HeapHashSet<Member<Resource>> m_liveResources; | 298 HeapHashSet<Member<Resource>> m_liveResources; |
| 292 friend RawPtr<MemoryCache> replaceMemoryCacheForTesting(RawPtr<MemoryCache>) ; | 299 friend RawPtr<MemoryCache> replaceMemoryCacheForTesting(RawPtr<MemoryCache>) ; |
| 293 #endif | 300 #endif |
| 294 | 301 |
| 295 friend class MemoryCacheTest; | 302 friend class MemoryCacheTest; |
| 296 #ifdef MEMORY_CACHE_STATS | 303 #ifdef MEMORY_CACHE_STATS |
| 297 Timer<MemoryCache> m_statsTimer; | 304 Timer<MemoryCache> m_statsTimer; |
| 298 #endif | 305 #endif |
| 299 }; | 306 }; |
| 300 | 307 |
| 301 // Returns the global cache. | 308 // Returns the global cache. |
| 302 MemoryCache* memoryCache(); | 309 MemoryCache* memoryCache(); |
| 303 | 310 |
| 304 // Sets the global cache, used to swap in a test instance. Returns the old | 311 // Sets the global cache, used to swap in a test instance. Returns the old |
| 305 // MemoryCache object. | 312 // MemoryCache object. |
| 306 PassOwnPtrWillBeRawPtr<MemoryCache> replaceMemoryCacheForTesting(PassOwnPtrWillB eRawPtr<MemoryCache>); | 313 PassOwnPtrWillBeRawPtr<MemoryCache> replaceMemoryCacheForTesting(PassOwnPtrWillB eRawPtr<MemoryCache>); |
| 307 | 314 |
| 308 } | 315 } |
| 309 | 316 |
| 310 #endif | 317 #endif |
| OLD | NEW |