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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/fetch/ResourceFetcher.h ('k') | Source/core/fetch/ResourceLoader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ 6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 static ResourceLoadPriority loadPriority(Resource::Type type, const FetchRequest & request) 109 static ResourceLoadPriority loadPriority(Resource::Type type, const FetchRequest & request)
110 { 110 {
111 if (request.priority() != ResourceLoadPriorityUnresolved) 111 if (request.priority() != ResourceLoadPriorityUnresolved)
112 return request.priority(); 112 return request.priority();
113 113
114 switch (type) { 114 switch (type) {
115 case Resource::MainResource: 115 case Resource::MainResource:
116 return ResourceLoadPriorityVeryHigh; 116 return ResourceLoadPriorityVeryHigh;
117 case Resource::CSSStyleSheet: 117 case Resource::CSSStyleSheet:
118 return ResourceLoadPriorityHigh; 118 return ResourceLoadPriorityHigh;
119 case Resource::Raw:
120 return request.options().synchronousPolicy == RequestSynchronously ? Res ourceLoadPriorityVeryHigh : ResourceLoadPriorityMedium;
119 case Resource::Script: 121 case Resource::Script:
120 case Resource::Font: 122 case Resource::Font:
121 case Resource::Raw:
122 case Resource::ImportResource: 123 case Resource::ImportResource:
123 return ResourceLoadPriorityMedium; 124 return ResourceLoadPriorityMedium;
124 case Resource::Image: 125 case Resource::Image:
125 return request.forPreload() ? ResourceLoadPriorityVeryLow : ResourceLoad PriorityLow; 126 return request.forPreload() ? ResourceLoadPriorityVeryLow : ResourceLoad PriorityLow;
126 case Resource::XSLStyleSheet: 127 case Resource::XSLStyleSheet:
127 return ResourceLoadPriorityHigh; 128 return ResourceLoadPriorityHigh;
128 case Resource::SVGDocument: 129 case Resource::SVGDocument:
129 return ResourceLoadPriorityLow; 130 return ResourceLoadPriorityLow;
130 case Resource::LinkPrefetch: 131 case Resource::LinkPrefetch:
131 return ResourceLoadPriorityVeryLow; 132 return ResourceLoadPriorityVeryLow;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 return 0; 205 return 0;
205 } 206 }
206 207
207 FetchContext& ResourceFetcher::context() const 208 FetchContext& ResourceFetcher::context() const
208 { 209 {
209 if (Frame* frame = this->frame()) 210 if (Frame* frame = this->frame())
210 return frame->fetchContext(); 211 return frame->fetchContext();
211 return FetchContext::nullInstance(); 212 return FetchContext::nullInstance();
212 } 213 }
213 214
214 unsigned long ResourceFetcher::fetchSynchronously(const ResourceRequest& passedR equest, StoredCredentials storedCredentials, ResourceError& error, ResourceRespo nse& response, Vector<char>& data) 215 ResourcePtr<Resource> ResourceFetcher::fetchSynchronously(FetchRequest& request)
215 { 216 {
216 ASSERT(document()); 217 ASSERT(document());
217 ResourceRequest request(passedRequest); 218 request.mutableResourceRequest().setTimeoutInterval(10);
218 request.setTimeoutInterval(10); 219 ResourceLoaderOptions options(request.options());
219 addAdditionalRequestHeaders(request, Resource::Raw); 220 options.synchronousPolicy = RequestSynchronously;
220 221 request.setOptions(options);
221 unsigned long identifier = createUniqueIdentifier(); 222 return requestResource(Resource::Raw, request);
222 context().dispatchWillSendRequest(m_documentLoader, identifier, request, Res ourceResponse());
223 documentLoader()->applicationCacheHost()->willStartLoadingSynchronously(requ est);
224 ResourceLoader::loadResourceSynchronously(request, storedCredentials, error, response, data);
225 int encodedDataLength = response.resourceLoadInfo() ? static_cast<int>(respo nse.resourceLoadInfo()->encodedDataLength) : -1;
226 context().sendRemainingDelegateMessages(m_documentLoader, identifier, respon se, data.data(), data.size(), encodedDataLength, error);
227 return identifier;
228 } 223 }
229 224
230 ResourcePtr<ImageResource> ResourceFetcher::fetchImage(FetchRequest& request) 225 ResourcePtr<ImageResource> ResourceFetcher::fetchImage(FetchRequest& request)
231 { 226 {
232 if (Frame* f = frame()) { 227 if (Frame* f = frame()) {
233 if (f->document()->pageDismissalEventBeingDispatched() != Document::NoDi smissal) { 228 if (f->document()->pageDismissalEventBeingDispatched() != Document::NoDi smissal) {
234 KURL requestURL = request.resourceRequest().url(); 229 KURL requestURL = request.resourceRequest().url();
235 if (requestURL.isValid() && canRequest(Resource::Image, requestURL, request.options(), request.forPreload())) 230 if (requestURL.isValid() && canRequest(Resource::Image, requestURL, request.options(), request.forPreload()))
236 PingLoader::loadImage(f, requestURL); 231 PingLoader::loadImage(f, requestURL);
237 return 0; 232 return 0;
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 { 503 {
509 if (!frame()) 504 if (!frame())
510 return false; 505 return false;
511 if (!m_documentLoader) 506 if (!m_documentLoader)
512 return true; 507 return true;
513 return m_documentLoader == frame()->loader()->activeDocumentLoader(); 508 return m_documentLoader == frame()->loader()->activeDocumentLoader();
514 } 509 }
515 510
516 ResourcePtr<Resource> ResourceFetcher::requestResource(Resource::Type type, Fetc hRequest& request) 511 ResourcePtr<Resource> ResourceFetcher::requestResource(Resource::Type type, Fetc hRequest& request)
517 { 512 {
513 ASSERT(request.options().synchronousPolicy == RequestAsynchronously || type == Resource::Raw);
514
518 KURL url = request.resourceRequest().url(); 515 KURL url = request.resourceRequest().url();
519 516
520 LOG(ResourceLoading, "ResourceFetcher::requestResource '%s', charset '%s', p riority=%d, forPreload=%u", url.elidedString().latin1().data(), request.charset( ).latin1().data(), request.priority(), request.forPreload()); 517 LOG(ResourceLoading, "ResourceFetcher::requestResource '%s', charset '%s', p riority=%d, forPreload=%u", url.elidedString().latin1().data(), request.charset( ).latin1().data(), request.priority(), request.forPreload());
521 518
522 // If only the fragment identifiers differ, it is the same resource. 519 // If only the fragment identifiers differ, it is the same resource.
523 url = MemoryCache::removeFragmentIdentifierIfNeeded(url); 520 url = MemoryCache::removeFragmentIdentifierIfNeeded(url);
524 521
525 if (!url.isValid()) 522 if (!url.isValid())
526 return 0; 523 return 0;
527 524
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 if ((policy != Use || resource->stillNeedsLoad()) && FetchRequest::NoDefer = = request.defer()) { 565 if ((policy != Use || resource->stillNeedsLoad()) && FetchRequest::NoDefer = = request.defer()) {
569 if (!shouldLoadNewResource()) { 566 if (!shouldLoadNewResource()) {
570 if (resource->inCache()) 567 if (resource->inCache())
571 memoryCache()->remove(resource.get()); 568 memoryCache()->remove(resource.get());
572 return 0; 569 return 0;
573 } 570 }
574 571
575 if (!m_documentLoader || !m_documentLoader->scheduleArchiveLoad(resource .get(), request.resourceRequest())) 572 if (!m_documentLoader || !m_documentLoader->scheduleArchiveLoad(resource .get(), request.resourceRequest()))
576 resource->load(this, request.options()); 573 resource->load(this, request.options());
577 574
578 // We don't support immediate loads, but we do support immediate failure . 575 // For asynchronous loads that immediately fail, it's sufficient to retu rn a
576 // null Resource, as it indicates that something prevented the load from starting.
577 // If there's a network error, that failure will happen asynchronously. However, if
578 // a sync load receives a network error, it will have already happened b y this point.
579 // In that case, the requester should have access to the relevant Resour ceError, so
580 // we need to return a non-null Resource.
579 if (resource->errorOccurred()) { 581 if (resource->errorOccurred()) {
580 if (resource->inCache()) 582 if (resource->inCache())
581 memoryCache()->remove(resource.get()); 583 memoryCache()->remove(resource.get());
582 return 0; 584 return request.options().synchronousPolicy == RequestSynchronously ? resource : 0;
583 } 585 }
584 } 586 }
585 587
586 // FIXME: Temporarily leave main resource caching disabled for chromium, 588 // FIXME: Temporarily leave main resource caching disabled for chromium,
587 // see https://bugs.webkit.org/show_bug.cgi?id=107962. Before caching main 589 // see https://bugs.webkit.org/show_bug.cgi?id=107962. Before caching main
588 // resources, we should be sure to understand the implications for memory 590 // resources, we should be sure to understand the implications for memory
589 // use. 591 // use.
590 // 592 //
591 // Ensure main resources aren't preloaded, and other main resource loads 593 // Ensure main resources aren't preloaded, and other main resource loads
592 // are removed from cache to prevent reuse. 594 // are removed from cache to prevent reuse.
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 } 1312 }
1311 #endif 1313 #endif
1312 1314
1313 const ResourceLoaderOptions& ResourceFetcher::defaultResourceOptions() 1315 const ResourceLoaderOptions& ResourceFetcher::defaultResourceOptions()
1314 { 1316 {
1315 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, options, (SendCallbacks, SniffCon tent, BufferData, AllowStoredCredentials, ClientRequestedCredentials, AskClientF orCrossOriginCredentials, DoSecurityCheck, CheckContentSecurityPolicy, UseDefaul tOriginRestrictionsForType, DocumentContext)); 1317 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, options, (SendCallbacks, SniffCon tent, BufferData, AllowStoredCredentials, ClientRequestedCredentials, AskClientF orCrossOriginCredentials, DoSecurityCheck, CheckContentSecurityPolicy, UseDefaul tOriginRestrictionsForType, DocumentContext));
1316 return options; 1318 return options;
1317 } 1319 }
1318 1320
1319 } 1321 }
OLDNEW
« 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