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

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

Issue 2202473002: DO NOT COMMIT: Experimental removal of encoded image data Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: (rebase) Created 4 years, 3 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) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 5 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 } 281 }
282 current = previous; 282 current = previous;
283 } 283 }
284 } 284 }
285 285
286 void MemoryCache::pruneDeadResources(PruneStrategy strategy) 286 void MemoryCache::pruneDeadResources(PruneStrategy strategy)
287 { 287 {
288 size_t capacity = deadCapacity(); 288 size_t capacity = deadCapacity();
289 if (strategy == MaximalPrune) 289 if (strategy == MaximalPrune)
290 capacity = 0; 290 capacity = 0;
291 if (!m_deadSize || (capacity && m_deadSize <= capacity)) 291
292 return; 292 // Now pruneDeadResources needs to check all resources when the strategy is Maximal
293 if (strategy != MaximalPrune) {
294 if (!m_deadSize || (capacity && m_deadSize <= capacity))
295 return;
296 }
293 297
294 size_t targetSize = static_cast<size_t>(capacity * cTargetPrunePercentage); // Cut by a percentage to avoid immediately pruning again. 298 size_t targetSize = static_cast<size_t>(capacity * cTargetPrunePercentage); // Cut by a percentage to avoid immediately pruning again.
295 299
296 int size = m_allResources.size(); 300 int size = m_allResources.size();
297 if (targetSize && m_deadSize <= targetSize) 301 if (targetSize && m_deadSize <= targetSize)
298 return; 302 return;
299 303
300 bool canShrinkLRULists = true; 304 bool canShrinkLRULists = true;
301 for (int i = size - 1; i >= 0; i--) { 305 for (int i = size - 1; i >= 0; i--) {
302 // Remove from the tail, since this is the least frequently accessed of the objects. 306 // Remove from the tail, since this is the least frequently accessed of the objects.
303 MemoryCacheEntry* current = m_allResources[i].m_tail; 307 MemoryCacheEntry* current = m_allResources[i].m_tail;
304 308
305 // First flush all the decoded data in this queue. 309 // First flush all the decoded data in this queue.
306 while (current) { 310 while (current) {
307 Resource* resource = current->resource(); 311 Resource* resource = current->resource();
308 MemoryCacheEntry* previous = current->m_previousInAllResourcesList; 312 MemoryCacheEntry* previous = current->m_previousInAllResourcesList;
309 313
310 // Decoded data may reference other resources. Skip |current| if 314 // Decoded data may reference other resources. Skip |current| if
311 // |current| somehow got kicked out of cache during 315 // |current| somehow got kicked out of cache during
312 // destroyDecodedData(). 316 // destroyDecodedData().
313 if (!resource || !contains(resource)) { 317 if (!resource || !contains(resource)) {
314 current = previous; 318 current = previous;
315 continue; 319 continue;
316 } 320 }
317 321
322 if (strategy == MaximalPrune) {
323 if (!resource->isPreloaded() && resource->isLoaded() && resource ->isReloadable()) {
324 resource->myPrune();
325 }
326 }
327
318 if (!resource->isAlive() && !resource->isPreloaded() && resource->is Loaded()) { 328 if (!resource->isAlive() && !resource->isPreloaded() && resource->is Loaded()) {
319 // Destroy our decoded data. This will remove us from 329 // Destroy our decoded data. This will remove us from
320 // m_liveDecodedResources, and possibly move us to a different 330 // m_liveDecodedResources, and possibly move us to a different
321 // LRU list in m_allResources. 331 // LRU list in m_allResources.
322 resource->prune(); 332 resource->prune();
323 333
324 if (targetSize && m_deadSize <= targetSize) 334 if (targetSize && m_deadSize <= targetSize)
325 return; 335 return;
326 } 336 }
327 current = previous; 337 current = previous;
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 bool MemoryCache::isInSameLRUListForTest(const Resource* x, const Resource* y) 756 bool MemoryCache::isInSameLRUListForTest(const Resource* x, const Resource* y)
747 { 757 {
748 MemoryCacheEntry* ex = getEntryForResource(x); 758 MemoryCacheEntry* ex = getEntryForResource(x);
749 MemoryCacheEntry* ey = getEntryForResource(y); 759 MemoryCacheEntry* ey = getEntryForResource(y);
750 ASSERT(ex); 760 ASSERT(ex);
751 ASSERT(ey); 761 ASSERT(ey);
752 return lruListFor(ex->m_accessCount, x->size()) == lruListFor(ey->m_accessCo unt, y->size()); 762 return lruListFor(ex->m_accessCount, x->size()) == lruListFor(ey->m_accessCo unt, y->size());
753 } 763 }
754 764
755 } // namespace blink 765 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/ImageResourceObserver.h ('k') | third_party/WebKit/Source/core/fetch/Resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698