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

Unified Diff: Source/core/fetch/ResourceFetcher.cpp

Issue 23702040: Send synchronous loads through the cache. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address comments Created 7 years, 3 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/core/fetch/ResourceFetcher.h ('k') | Source/core/fetch/ResourceLoader.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/fetch/ResourceFetcher.cpp
diff --git a/Source/core/fetch/ResourceFetcher.cpp b/Source/core/fetch/ResourceFetcher.cpp
index 063a3eb4c430313eef9947e2be1153d3ed6b46a8..4e8ca8b1a302563db92988e257466abdcf12180e 100644
--- a/Source/core/fetch/ResourceFetcher.cpp
+++ b/Source/core/fetch/ResourceFetcher.cpp
@@ -116,9 +116,10 @@ static ResourceLoadPriority loadPriority(Resource::Type type, const FetchRequest
return ResourceLoadPriorityVeryHigh;
case Resource::CSSStyleSheet:
return ResourceLoadPriorityHigh;
+ case Resource::Raw:
+ return request.options().synchronousPolicy == RequestSynchronously ? ResourceLoadPriorityVeryHigh : ResourceLoadPriorityMedium;
case Resource::Script:
case Resource::Font:
- case Resource::Raw:
case Resource::ImportResource:
return ResourceLoadPriorityMedium;
case Resource::Image:
@@ -211,20 +212,14 @@ FetchContext& ResourceFetcher::context() const
return FetchContext::nullInstance();
}
-unsigned long ResourceFetcher::fetchSynchronously(const ResourceRequest& passedRequest, StoredCredentials storedCredentials, ResourceError& error, ResourceResponse& response, Vector<char>& data)
+ResourcePtr<Resource> ResourceFetcher::fetchSynchronously(FetchRequest& request)
{
ASSERT(document());
- ResourceRequest request(passedRequest);
- request.setTimeoutInterval(10);
- addAdditionalRequestHeaders(request, Resource::Raw);
-
- unsigned long identifier = createUniqueIdentifier();
- context().dispatchWillSendRequest(m_documentLoader, identifier, request, ResourceResponse());
- documentLoader()->applicationCacheHost()->willStartLoadingSynchronously(request);
- ResourceLoader::loadResourceSynchronously(request, storedCredentials, error, response, data);
- int encodedDataLength = response.resourceLoadInfo() ? static_cast<int>(response.resourceLoadInfo()->encodedDataLength) : -1;
- context().sendRemainingDelegateMessages(m_documentLoader, identifier, response, data.data(), data.size(), encodedDataLength, error);
- return identifier;
+ request.mutableResourceRequest().setTimeoutInterval(10);
+ ResourceLoaderOptions options(request.options());
+ options.synchronousPolicy = RequestSynchronously;
+ request.setOptions(options);
+ return requestResource(Resource::Raw, request);
}
ResourcePtr<ImageResource> ResourceFetcher::fetchImage(FetchRequest& request)
@@ -515,6 +510,8 @@ bool ResourceFetcher::shouldLoadNewResource() const
ResourcePtr<Resource> ResourceFetcher::requestResource(Resource::Type type, FetchRequest& request)
{
+ ASSERT(request.options().synchronousPolicy == RequestAsynchronously || type == Resource::Raw);
+
KURL url = request.resourceRequest().url();
LOG(ResourceLoading, "ResourceFetcher::requestResource '%s', charset '%s', priority=%d, forPreload=%u", url.elidedString().latin1().data(), request.charset().latin1().data(), request.priority(), request.forPreload());
@@ -575,11 +572,16 @@ ResourcePtr<Resource> ResourceFetcher::requestResource(Resource::Type type, Fetc
if (!m_documentLoader || !m_documentLoader->scheduleArchiveLoad(resource.get(), request.resourceRequest()))
resource->load(this, request.options());
- // We don't support immediate loads, but we do support immediate failure.
+ // For asynchronous loads that immediately fail, it's sufficient to return a
+ // null Resource, as it indicates that something prevented the load from starting.
+ // If there's a network error, that failure will happen asynchronously. However, if
+ // a sync load receives a network error, it will have already happened by this point.
+ // In that case, the requester should have access to the relevant ResourceError, so
+ // we need to return a non-null Resource.
if (resource->errorOccurred()) {
if (resource->inCache())
memoryCache()->remove(resource.get());
- return 0;
+ return request.options().synchronousPolicy == RequestSynchronously ? resource : 0;
}
}
« no previous file with comments | « Source/core/fetch/ResourceFetcher.h ('k') | Source/core/fetch/ResourceLoader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698