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

Side by Side Diff: Source/core/fetch/ResourceFetcher.cpp

Issue 645513003: Use C++11 range-based loop in core/fetch (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: mike's comments Created 6 years, 2 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) 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 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 ASSERT(resource->url() == url.string()); 802 ASSERT(resource->url() == url.string());
803 m_documentResources.set(resource->url(), resource); 803 m_documentResources.set(resource->url(), resource);
804 return resource; 804 return resource;
805 } 805 }
806 806
807 void ResourceFetcher::resourceTimingReportTimerFired(Timer<ResourceFetcher>* tim er) 807 void ResourceFetcher::resourceTimingReportTimerFired(Timer<ResourceFetcher>* tim er)
808 { 808 {
809 ASSERT_UNUSED(timer, timer == &m_resourceTimingReportTimer); 809 ASSERT_UNUSED(timer, timer == &m_resourceTimingReportTimer);
810 HashMap<RefPtr<ResourceTimingInfo>, bool> timingReports; 810 HashMap<RefPtr<ResourceTimingInfo>, bool> timingReports;
811 timingReports.swap(m_scheduledResourceTimingReports); 811 timingReports.swap(m_scheduledResourceTimingReports);
812 HashMap<RefPtr<ResourceTimingInfo>, bool>::iterator end = timingReports.end( ); 812 for (const auto& timingInfo : timingReports)
813 for (HashMap<RefPtr<ResourceTimingInfo>, bool>::iterator it = timingReports. begin(); it != end; ++it) { 813 reportResourceTiming(timingInfo.key.get(), document(), timingInfo.value) ;
814 RefPtr<ResourceTimingInfo> info = it->key;
815 bool isMainResource = it->value;
816 reportResourceTiming(info.get(), document(), isMainResource);
817 }
818 } 814 }
819 815
820 void ResourceFetcher::determineRequestContext(ResourceRequest& request, Resource ::Type type) 816 void ResourceFetcher::determineRequestContext(ResourceRequest& request, Resource ::Type type)
821 { 817 {
822 WebURLRequest::RequestContext requestContext = requestContextFromType(this, type); 818 WebURLRequest::RequestContext requestContext = requestContextFromType(this, type);
823 request.setRequestContext(requestContext); 819 request.setRequestContext(requestContext);
824 } 820 }
825 821
826 ResourceRequestCachePolicy ResourceFetcher::resourceRequestCachePolicy(const Res ourceRequest& request, Resource::Type type) 822 ResourceRequestCachePolicy ResourceFetcher::resourceRequestCachePolicy(const Res ourceRequest& request, Resource::Type type)
827 { 823 {
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 return frame() && !frame()->loader().client()->allowImage(m_imagesEnabled, u rl); 1126 return frame() && !frame()->loader().client()->allowImage(m_imagesEnabled, u rl);
1131 } 1127 }
1132 1128
1133 bool ResourceFetcher::shouldDeferImageLoad(const KURL& url) const 1129 bool ResourceFetcher::shouldDeferImageLoad(const KURL& url) const
1134 { 1130 {
1135 return clientDefersImage(url) || !m_autoLoadImages; 1131 return clientDefersImage(url) || !m_autoLoadImages;
1136 } 1132 }
1137 1133
1138 void ResourceFetcher::reloadImagesIfNotDeferred() 1134 void ResourceFetcher::reloadImagesIfNotDeferred()
1139 { 1135 {
1140 DocumentResourceMap::iterator end = m_documentResources.end(); 1136 for (const auto& documentResource : m_documentResources) {
1141 for (DocumentResourceMap::iterator it = m_documentResources.begin(); it != e nd; ++it) { 1137 Resource* resource = documentResource.value.get();
1142 Resource* resource = it->value.get();
1143 if (resource->type() == Resource::Image && resource->stillNeedsLoad() && !clientDefersImage(resource->url())) 1138 if (resource->type() == Resource::Image && resource->stillNeedsLoad() && !clientDefersImage(resource->url()))
1144 const_cast<Resource*>(resource)->load(this, defaultResourceOptions() ); 1139 const_cast<Resource*>(resource)->load(this, defaultResourceOptions() );
1145 } 1140 }
1146 } 1141 }
1147 1142
1148 void ResourceFetcher::redirectReceived(Resource* resource, const ResourceRespons e& redirectResponse) 1143 void ResourceFetcher::redirectReceived(Resource* resource, const ResourceRespons e& redirectResponse)
1149 { 1144 {
1150 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource); 1145 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource);
1151 if (it != m_resourceTimingInfoMap.end()) 1146 if (it != m_resourceTimingInfoMap.end())
1152 it->value->addRedirect(redirectResponse); 1147 it->value->addRedirect(redirectResponse);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 { 1183 {
1189 ASSERT_UNUSED(timer, timer == &m_garbageCollectDocumentResourcesTimer); 1184 ASSERT_UNUSED(timer, timer == &m_garbageCollectDocumentResourcesTimer);
1190 garbageCollectDocumentResources(); 1185 garbageCollectDocumentResources();
1191 } 1186 }
1192 1187
1193 void ResourceFetcher::garbageCollectDocumentResources() 1188 void ResourceFetcher::garbageCollectDocumentResources()
1194 { 1189 {
1195 typedef Vector<String, 10> StringVector; 1190 typedef Vector<String, 10> StringVector;
1196 StringVector resourcesToDelete; 1191 StringVector resourcesToDelete;
1197 1192
1198 for (DocumentResourceMap::iterator it = m_documentResources.begin(); it != m _documentResources.end(); ++it) { 1193 for (const auto& documentResource : m_documentResources) {
1199 if (it->value->hasOneHandle()) 1194 if (documentResource.value->hasOneHandle())
1200 resourcesToDelete.append(it->key); 1195 resourcesToDelete.append(documentResource.key);
1201 } 1196 }
1202 1197
1203 m_documentResources.removeAll(resourcesToDelete); 1198 m_documentResources.removeAll(resourcesToDelete);
1204 } 1199 }
1205 1200
1206 void ResourceFetcher::notifyLoadedFromMemoryCache(Resource* resource) 1201 void ResourceFetcher::notifyLoadedFromMemoryCache(Resource* resource)
1207 { 1202 {
1208 if (!frame() || !frame()->page() || resource->status() != Resource::Cached | | m_validatedURLs.contains(resource->url())) 1203 if (!frame() || !frame()->page() || resource->status() != Resource::Cached | | m_validatedURLs.contains(resource->url()))
1209 return; 1204 return;
1210 1205
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 #if PRELOAD_DEBUG 1265 #if PRELOAD_DEBUG
1271 printf("PRELOADING %s\n", resource->url().string().latin1().data()); 1266 printf("PRELOADING %s\n", resource->url().string().latin1().data());
1272 #endif 1267 #endif
1273 } 1268 }
1274 1269
1275 bool ResourceFetcher::isPreloaded(const String& urlString) const 1270 bool ResourceFetcher::isPreloaded(const String& urlString) const
1276 { 1271 {
1277 const KURL& url = m_document->completeURL(urlString); 1272 const KURL& url = m_document->completeURL(urlString);
1278 1273
1279 if (m_preloads) { 1274 if (m_preloads) {
1280 ListHashSet<Resource*>::iterator end = m_preloads->end(); 1275 for (const auto& resource : *m_preloads) {
1281 for (ListHashSet<Resource*>::iterator it = m_preloads->begin(); it != en d; ++it) {
1282 Resource* resource = *it;
1283 if (resource->url() == url) 1276 if (resource->url() == url)
1284 return true; 1277 return true;
1285 } 1278 }
1286 } 1279 }
1287 1280
1288 return false; 1281 return false;
1289 } 1282 }
1290 1283
1291 void ResourceFetcher::clearPreloads() 1284 void ResourceFetcher::clearPreloads()
1292 { 1285 {
1293 #if PRELOAD_DEBUG 1286 #if PRELOAD_DEBUG
1294 printPreloadStats(); 1287 printPreloadStats();
1295 #endif 1288 #endif
1296 if (!m_preloads) 1289 if (!m_preloads)
1297 return; 1290 return;
1298 1291
1299 ListHashSet<Resource*>::iterator end = m_preloads->end(); 1292 for (const auto& resource : *m_preloads) {
1300 for (ListHashSet<Resource*>::iterator it = m_preloads->begin(); it != end; + +it) { 1293 resource->decreasePreloadCount();
1301 Resource* res = *it; 1294 bool deleted = resource->deleteIfPossible();
1302 res->decreasePreloadCount(); 1295 if (!deleted && resource->preloadResult() == Resource::PreloadNotReferen ced)
1303 bool deleted = res->deleteIfPossible(); 1296 memoryCache()->remove(resource);
1304 if (!deleted && res->preloadResult() == Resource::PreloadNotReferenced)
1305 memoryCache()->remove(res);
1306 } 1297 }
1307 m_preloads.clear(); 1298 m_preloads.clear();
1308 } 1299 }
1309 1300
1310 void ResourceFetcher::didFinishLoading(const Resource* resource, double finishTi me, int64_t encodedDataLength) 1301 void ResourceFetcher::didFinishLoading(const Resource* resource, double finishTi me, int64_t encodedDataLength)
1311 { 1302 {
1312 TRACE_EVENT_ASYNC_END0("net", "Resource", resource); 1303 TRACE_EVENT_ASYNC_END0("net", "Resource", resource);
1313 context().dispatchDidFinishLoading(m_documentLoader, resource->identifier(), finishTime, encodedDataLength); 1304 context().dispatchDidFinishLoading(m_documentLoader, resource->identifier(), finishTime, encodedDataLength);
1314 } 1305 }
1315 1306
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 { 1456 {
1466 if (!m_preloads) 1457 if (!m_preloads)
1467 return; 1458 return;
1468 1459
1469 unsigned scripts = 0; 1460 unsigned scripts = 0;
1470 unsigned scriptMisses = 0; 1461 unsigned scriptMisses = 0;
1471 unsigned stylesheets = 0; 1462 unsigned stylesheets = 0;
1472 unsigned stylesheetMisses = 0; 1463 unsigned stylesheetMisses = 0;
1473 unsigned images = 0; 1464 unsigned images = 0;
1474 unsigned imageMisses = 0; 1465 unsigned imageMisses = 0;
1475 ListHashSet<Resource*>::iterator end = m_preloads->end(); 1466 for (const auto& resource : *m_preloads) {
1476 for (ListHashSet<Resource*>::iterator it = m_preloads->begin(); it != end; + +it) { 1467 if (resource->preloadResult() == Resource::PreloadNotReferenced)
1477 Resource* res = *it; 1468 printf("!! UNREFERENCED PRELOAD %s\n", resource->url().string().lati n1().data());
1478 if (res->preloadResult() == Resource::PreloadNotReferenced) 1469 else if (resource->preloadResult() == Resource::PreloadReferencedWhileCo mplete)
1479 printf("!! UNREFERENCED PRELOAD %s\n", res->url().string().latin1(). data()); 1470 printf("HIT COMPLETE PRELOAD %s\n", resource->url().string().latin1( ).data());
1480 else if (res->preloadResult() == Resource::PreloadReferencedWhileComplet e) 1471 else if (resource->preloadResult() == Resource::PreloadReferencedWhileLo ading)
1481 printf("HIT COMPLETE PRELOAD %s\n", res->url().string().latin1().dat a()); 1472 printf("HIT LOADING PRELOAD %s\n", resource->url().string().latin1() .data());
1482 else if (res->preloadResult() == Resource::PreloadReferencedWhileLoading )
1483 printf("HIT LOADING PRELOAD %s\n", res->url().string().latin1().data ());
1484 1473
1485 if (res->type() == Resource::Script) { 1474 if (resource->type() == Resource::Script) {
1486 scripts++; 1475 scripts++;
1487 if (res->preloadResult() < Resource::PreloadReferencedWhileLoading) 1476 if (resource->preloadResult() < Resource::PreloadReferencedWhileLoad ing)
1488 scriptMisses++; 1477 scriptMisses++;
1489 } else if (res->type() == Resource::CSSStyleSheet) { 1478 } else if (resource->type() == Resource::CSSStyleSheet) {
1490 stylesheets++; 1479 stylesheets++;
1491 if (res->preloadResult() < Resource::PreloadReferencedWhileLoading) 1480 if (resource->preloadResult() < Resource::PreloadReferencedWhileLoad ing)
1492 stylesheetMisses++; 1481 stylesheetMisses++;
1493 } else { 1482 } else {
1494 images++; 1483 images++;
1495 if (res->preloadResult() < Resource::PreloadReferencedWhileLoading) 1484 if (resource->preloadResult() < Resource::PreloadReferencedWhileLoad ing)
1496 imageMisses++; 1485 imageMisses++;
1497 } 1486 }
1498 1487
1499 if (res->errorOccurred()) 1488 if (resource->errorOccurred())
1500 memoryCache()->remove(res); 1489 memoryCache()->remove(resource);
1501 1490
1502 res->decreasePreloadCount(); 1491 resource->decreasePreloadCount();
1503 } 1492 }
1504 m_preloads.clear(); 1493 m_preloads.clear();
1505 1494
1506 if (scripts) 1495 if (scripts)
1507 printf("SCRIPTS: %d (%d hits, hit rate %d%%)\n", scripts, scripts - scri ptMisses, (scripts - scriptMisses) * 100 / scripts); 1496 printf("SCRIPTS: %d (%d hits, hit rate %d%%)\n", scripts, scripts - scri ptMisses, (scripts - scriptMisses) * 100 / scripts);
1508 if (stylesheets) 1497 if (stylesheets)
1509 printf("STYLESHEETS: %d (%d hits, hit rate %d%%)\n", stylesheets, styles heets - stylesheetMisses, (stylesheets - stylesheetMisses) * 100 / stylesheets); 1498 printf("STYLESHEETS: %d (%d hits, hit rate %d%%)\n", stylesheets, styles heets - stylesheetMisses, (stylesheets - stylesheetMisses) * 100 / stylesheets);
1510 if (images) 1499 if (images)
1511 printf("IMAGES: %d (%d hits, hit rate %d%%)\n", images, images - imageM isses, (images - imageMisses) * 100 / images); 1500 printf("IMAGES: %d (%d hits, hit rate %d%%)\n", images, images - imageM isses, (images - imageMisses) * 100 / images);
1512 } 1501 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 1542
1554 void ResourceFetcher::trace(Visitor* visitor) 1543 void ResourceFetcher::trace(Visitor* visitor)
1555 { 1544 {
1556 visitor->trace(m_document); 1545 visitor->trace(m_document);
1557 visitor->trace(m_loaders); 1546 visitor->trace(m_loaders);
1558 visitor->trace(m_multipartLoaders); 1547 visitor->trace(m_multipartLoaders);
1559 ResourceLoaderHost::trace(visitor); 1548 ResourceLoaderHost::trace(visitor);
1560 } 1549 }
1561 1550
1562 } 1551 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698