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

Unified Diff: third_party/WebKit/Source/core/inspector/InspectorResourceAgent.cpp

Issue 1667843003: Make Resource RefCountedWillBeGarbageCollectedFinalized, attempt #2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + address review comments Created 4 years, 10 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: third_party/WebKit/Source/core/inspector/InspectorResourceAgent.cpp
diff --git a/third_party/WebKit/Source/core/inspector/InspectorResourceAgent.cpp b/third_party/WebKit/Source/core/inspector/InspectorResourceAgent.cpp
index e4a307f1c16c91f125e7cd1a31d48ba565269ec8..d42319ecb0ab2913b7211680f3d6b6f101f950a9 100644
--- a/third_party/WebKit/Source/core/inspector/InspectorResourceAgent.cpp
+++ b/third_party/WebKit/Source/core/inspector/InspectorResourceAgent.cpp
@@ -558,7 +558,12 @@ void InspectorResourceAgent::didReceiveResourceResponse(LocalFrame* frame, unsig
if (type == InspectorPageAgent::DocumentResource && loader && loader->substituteData().isValid())
return;
- if (cachedResource)
+ // It's only safe to reference a Resource in m_resourcesData if it's in the
+ // cache at this point. Resources are added to NetworkResourcesData here
+ // and removed in removedResourceFromMemoryCache(), so if the Resource isn't
+ // in the cache here, NetworkResourceData's strong reference to the
+ // Resource will keep it alive indefinitely.
+ if (cachedResource && memoryCache()->contains(cachedResource))
m_resourcesData->addResource(requestId, cachedResource);
String frameId = IdentifiersFactory::frameId(frame);
String loaderId = loader ? IdentifiersFactory::loaderId(loader) : "";
@@ -742,13 +747,13 @@ void InspectorResourceAgent::didFinishEventSourceRequest(ThreadableLoaderClient*
m_pendingRequest = nullptr;
}
-void InspectorResourceAgent::willDestroyResource(Resource* cachedResource)
+void InspectorResourceAgent::removedResourceFromMemoryCache(Resource* cachedResource)
{
String content;
bool base64Encoded;
bool hasContent = InspectorPageAgent::cachedResourceContent(cachedResource, &content, &base64Encoded);
Vector<String> requestIds = m_resourcesData->removeResource(cachedResource);
- if (hasContent) {
+ if (hasContent && !isErrorStatusCode(cachedResource->response().httpStatusCode())) {
for (auto& request : requestIds)
m_resourcesData->setResourceContent(request, content, base64Encoded);
}

Powered by Google App Engine
This is Rietveld 408576698