CachedResource* CachedResourceLoader::loadResource(CachedResource::Type type, ResourceRequest& request, const String& charset, ResourceLoadPriority priority) { ASSERT(!memoryCache()->resourceForURL(request.url())); LOG(ResourceLoading, "Loading CachedResource for '%s'.", request.url().string().latin1().data()); CachedResource* resource = createResource(type, request, charset); bool inCache = memoryCache()->add(resource); // Pretend the resource is in the cache, to prevent it from being deleted during the load() call. // FIXME: CachedResource should just use normal refcounting instead. if (!inCache) resource->setInCache(true); resource->setLoadPriority(priority); resource->load(this); if (!inCache) { resource->setOwningCachedResourceLoader(this); resource->setInCache(false); } // We don't support immediate loads, but we do support immediate failure. if (resource->errorOccurred()) { if (inCache) memoryCache()->remove(resource); else delete resource; return 0; } m_validatedURLs.add(request.url()); return resource; }
CachedResource* CachedResourceLoader::revalidateResource(CachedResource* resource, ResourceLoadPriority priority, const ResourceLoaderOptions& options) { ASSERT(resource); ASSERT(resource->inCache()); ASSERT(!memoryCache()->disabled()); ASSERT(resource->canUseCacheValidator()); ASSERT(!resource->resourceToRevalidate()); // Copy the URL out of the resource to be revalidated in case it gets deleted by the remove() call below. String url = resource->url(); bool urlProtocolIsData = resource->url().protocolIsData(); CachedResource* newResource = createResource(resource->type(), resource->resourceRequest(), resource->encoding()); LOG(ResourceLoading, "Resource %p created to revalidate %p", newResource, resource); newResource->setResourceToRevalidate(resource); memoryCache()->remove(resource); memoryCache()->add(newResource); newResource->setLoadPriority(priority); newResource->load(this, options); if (!urlProtocolIsData) m_validatedURLs.add(url); return newResource; }
CachedResource* CachedResourceLoader::revalidateResource(CachedResource* resource, ResourceLoadPriority priority) { ASSERT(resource); ASSERT(resource->inCache()); ASSERT(!memoryCache()->disabled()); ASSERT(resource->canUseCacheValidator()); ASSERT(!resource->resourceToRevalidate()); // Copy the URL out of the resource to be revalidated in case it gets deleted by the remove() call below. String url = resource->url(); CachedResource* newResource = createResource(resource->type(), KURL(ParsedURLString, url), resource->encoding()); LOG(ResourceLoading, "Resource %p created to revalidate %p", newResource, resource); newResource->setResourceToRevalidate(resource); memoryCache()->remove(resource); memoryCache()->add(newResource); newResource->setLoadPriority(priority); newResource->load(this); m_validatedURLs.add(url); return newResource; }