void CachedResource::setBodyDataFrom(const CachedResource& resource) { m_data = resource.m_data; m_response = resource.m_response; setDecodedSize(resource.decodedSize()); setEncodedSize(resource.encodedSize()); }
void MemoryCache::TypeStatistic::addResource(CachedResource& resource) { count++; size += resource.size(); liveSize += resource.hasClients() ? resource.size() : 0; decodedSize += resource.decodedSize(); }
void MemoryCache::dumpLRULists(bool includeLive) const { printf("LRU-SP lists in eviction order (Kilobytes decoded, Kilobytes encoded, Access count, Referenced, isPurgeable, wasPurged):\n"); int size = m_allResources.size(); for (int i = size - 1; i >= 0; i--) { printf("\n\nList %d: ", i); CachedResource* current = m_allResources[i].m_tail; while (current) { CachedResource* prev = current->m_prevInAllResourcesList; if (includeLive || !current->hasClients()) printf("(%.1fK, %.1fK, %uA, %dR, %d, %d); ", current->decodedSize() / 1024.0f, (current->encodedSize() + current->overheadSize()) / 1024.0f, current->accessCount(), current->hasClients(), current->isPurgeable(), current->wasPurged()); current = prev; } } }
void MemoryCache::revalidationSucceeded(CachedResource* revalidatingResource, const ResourceResponse& response) { CachedResource* resource = revalidatingResource->resourceToRevalidate(); ASSERT(resource); ASSERT(!resource->inCache()); ASSERT(resource->isLoaded()); ASSERT(revalidatingResource->inCache()); // Calling evict() can potentially delete revalidatingResource, which we use // below. This mustn't be the case since revalidation means it is loaded // and so canDelete() is false. ASSERT(!revalidatingResource->canDelete()); evict(revalidatingResource); CachedResourceMap& resources = getSessionMap(resource->sessionID()); #if ENABLE(CACHE_PARTITIONING) ASSERT(!resources.get(resource->url()) || !resources.get(resource->url())->get(resource->cachePartition())); CachedResourceItem* originMap = resources.get(resource->url()); if (!originMap) { originMap = new CachedResourceItem; resources.set(resource->url(), adoptPtr(originMap)); } originMap->set(resource->cachePartition(), resource); #else ASSERT(!resources.get(resource->url())); resources.set(resource->url(), resource); #endif resource->setInCache(true); resource->updateResponseAfterRevalidation(response); insertInLRUList(resource); int delta = resource->size(); if (resource->decodedSize() && resource->hasClients()) insertInLiveDecodedResourcesList(resource); if (delta) adjustSize(resource->hasClients(), delta); revalidatingResource->switchClientsToRevalidatedResource(); ASSERT(!revalidatingResource->m_deleted); // this deletes the revalidating resource revalidatingResource->clearResourceToRevalidate(); }
void MemoryCache::pruneLiveResourcesToSize(unsigned targetSize) { if (m_inPruneResources) return; TemporaryChange<bool> reentrancyProtector(m_inPruneResources, true); double currentTime = FrameView::currentPaintTimeStamp(); if (!currentTime) // In case prune is called directly, outside of a Frame paint. currentTime = WTF::currentTime(); // Destroy any decoded data in live objects that we can. // Start from the tail, since this is the least recently accessed of the objects. // The list might not be sorted by the m_lastDecodedAccessTime. The impact // of this weaker invariant is minor as the below if statement to check the // elapsedTime will evaluate to false as the currentTime will be a lot // greater than the current->m_lastDecodedAccessTime. // For more details see: https://bugs.webkit.org/show_bug.cgi?id=30209 CachedResource* current = m_liveDecodedResources.m_tail; while (current) { CachedResource* prev = current->m_prevInLiveResourcesList; ASSERT(current->hasClients()); if (current->isLoaded() && current->decodedSize()) { // Check to see if the remaining resources are too new to prune. double elapsedTime = currentTime - current->m_lastDecodedAccessTime; if (elapsedTime < cMinDelayBeforeLiveDecodedPrune) return; // Destroy our decoded data. This will remove us from // m_liveDecodedResources, and possibly move us to a different LRU // list in m_allResources. current->destroyDecodedData(); if (targetSize && m_liveSize <= targetSize) return; } current = prev; } }