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

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: 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
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;
abarth-chromium 2013/09/13 23:48:28 Should the async pathway ASSERT that the options a
Nate Chapin 2013/09/16 20:32:50 There are a lot of pathways :/ I'd say we should
220 221 request.setOptions(options);
221 unsigned long identifier = createUniqueIdentifier(); 222 return requestResource(Resource::Raw, request);
abarth-chromium 2013/09/13 23:48:28 Should this function return a ResourcePtr<RawResou
Nate Chapin 2013/09/16 20:32:50 Probably not? Technically it's a raw resource unde
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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 return 0; 567 return 0;
573 } 568 }
574 569
575 if (!m_documentLoader || !m_documentLoader->scheduleArchiveLoad(resource .get(), request.resourceRequest())) 570 if (!m_documentLoader || !m_documentLoader->scheduleArchiveLoad(resource .get(), request.resourceRequest()))
576 resource->load(this, request.options()); 571 resource->load(this, request.options());
577 572
578 // We don't support immediate loads, but we do support immediate failure . 573 // We don't support immediate loads, but we do support immediate failure .
579 if (resource->errorOccurred()) { 574 if (resource->errorOccurred()) {
580 if (resource->inCache()) 575 if (resource->inCache())
581 memoryCache()->remove(resource.get()); 576 memoryCache()->remove(resource.get());
582 return 0; 577 return request.options().synchronousPolicy == RequestSynchronously ? resource : 0;
Nate Chapin 2013/09/12 23:28:46 This is kind of lame, wherein we let both sync and
abarth-chromium 2013/09/13 23:48:28 I might add this information as a comment.
Nate Chapin 2013/09/16 20:32:50 Will do.
583 } 578 }
584 } 579 }
585 580
586 // FIXME: Temporarily leave main resource caching disabled for chromium, 581 // FIXME: Temporarily leave main resource caching disabled for chromium,
587 // see https://bugs.webkit.org/show_bug.cgi?id=107962. Before caching main 582 // 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 583 // resources, we should be sure to understand the implications for memory
589 // use. 584 // use.
590 // 585 //
591 // Ensure main resources aren't preloaded, and other main resource loads 586 // Ensure main resources aren't preloaded, and other main resource loads
592 // are removed from cache to prevent reuse. 587 // are removed from cache to prevent reuse.
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 } 1305 }
1311 #endif 1306 #endif
1312 1307
1313 const ResourceLoaderOptions& ResourceFetcher::defaultResourceOptions() 1308 const ResourceLoaderOptions& ResourceFetcher::defaultResourceOptions()
1314 { 1309 {
1315 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, options, (SendCallbacks, SniffCon tent, BufferData, AllowStoredCredentials, ClientRequestedCredentials, AskClientF orCrossOriginCredentials, DoSecurityCheck, CheckContentSecurityPolicy, UseDefaul tOriginRestrictionsForType, DocumentContext)); 1310 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, options, (SendCallbacks, SniffCon tent, BufferData, AllowStoredCredentials, ClientRequestedCredentials, AskClientF orCrossOriginCredentials, DoSecurityCheck, CheckContentSecurityPolicy, UseDefaul tOriginRestrictionsForType, DocumentContext));
1316 return options; 1311 return options;
1317 } 1312 }
1318 1313
1319 } 1314 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698