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

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: Pruning when handle count reaches 1 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
Index: Source/core/fetch/Resource.cpp
diff --git a/Source/core/fetch/Resource.cpp b/Source/core/fetch/Resource.cpp
index fcbb7ce19a58503553f48890fe1d515554b2bdd0..e60ee341f51838a6314a8c22b4348ae09a831b84 100644
--- a/Source/core/fetch/Resource.cpp
+++ b/Source/core/fetch/Resource.cpp
@@ -364,6 +364,12 @@ bool Resource::unlock()
return true;
}
+bool Resource::hasRightHandleCountApartFromCache(unsigned targetCount)
+{
+ bool inCache = memoryCache()->contains(this);
+ return (inCache && m_handleCount == targetCount + 1) || (!inCache && m_handleCount == targetCount);
Philippe 2014/03/26 16:04:07 Nit: not sure this is more readable but in case yo
Philippe 2014/03/26 17:08:33 You might not even need the '!!' though. We usuall
clamy 2014/03/27 10:47:16 Done.
+}
+
void Resource::responseReceived(const ResourceResponse& response)
{
setResponse(response);
@@ -403,6 +409,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()
+{
+ return !hasClients() && !m_loader && !m_preloadCount && hasRightHandleCountApartFromCache(0)
+ && !m_protectorCount && !m_resourceToRevalidate && !m_proxyResource;
+}
+
+bool Resource::hasOneHandleApartFromCache()
+{
+ return hasRightHandleCountApartFromCache(1);
+}
+
CachedMetadata* Resource::cachedMetadata(unsigned dataTypeID) const
{
if (!m_cachedMetadata || m_cachedMetadata->dataTypeID() != dataTypeID)
@@ -771,6 +788,8 @@ void Resource::unregisterHandle(ResourcePtrBase* h)
unlock();
} else if (m_handleCount == 1 && memoryCache()->contains(this)) {
unlock();
+ if (!hasClients())
Philippe 2014/03/26 16:04:07 Nit: Do we still need this change?
clamy 2014/03/27 10:47:16 Yes this is what is making it work with the rebase
+ memoryCache()->prune(this);
}
}

Powered by Google App Engine
This is Rietveld 408576698