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

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

Issue 2230433002: Add MemoryCoordinatorClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tweak 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 , m_maxDeadCapacity(cDefaultCacheCapacity) 97 , m_maxDeadCapacity(cDefaultCacheCapacity)
98 , m_maxDeferredPruneDeadCapacity(cDeferredPruneDeadCapacityFactor * cDefault CacheCapacity) 98 , m_maxDeferredPruneDeadCapacity(cDeferredPruneDeadCapacityFactor * cDefault CacheCapacity)
99 , m_delayBeforeLiveDecodedPrune(cMinDelayBeforeLiveDecodedPrune) 99 , m_delayBeforeLiveDecodedPrune(cMinDelayBeforeLiveDecodedPrune)
100 , m_liveSize(0) 100 , m_liveSize(0)
101 , m_deadSize(0) 101 , m_deadSize(0)
102 #ifdef MEMORY_CACHE_STATS 102 #ifdef MEMORY_CACHE_STATS
103 , m_statsTimer(this, &MemoryCache::dumpStats) 103 , m_statsTimer(this, &MemoryCache::dumpStats)
104 #endif 104 #endif
105 { 105 {
106 MemoryCacheDumpProvider::instance()->setMemoryCache(this); 106 MemoryCacheDumpProvider::instance()->setMemoryCache(this);
107 MemoryCoordinator::instance().registerClient(this);
107 #ifdef MEMORY_CACHE_STATS 108 #ifdef MEMORY_CACHE_STATS
108 const double statsIntervalInSeconds = 15; 109 const double statsIntervalInSeconds = 15;
109 m_statsTimer.startRepeating(statsIntervalInSeconds, BLINK_FROM_HERE); 110 m_statsTimer.startRepeating(statsIntervalInSeconds, BLINK_FROM_HERE);
110 #endif 111 #endif
111 } 112 }
112 113
113 MemoryCache* MemoryCache::create() 114 MemoryCache* MemoryCache::create()
114 { 115 {
115 return new MemoryCache; 116 return new MemoryCache;
116 } 117 }
117 118
118 MemoryCache::~MemoryCache() 119 MemoryCache::~MemoryCache()
119 { 120 {
120 if (m_prunePending) 121 if (m_prunePending)
121 Platform::current()->currentThread()->removeTaskObserver(this); 122 Platform::current()->currentThread()->removeTaskObserver(this);
123 MemoryCoordinator::instance().unregisterClient(this);
haraken 2016/08/12 02:55:00 We don't need to call this since the client is aut
bashi 2016/08/16 00:09:06 Removed. Does it mean we should have null checks
haraken 2016/08/16 02:37:04 No. Cleared entries are automatically removed from
bashi 2016/08/16 02:39:41 I see. Thanks for clarification.
122 } 124 }
123 125
124 DEFINE_TRACE(MemoryCache) 126 DEFINE_TRACE(MemoryCache)
125 { 127 {
126 visitor->trace(m_allResources); 128 visitor->trace(m_allResources);
127 visitor->trace(m_liveDecodedResources); 129 visitor->trace(m_liveDecodedResources);
128 visitor->trace(m_resourceMaps); 130 visitor->trace(m_resourceMaps);
129 MemoryCacheDumpClient::trace(visitor); 131 MemoryCacheDumpClient::trace(visitor);
132 MemoryCoordinatorClient::trace(visitor);
130 } 133 }
131 134
132 KURL MemoryCache::removeFragmentIdentifierIfNeeded(const KURL& originalURL) 135 KURL MemoryCache::removeFragmentIdentifierIfNeeded(const KURL& originalURL)
133 { 136 {
134 if (!originalURL.hasFragmentIdentifier()) 137 if (!originalURL.hasFragmentIdentifier())
135 return originalURL; 138 return originalURL;
136 // Strip away fragment identifier from HTTP URLs. 139 // Strip away fragment identifier from HTTP URLs.
137 // Data URLs must be unmodified. For file and custom URLs clients may expect resources 140 // Data URLs must be unmodified. For file and custom URLs clients may expect resources
138 // to be unique even when they differ by the fragment identifier only. 141 // to be unique even when they differ by the fragment identifier only.
139 if (!originalURL.protocolIsInHTTPFamily()) 142 if (!originalURL.protocolIsInHTTPFamily())
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 { 731 {
729 for (const auto& resourceMapIter : m_resourceMaps) { 732 for (const auto& resourceMapIter : m_resourceMaps) {
730 for (const auto& resourceIter : *resourceMapIter.value) { 733 for (const auto& resourceIter : *resourceMapIter.value) {
731 Resource* resource = resourceIter.value->resource(); 734 Resource* resource = resourceIter.value->resource();
732 resource->onMemoryDump(levelOfDetail, memoryDump); 735 resource->onMemoryDump(levelOfDetail, memoryDump);
733 } 736 }
734 } 737 }
735 return true; 738 return true;
736 } 739 }
737 740
741 void MemoryCache::onMemoryPressure(WebMemoryPressureLevel level)
742 {
743 if (ProcessHeap::isLowEndDevice())
esprehn 2016/08/15 15:41:07 Hmm, should we do this in the constructor then? Ca
bashi 2016/08/16 00:09:06 Done. tasak@: you might want to move back this co
744 pruneAll();
745 }
746
738 bool MemoryCache::isInSameLRUListForTest(const Resource* x, const Resource* y) 747 bool MemoryCache::isInSameLRUListForTest(const Resource* x, const Resource* y)
739 { 748 {
740 MemoryCacheEntry* ex = getEntryForResource(x); 749 MemoryCacheEntry* ex = getEntryForResource(x);
741 MemoryCacheEntry* ey = getEntryForResource(y); 750 MemoryCacheEntry* ey = getEntryForResource(y);
742 ASSERT(ex); 751 ASSERT(ex);
743 ASSERT(ey); 752 ASSERT(ey);
744 return lruListFor(ex->m_accessCount, x->size()) == lruListFor(ey->m_accessCo unt, y->size()); 753 return lruListFor(ex->m_accessCount, x->size()) == lruListFor(ey->m_accessCo unt, y->size());
745 } 754 }
746 755
747 #ifdef MEMORY_CACHE_STATS 756 #ifdef MEMORY_CACHE_STATS
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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()); 791 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 792
784 current = current->m_previousInAllResourcesList; 793 current = current->m_previousInAllResourcesList;
785 } 794 }
786 } 795 }
787 } 796 }
788 797
789 #endif // MEMORY_CACHE_STATS 798 #endif // MEMORY_CACHE_STATS
790 799
791 } // namespace blink 800 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698