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

Unified Diff: Source/WebCore/loader/cache/CachedResourceLoader.cpp

Issue 7548016: Merge 92143 - .: REGRESSION (r39725?): Resources removed from document can not be freed until the... (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/835/
Patch Set: Created 9 years, 5 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/WebCore/loader/cache/CachedResourceLoader.h ('k') | Source/WebCore/testing/Internals.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/WebCore/loader/cache/CachedResourceLoader.cpp
===================================================================
--- Source/WebCore/loader/cache/CachedResourceLoader.cpp (revision 92202)
+++ Source/WebCore/loader/cache/CachedResourceLoader.cpp (working copy)
@@ -86,6 +86,7 @@
CachedResourceLoader::CachedResourceLoader(Document* document)
: m_document(document)
, m_requestCount(0)
+ , m_garbageCollectDocumentResourcesTimer(this, &CachedResourceLoader::garbageCollectDocumentResourcesTimerFired)
, m_autoLoadImages(true)
, m_loadFinishing(false)
, m_allowStaleResources(false)
@@ -572,8 +573,35 @@
if (frame())
frame()->loader()->loadDone();
performPostLoadActions();
+
+ if (!m_garbageCollectDocumentResourcesTimer.isActive())
+ m_garbageCollectDocumentResourcesTimer.startOneShot(0);
}
+// Garbage collecting m_documentResources is a workaround for the
+// CachedResourceHandles on the RHS being strong references. Ideally this
+// would be a weak map, however CachedResourceHandles perform additional
+// bookkeeping on CachedResources, so instead pseudo-GC them -- when the
+// reference count reaches 1, m_documentResources is the only reference, so
+// remove it from the map.
+void CachedResourceLoader::garbageCollectDocumentResourcesTimerFired(Timer<CachedResourceLoader>* timer)
+{
+ ASSERT_UNUSED(timer, timer == &m_garbageCollectDocumentResourcesTimer);
+
+ typedef Vector<String, 10> StringVector;
+ StringVector resourcesToDelete;
+
+ for (DocumentResourceMap::iterator it = m_documentResources.begin(); it != m_documentResources.end(); ++it) {
+ if (it->second->hasOneHandle()) {
+ resourcesToDelete.append(it->first);
+ it->second->setOwningCachedResourceLoader(0);
+ }
+ }
+
+ for (StringVector::const_iterator it = resourcesToDelete.begin(); it != resourcesToDelete.end(); ++it)
+ m_documentResources.remove(*it);
+}
+
void CachedResourceLoader::performPostLoadActions()
{
checkForPendingPreloads();
« no previous file with comments | « Source/WebCore/loader/cache/CachedResourceLoader.h ('k') | Source/WebCore/testing/Internals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698