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

Side by Side Diff: third_party/WebKit/Source/core/fetch/Resource.cpp

Issue 1802123002: Unify Resource loading status tracking (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
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) 2006 Samuel Weinig (sam.weinig@gmail.com) 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 #if !ENABLE(OILPAN) 151 #if !ENABLE(OILPAN)
152 , m_weakPtrFactory(this) 152 , m_weakPtrFactory(this)
153 #endif 153 #endif
154 , m_loadFinishTime(0) 154 , m_loadFinishTime(0)
155 , m_identifier(0) 155 , m_identifier(0)
156 , m_encodedSize(0) 156 , m_encodedSize(0)
157 , m_decodedSize(0) 157 , m_decodedSize(0)
158 , m_preloadCount(0) 158 , m_preloadCount(0)
159 , m_cacheIdentifier(MemoryCache::defaultCacheIdentifier()) 159 , m_cacheIdentifier(MemoryCache::defaultCacheIdentifier())
160 , m_preloadResult(PreloadNotReferenced) 160 , m_preloadResult(PreloadNotReferenced)
161 , m_requestedFromNetworkingLayer(false)
162 , m_loading(false)
163 , m_type(type) 161 , m_type(type)
164 , m_status(Pending) 162 , m_status(NotStarted)
165 , m_needsSynchronousCacheHit(false) 163 , m_needsSynchronousCacheHit(false)
166 , m_linkPreload(false) 164 , m_linkPreload(false)
167 { 165 {
168 ASSERT(m_type == unsigned(type)); // m_type is a bitfield, so this tests car eless updates of the enum. 166 ASSERT(m_type == unsigned(type)); // m_type is a bitfield, so this tests car eless updates of the enum.
169 InstanceCounters::incrementCounter(InstanceCounters::ResourceCounter); 167 InstanceCounters::incrementCounter(InstanceCounters::ResourceCounter);
170 168
171 // Currently we support the metadata caching only for HTTP family. 169 // Currently we support the metadata caching only for HTTP family.
172 if (m_resourceRequest.url().protocolIsInHTTPFamily()) 170 if (m_resourceRequest.url().protocolIsInHTTPFamily())
173 m_cacheHandler = CacheHandler::create(this); 171 m_cacheHandler = CacheHandler::create(this);
174 172
(...skipping 21 matching lines...) Expand all
196 visitor->trace(m_loader); 194 visitor->trace(m_loader);
197 #if ENABLE(OILPAN) 195 #if ENABLE(OILPAN)
198 visitor->trace(m_cacheHandler); 196 visitor->trace(m_cacheHandler);
199 #endif 197 #endif
200 } 198 }
201 199
202 void Resource::load(ResourceFetcher* fetcher, const ResourceLoaderOptions& optio ns) 200 void Resource::load(ResourceFetcher* fetcher, const ResourceLoaderOptions& optio ns)
203 { 201 {
204 RELEASE_ASSERT(!m_loader); 202 RELEASE_ASSERT(!m_loader);
205 m_options = options; 203 m_options = options;
206 m_loading = true;
207 m_status = Pending; 204 m_status = Pending;
208 205
209 ResourceRequest& request(m_revalidatingRequest.isNull() ? m_resourceRequest : m_revalidatingRequest); 206 ResourceRequest& request(m_revalidatingRequest.isNull() ? m_resourceRequest : m_revalidatingRequest);
210 if (!accept().isEmpty()) 207 if (!accept().isEmpty())
211 request.setHTTPAccept(accept()); 208 request.setHTTPAccept(accept());
212 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC redentials); 209 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC redentials);
213 210
214 // FIXME: It's unfortunate that the cache layer and below get to know anythi ng about fragment identifiers. 211 // FIXME: It's unfortunate that the cache layer and below get to know anythi ng about fragment identifiers.
215 // We should look into removing the expectation of that knowledge from the p latform network stacks. 212 // We should look into removing the expectation of that knowledge from the p latform network stacks.
216 KURL urlWithoutFragment = request.url(); 213 KURL urlWithoutFragment = request.url();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 { 281 {
285 if (!m_revalidatingRequest.isNull()) 282 if (!m_revalidatingRequest.isNull())
286 m_revalidatingRequest = ResourceRequest(); 283 m_revalidatingRequest = ResourceRequest();
287 284
288 if (!m_error.isNull() && (m_error.isCancellation() || !isPreloaded())) 285 if (!m_error.isNull() && (m_error.isCancellation() || !isPreloaded()))
289 memoryCache()->remove(this); 286 memoryCache()->remove(this);
290 287
291 setStatus(status); 288 setStatus(status);
292 ASSERT(errorOccurred()); 289 ASSERT(errorOccurred());
293 m_data.clear(); 290 m_data.clear();
294
295 setLoading(false);
296 checkNotify(); 291 checkNotify();
297 markClientsFinished(); 292 markClientsFinished();
298 } 293 }
299 294
300 void Resource::finish() 295 void Resource::finish()
301 { 296 {
302 ASSERT(m_revalidatingRequest.isNull()); 297 ASSERT(m_revalidatingRequest.isNull());
303 setLoading(false); 298 if (!errorOccurred())
299 m_status = Cached;
304 checkNotify(); 300 checkNotify();
305 markClientsFinished(); 301 markClientsFinished();
306 if (!errorOccurred())
307 m_status = Cached;
308 } 302 }
309 303
310 AtomicString Resource::httpContentType() const 304 AtomicString Resource::httpContentType() const
311 { 305 {
312 return extractMIMETypeFromMediaType(m_response.httpHeaderField(HTTPNames::Co ntent_Type).lower()); 306 return extractMIMETypeFromMediaType(m_response.httpHeaderField(HTTPNames::Co ntent_Type).lower());
313 } 307 }
314 308
315 bool Resource::passesAccessControlCheck(SecurityOrigin* securityOrigin) const 309 bool Resource::passesAccessControlCheck(SecurityOrigin* securityOrigin) const
316 { 310 {
317 String ignoredErrorDescription; 311 String ignoredErrorDescription;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 { 409 {
416 if (!m_redirectChain.size()) 410 if (!m_redirectChain.size())
417 return m_resourceRequest; 411 return m_resourceRequest;
418 return m_redirectChain.last().m_request; 412 return m_redirectChain.last().m_request;
419 } 413 }
420 414
421 void Resource::willFollowRedirect(ResourceRequest& newRequest, const ResourceRes ponse& redirectResponse) 415 void Resource::willFollowRedirect(ResourceRequest& newRequest, const ResourceRes ponse& redirectResponse)
422 { 416 {
423 newRequest.setAllowStoredCredentials(m_options.allowCredentials == AllowStor edCredentials); 417 newRequest.setAllowStoredCredentials(m_options.allowCredentials == AllowStor edCredentials);
424 m_redirectChain.append(RedirectPair(newRequest, redirectResponse)); 418 m_redirectChain.append(RedirectPair(newRequest, redirectResponse));
425 m_requestedFromNetworkingLayer = true;
426 } 419 }
427 420
428 bool Resource::unlock() 421 bool Resource::unlock()
429 { 422 {
430 if (!m_data) 423 if (!m_data)
431 return false; 424 return false;
432 425
433 if (!m_data->isLocked()) 426 if (!m_data->isLocked())
434 return true; 427 return true;
435 428
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 return m_cachedMetadata.get(); 546 return m_cachedMetadata.get();
554 } 547 }
555 548
556 void Resource::clearLoader() 549 void Resource::clearLoader()
557 { 550 {
558 m_loader = nullptr; 551 m_loader = nullptr;
559 } 552 }
560 553
561 void Resource::didAddClient(ResourceClient* c) 554 void Resource::didAddClient(ResourceClient* c)
562 { 555 {
563 if (!isLoading() && !stillNeedsLoad()) { 556 if (isLoaded()) {
564 c->notifyFinished(this); 557 c->notifyFinished(this);
565 if (m_clients.contains(c)) { 558 if (m_clients.contains(c)) {
566 m_finishedClients.add(c); 559 m_finishedClients.add(c);
567 m_clients.remove(c); 560 m_clients.remove(c);
568 } 561 }
569 } 562 }
570 } 563 }
571 564
572 static bool shouldSendCachedDataSynchronouslyForType(Resource::Type type) 565 static bool shouldSendCachedDataSynchronouslyForType(Resource::Type type)
573 { 566 {
(...skipping 14 matching lines...) Expand all
588 return false; 581 return false;
589 } 582 }
590 583
591 void Resource::addClient(ResourceClient* client) 584 void Resource::addClient(ResourceClient* client)
592 { 585 {
593 ASSERT(!isPurgeable()); 586 ASSERT(!isPurgeable());
594 587
595 if (m_preloadResult == PreloadNotReferenced) { 588 if (m_preloadResult == PreloadNotReferenced) {
596 if (isLoaded()) 589 if (isLoaded())
597 m_preloadResult = PreloadReferencedWhileComplete; 590 m_preloadResult = PreloadReferencedWhileComplete;
598 else if (m_requestedFromNetworkingLayer) 591 else if (isLoading())
599 m_preloadResult = PreloadReferencedWhileLoading; 592 m_preloadResult = PreloadReferencedWhileLoading;
600 else 593 else
601 m_preloadResult = PreloadReferenced; 594 m_preloadResult = PreloadReferenced;
602 } 595 }
603 if (!hasClients()) 596 if (!hasClients())
604 memoryCache()->makeLive(this); 597 memoryCache()->makeLive(this);
605 598
606 if (!m_revalidatingRequest.isNull()) { 599 if (!m_revalidatingRequest.isNull()) {
607 m_clients.add(client); 600 m_clients.add(client);
608 return; 601 return;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 unlock(); 659 unlock();
667 } 660 }
668 661
669 void Resource::cancelTimerFired(Timer<Resource>* timer) 662 void Resource::cancelTimerFired(Timer<Resource>* timer)
670 { 663 {
671 ASSERT_UNUSED(timer, timer == &m_cancelTimer); 664 ASSERT_UNUSED(timer, timer == &m_cancelTimer);
672 if (hasClients() || !m_loader) 665 if (hasClients() || !m_loader)
673 return; 666 return;
674 RefPtrWillBeRawPtr<Resource> protect(this); 667 RefPtrWillBeRawPtr<Resource> protect(this);
675 m_loader->cancelIfNotFinishing(); 668 m_loader->cancelIfNotFinishing();
676 if (m_status != Cached) 669 memoryCache()->remove(this);
Nate Chapin 2016/03/18 21:24:06 This clause is weird. If we cancel *while finishin
hiroshige 2016/03/18 23:21:20 This is the case in XHR and might cause the test f
Nate Chapin 2016/03/21 22:04:01 Yeah, it seems like a good opportunity for cleanup
677 memoryCache()->remove(this);
678 } 670 }
679 671
680 void Resource::setDecodedSize(size_t decodedSize) 672 void Resource::setDecodedSize(size_t decodedSize)
681 { 673 {
682 if (decodedSize == m_decodedSize) 674 if (decodedSize == m_decodedSize)
683 return; 675 return;
684 size_t oldSize = size(); 676 size_t oldSize = size();
685 m_decodedSize = decodedSize; 677 m_decodedSize = decodedSize;
686 memoryCache()->update(this, oldSize, size()); 678 memoryCache()->update(this, oldSize, size());
687 memoryCache()->updateDecodedResource(this, UpdateForPropertyChange); 679 memoryCache()->updateDecodedResource(this, UpdateForPropertyChange);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 return !m_response.httpHeaderField(HTTPNames::Vary).isNull(); 850 return !m_response.httpHeaderField(HTTPNames::Vary).isNull();
859 } 851 }
860 852
861 bool Resource::mustRevalidateDueToCacheHeaders() 853 bool Resource::mustRevalidateDueToCacheHeaders()
862 { 854 {
863 return !canUseResponse(m_response, m_responseTimestamp) || m_resourceRequest .cacheControlContainsNoCache() || m_resourceRequest.cacheControlContainsNoStore( ); 855 return !canUseResponse(m_response, m_responseTimestamp) || m_resourceRequest .cacheControlContainsNoCache() || m_resourceRequest.cacheControlContainsNoStore( );
864 } 856 }
865 857
866 bool Resource::canUseCacheValidator() 858 bool Resource::canUseCacheValidator()
867 { 859 {
868 if (m_loading || errorOccurred()) 860 if (isLoading() || errorOccurred())
869 return false; 861 return false;
870 862
871 if (hasCacheControlNoStoreHeader()) 863 if (hasCacheControlNoStoreHeader())
872 return false; 864 return false;
873 return m_response.hasCacheValidatorFields() || m_resourceRequest.hasCacheVal idatorFields(); 865 return m_response.hasCacheValidatorFields() || m_resourceRequest.hasCacheVal idatorFields();
874 } 866 }
875 867
876 bool Resource::isPurgeable() const 868 bool Resource::isPurgeable() const
877 { 869 {
878 return m_data && !m_data->isLocked(); 870 return m_data && !m_data->isLocked();
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 case Resource::Media: 1092 case Resource::Media:
1101 return "Media"; 1093 return "Media";
1102 case Resource::Manifest: 1094 case Resource::Manifest:
1103 return "Manifest"; 1095 return "Manifest";
1104 } 1096 }
1105 ASSERT_NOT_REACHED(); 1097 ASSERT_NOT_REACHED();
1106 return "Unknown"; 1098 return "Unknown";
1107 } 1099 }
1108 1100
1109 } // namespace blink 1101 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698