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

Unified Diff: third_party/WebKit/Source/core/fetch/MemoryCache.cpp

Issue 2296913003: [WeakMemoryCache] Make references from MemoryCache to Resource Weak (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@WeakMemoryCache_RemoveStats
Patch Set: Assume resource is always non-null 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/fetch/MemoryCache.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/fetch/MemoryCache.cpp
diff --git a/third_party/WebKit/Source/core/fetch/MemoryCache.cpp b/third_party/WebKit/Source/core/fetch/MemoryCache.cpp
index 7c7e029eb8be135eb56caa1b837e63793c8d401a..a0de01441465ee86da4cb6e7bafad6c0ef50e6d1 100644
--- a/third_party/WebKit/Source/core/fetch/MemoryCache.cpp
+++ b/third_party/WebKit/Source/core/fetch/MemoryCache.cpp
@@ -62,13 +62,21 @@ MemoryCache* replaceMemoryCacheForTesting(MemoryCache* cache)
DEFINE_TRACE(MemoryCacheEntry)
{
- visitor->trace(m_resource);
+ visitor->template registerWeakMembers<MemoryCacheEntry, &MemoryCacheEntry::clearResourceWeak>(this);
visitor->trace(m_previousInLiveResourcesList);
visitor->trace(m_nextInLiveResourcesList);
visitor->trace(m_previousInAllResourcesList);
visitor->trace(m_nextInAllResourcesList);
}
+void MemoryCacheEntry::clearResourceWeak(Visitor* visitor)
+{
+ if (!m_resource || ThreadHeap::isHeapObjectAlive(m_resource))
+ return;
+ memoryCache()->remove(m_resource.get());
+ m_resource.clear();
+}
+
void MemoryCacheEntry::dispose()
{
m_resource.clear();
@@ -159,7 +167,7 @@ void MemoryCache::add(Resource* resource)
ASSERT(resource->url().isValid());
ResourceMap* resources = ensureResourceMap(resource->cacheIdentifier());
KURL url = removeFragmentIdentifierIfNeeded(resource->url());
- RELEASE_ASSERT(!resources->contains(url));
+ CHECK(!contains(resource));
resources->set(url, MemoryCacheEntry::create(resource));
update(resource, 0, resource->size(), true);
@@ -206,8 +214,11 @@ HeapVector<Member<Resource>> MemoryCache::resourcesForURL(const KURL& resourceUR
KURL url = removeFragmentIdentifierIfNeeded(resourceURL);
HeapVector<Member<Resource>> results;
for (const auto& resourceMapIter : m_resourceMaps) {
- if (MemoryCacheEntry* entry = resourceMapIter.value->get(url))
- results.append(entry->resource());
+ if (MemoryCacheEntry* entry = resourceMapIter.value->get(url)) {
+ Resource* resource = entry->resource();
+ DCHECK(resource);
+ results.append(resource);
+ }
}
return results;
}
@@ -358,6 +369,7 @@ void MemoryCache::evict(MemoryCacheEntry* entry)
ASSERT(WTF::isMainThread());
Resource* resource = entry->resource();
+ DCHECK(resource);
RESOURCE_LOADING_DVLOG(1) << "Evicting resource " << resource << " for " << resource->url().getString() << " from cache";
TRACE_EVENT1("blink", "MemoryCache::evict", "resource", resource->url().getString().utf8());
// The resource may have already been removed by someone other than our caller,
@@ -379,7 +391,7 @@ void MemoryCache::evict(MemoryCacheEntry* entry)
MemoryCacheEntry* MemoryCache::getEntryForResource(const Resource* resource) const
{
- if (resource->url().isNull() || resource->url().isEmpty())
+ if (!resource || resource->url().isNull() || resource->url().isEmpty())
return nullptr;
ResourceMap* resources = m_resourceMaps.get(resource->cacheIdentifier());
if (!resources)
@@ -589,6 +601,7 @@ MemoryCache::Statistics MemoryCache::getStatistics()
for (const auto& resourceMapIter : m_resourceMaps) {
for (const auto& resourceIter : *resourceMapIter.value) {
Resource* resource = resourceIter.value->resource();
+ DCHECK(resource);
switch (resource->getType()) {
case Resource::Image:
stats.images.addResource(resource);
« no previous file with comments | « third_party/WebKit/Source/core/fetch/MemoryCache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698