예제 #1
0
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;
}