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

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

Issue 2253853002: Remove SharedBuffer::unlock() and keep Resource's SharedBuffer always locked (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use hasClientsOrObservers() for live_size Created 4 years, 4 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 if (!resourceURL.isValid() || resourceURL.isNull()) 194 if (!resourceURL.isValid() || resourceURL.isNull())
195 return nullptr; 195 return nullptr;
196 ASSERT(!cacheIdentifier.isNull()); 196 ASSERT(!cacheIdentifier.isNull());
197 ResourceMap* resources = m_resourceMaps.get(cacheIdentifier); 197 ResourceMap* resources = m_resourceMaps.get(cacheIdentifier);
198 if (!resources) 198 if (!resources)
199 return nullptr; 199 return nullptr;
200 KURL url = removeFragmentIdentifierIfNeeded(resourceURL); 200 KURL url = removeFragmentIdentifierIfNeeded(resourceURL);
201 MemoryCacheEntry* entry = resources->get(url); 201 MemoryCacheEntry* entry = resources->get(url);
202 if (!entry) 202 if (!entry)
203 return nullptr; 203 return nullptr;
204 Resource* resource = entry->resource(); 204 return entry->resource();
205 if (resource && !resource->lock())
206 return nullptr;
207 return resource;
208 } 205 }
209 206
210 HeapVector<Member<Resource>> MemoryCache::resourcesForURL(const KURL& resourceUR L) 207 HeapVector<Member<Resource>> MemoryCache::resourcesForURL(const KURL& resourceUR L)
211 { 208 {
212 ASSERT(WTF::isMainThread()); 209 ASSERT(WTF::isMainThread());
213 KURL url = removeFragmentIdentifierIfNeeded(resourceURL); 210 KURL url = removeFragmentIdentifierIfNeeded(resourceURL);
214 HeapVector<Member<Resource>> results; 211 HeapVector<Member<Resource>> results;
215 for (const auto& resourceMapIter : m_resourceMaps) { 212 for (const auto& resourceMapIter : m_resourceMaps) {
216 if (MemoryCacheEntry* entry = resourceMapIter.value->get(url)) 213 if (MemoryCacheEntry* entry = resourceMapIter.value->get(url))
217 results.append(entry->resource()); 214 results.append(entry->resource());
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 572
576 void MemoryCache::removeURLFromCache(const KURL& url) 573 void MemoryCache::removeURLFromCache(const KURL& url)
577 { 574 {
578 HeapVector<Member<Resource>> resources = resourcesForURL(url); 575 HeapVector<Member<Resource>> resources = resourcesForURL(url);
579 for (Resource* resource : resources) 576 for (Resource* resource : resources)
580 memoryCache()->remove(resource); 577 memoryCache()->remove(resource);
581 } 578 }
582 579
583 void MemoryCache::TypeStatistic::addResource(Resource* o) 580 void MemoryCache::TypeStatistic::addResource(Resource* o)
584 { 581 {
585 bool purgeable = o->isPurgeable();
586 size_t pageSize = (o->encodedSize() + o->overheadSize() + 4095) & ~4095;
587 count++; 582 count++;
588 size += o->size(); 583 size += o->size();
589 liveSize += o->hasClientsOrObservers() ? o->size() : 0; 584 liveSize += o->hasClientsOrObservers() ? o->size() : 0;
590 decodedSize += o->decodedSize(); 585 decodedSize += o->decodedSize();
591 encodedSize += o->encodedSize(); 586 encodedSize += o->encodedSize();
592 encodedSizeDuplicatedInDataURLs += o->url().protocolIsData() ? o->encodedSiz e() : 0; 587 encodedSizeDuplicatedInDataURLs += o->url().protocolIsData() ? o->encodedSiz e() : 0;
593 purgeableSize += purgeable ? pageSize : 0;
594 } 588 }
595 589
596 MemoryCache::Statistics MemoryCache::getStatistics() 590 MemoryCache::Statistics MemoryCache::getStatistics()
597 { 591 {
598 Statistics stats; 592 Statistics stats;
599 for (const auto& resourceMapIter : m_resourceMaps) { 593 for (const auto& resourceMapIter : m_resourceMaps) {
600 for (const auto& resourceIter : *resourceMapIter.value) { 594 for (const auto& resourceIter : *resourceMapIter.value) {
601 Resource* resource = resourceIter.value->resource(); 595 Resource* resource = resourceIter.value->resource();
602 switch (resource->getType()) { 596 switch (resource->getType()) {
603 case Resource::Image: 597 case Resource::Image:
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 { 766 {
773 printf("LRU-SP lists in eviction order (Kilobytes decoded, Kilobytes encoded , Access count, Referenced, isPurgeable):\n"); 767 printf("LRU-SP lists in eviction order (Kilobytes decoded, Kilobytes encoded , Access count, Referenced, isPurgeable):\n");
774 768
775 int size = m_allResources.size(); 769 int size = m_allResources.size();
776 for (int i = size - 1; i >= 0; i--) { 770 for (int i = size - 1; i >= 0; i--) {
777 printf("\n\nList %d: ", i); 771 printf("\n\nList %d: ", i);
778 MemoryCacheEntry* current = m_allResources[i].m_tail; 772 MemoryCacheEntry* current = m_allResources[i].m_tail;
779 while (current) { 773 while (current) {
780 Resource* currentResource = current->resource(); 774 Resource* currentResource = current->resource();
781 if (includeLive || !currentResource->hasClientsOrObservers()) 775 if (includeLive || !currentResource->hasClientsOrObservers())
782 printf("(%.1fK, %.1fK, %uA, %dR, %d); ", currentResource->decode dSize() / 1024.0f, (currentResource->encodedSize() + currentResource->overheadSi ze()) / 1024.0f, current->m_accessCount, currentResource->hasClientsOrObservers( ), currentResource->isPurgeable()); 776 printf("(%.1fK, %.1fK, %uA, %dR); ", currentResource->decodedSiz e() / 1024.0f, (currentResource->encodedSize() + currentResource->overheadSize() ) / 1024.0f, current->m_accessCount, currentResource->hasClientsOrObservers());
783 777
784 current = current->m_previousInAllResourcesList; 778 current = current->m_previousInAllResourcesList;
785 } 779 }
786 } 780 }
787 } 781 }
788 782
789 #endif // MEMORY_CACHE_STATS 783 #endif // MEMORY_CACHE_STATS
790 784
791 } // namespace blink 785 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/ImageResource.cpp ('k') | third_party/WebKit/Source/core/fetch/Resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698