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) 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 Loading... | |
| 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 Loading... | |
| 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; | |
|
haraken
2016/08/17 08:13:31
Can you remove the purgeableSize member entirely?
hiroshige
2016/08/17 09:02:37
Yes.
Created a separate CL: https://codereview.chr
| |
| 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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, %d); ", currentResource->decode dSize() / 1024.0f, (currentResource->encodedSize() + currentResource->overheadSi ze()) / 1024.0f, current->m_accessCount, currentResource->hasClientsOrObservers( ), currentResource->isPurgeable()); |
| 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 |
| OLD | NEW |