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

Unified Diff: Source/core/fetch/Resource.cpp

Issue 179943002: MemoryCache: make sure that Resources are evicted only when they can be deleted (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 6 years, 9 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 | « Source/core/fetch/Resource.h ('k') | Source/core/fetch/ResourceFetcher.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/fetch/Resource.cpp
diff --git a/Source/core/fetch/Resource.cpp b/Source/core/fetch/Resource.cpp
index 8de53059160fd0e7cf8cb2198f29297b80c8bb0f..a58d4e3819ecf82bf45a6d62c936a9f4f387ce1a 100644
--- a/Source/core/fetch/Resource.cpp
+++ b/Source/core/fetch/Resource.cpp
@@ -364,6 +364,11 @@ bool Resource::unlock()
return true;
}
+bool Resource::hasRightHandleCountApartFromCache(unsigned targetCount) const
+{
+ return m_handleCount == targetCount + memoryCache()->contains(this);
+}
+
void Resource::responseReceived(const ResourceResponse& response)
{
setResponse(response);
@@ -403,6 +408,17 @@ void Resource::setCachedMetadata(unsigned dataTypeID, const char* data, size_t s
blink::Platform::current()->cacheMetadata(m_response.url(), m_response.responseTime(), serializedData.data(), serializedData.size());
}
+bool Resource::canDelete() const
+{
+ return !hasClients() && !m_loader && !m_preloadCount && hasRightHandleCountApartFromCache(0)
+ && !m_protectorCount && !m_resourceToRevalidate && !m_proxyResource;
+}
+
+bool Resource::hasOneHandleApartFromCache() const
+{
+ return hasRightHandleCountApartFromCache(1);
+}
+
CachedMetadata* Resource::cachedMetadata(unsigned dataTypeID) const
{
if (!m_cachedMetadata || m_cachedMetadata->dataTypeID() != dataTypeID)
@@ -771,6 +787,8 @@ void Resource::unregisterHandle(ResourcePtrBase* h)
unlock();
} else if (m_handleCount == 1 && memoryCache()->contains(this)) {
unlock();
+ if (!hasClients())
+ memoryCache()->prune(this);
}
}
« no previous file with comments | « Source/core/fetch/Resource.h ('k') | Source/core/fetch/ResourceFetcher.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698