| OLD | NEW |
| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 #include "platform/weborigin/KnownPorts.h" | 46 #include "platform/weborigin/KnownPorts.h" |
| 47 #include "platform/weborigin/SecurityOrigin.h" | 47 #include "platform/weborigin/SecurityOrigin.h" |
| 48 #include "platform/weborigin/SecurityPolicy.h" | 48 #include "platform/weborigin/SecurityPolicy.h" |
| 49 #include "public/platform/Platform.h" | 49 #include "public/platform/Platform.h" |
| 50 #include "public/platform/WebCachePolicy.h" | 50 #include "public/platform/WebCachePolicy.h" |
| 51 #include "public/platform/WebURL.h" | 51 #include "public/platform/WebURL.h" |
| 52 #include "public/platform/WebURLRequest.h" | 52 #include "public/platform/WebURLRequest.h" |
| 53 #include "wtf/text/CString.h" | 53 #include "wtf/text/CString.h" |
| 54 #include "wtf/text/WTFString.h" | 54 #include "wtf/text/WTFString.h" |
| 55 | 55 |
| 56 #define PRELOAD_DEBUG 0 | |
| 57 | |
| 58 using blink::WebURLRequest; | 56 using blink::WebURLRequest; |
| 59 | 57 |
| 60 namespace blink { | 58 namespace blink { |
| 61 | 59 |
| 62 namespace { | 60 namespace { |
| 63 | 61 |
| 64 // Events for UMA. Do not reorder or delete. Add new events at the end, but | 62 // Events for UMA. Do not reorder or delete. Add new events at the end, but |
| 65 // before SriResourceIntegrityMismatchEventCount. | 63 // before SriResourceIntegrityMismatchEventCount. |
| 66 enum SriResourceIntegrityMismatchEvent { | 64 enum SriResourceIntegrityMismatchEvent { |
| 67 CheckingForIntegrityMismatch = 0, | 65 CheckingForIntegrityMismatch = 0, |
| (...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 void ResourceFetcher::preloadStarted(Resource* resource) | 825 void ResourceFetcher::preloadStarted(Resource* resource) |
| 828 { | 826 { |
| 829 if (m_preloads && m_preloads->contains(resource)) | 827 if (m_preloads && m_preloads->contains(resource)) |
| 830 return; | 828 return; |
| 831 TRACE_EVENT_ASYNC_STEP_INTO0("blink.net", "Resource", resource, "Preload"); | 829 TRACE_EVENT_ASYNC_STEP_INTO0("blink.net", "Resource", resource, "Preload"); |
| 832 resource->increasePreloadCount(); | 830 resource->increasePreloadCount(); |
| 833 | 831 |
| 834 if (!m_preloads) | 832 if (!m_preloads) |
| 835 m_preloads = new HeapListHashSet<Member<Resource>>; | 833 m_preloads = new HeapListHashSet<Member<Resource>>; |
| 836 m_preloads->add(resource); | 834 m_preloads->add(resource); |
| 837 | |
| 838 #if PRELOAD_DEBUG | |
| 839 printf("PRELOADING %s\n", resource->url().string().latin1().data()); | |
| 840 #endif | |
| 841 } | 835 } |
| 842 | 836 |
| 843 bool ResourceFetcher::isPreloaded(const KURL& url) const | 837 bool ResourceFetcher::isPreloaded(const KURL& url) const |
| 844 { | 838 { |
| 845 if (m_preloads) { | 839 if (m_preloads) { |
| 846 for (auto resource : *m_preloads) { | 840 for (auto resource : *m_preloads) { |
| 847 if (resource->url() == url) | 841 if (resource->url() == url) |
| 848 return true; | 842 return true; |
| 849 } | 843 } |
| 850 } | 844 } |
| 851 | 845 |
| 852 return false; | 846 return false; |
| 853 } | 847 } |
| 854 | 848 |
| 855 void ResourceFetcher::clearPreloads(ClearPreloadsPolicy policy) | 849 void ResourceFetcher::clearPreloads(ClearPreloadsPolicy policy) |
| 856 { | 850 { |
| 857 #if PRELOAD_DEBUG | |
| 858 printPreloadStats(); | |
| 859 #endif | |
| 860 if (!m_preloads) | 851 if (!m_preloads) |
| 861 return; | 852 return; |
| 862 | 853 |
| 854 logPreloadStats(); |
| 855 |
| 863 for (auto resource : *m_preloads) { | 856 for (auto resource : *m_preloads) { |
| 864 resource->decreasePreloadCount(); | 857 resource->decreasePreloadCount(); |
| 865 if (resource->getPreloadResult() == Resource::PreloadNotReferenced && (p
olicy == ClearAllPreloads || !resource->isLinkPreload())) | 858 if (resource->getPreloadResult() == Resource::PreloadNotReferenced && (p
olicy == ClearAllPreloads || !resource->isLinkPreload())) |
| 866 memoryCache()->remove(resource.get()); | 859 memoryCache()->remove(resource.get()); |
| 867 } | 860 } |
| 868 m_preloads.clear(); | 861 m_preloads.clear(); |
| 869 } | 862 } |
| 870 | 863 |
| 871 ArchiveResource* ResourceFetcher::createArchive(Resource* resource) | 864 ArchiveResource* ResourceFetcher::createArchive(Resource* resource) |
| 872 { | 865 { |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 { | 1049 { |
| 1057 for (const auto& documentResource : m_documentResources) { | 1050 for (const auto& documentResource : m_documentResources) { |
| 1058 Resource* resource = documentResource.value.get(); | 1051 Resource* resource = documentResource.value.get(); |
| 1059 if (resource && resource->isImage()) { | 1052 if (resource && resource->isImage()) { |
| 1060 ImageResource* imageResource = toImageResource(resource); | 1053 ImageResource* imageResource = toImageResource(resource); |
| 1061 imageResource->reloadIfLoFi(this); | 1054 imageResource->reloadIfLoFi(this); |
| 1062 } | 1055 } |
| 1063 } | 1056 } |
| 1064 } | 1057 } |
| 1065 | 1058 |
| 1066 #if PRELOAD_DEBUG | 1059 void ResourceFetcher::logPreloadStats() |
| 1067 void ResourceFetcher::printPreloadStats() | |
| 1068 { | 1060 { |
| 1069 if (!m_preloads) | 1061 if (!m_preloads) |
| 1070 return; | 1062 return; |
| 1071 | |
| 1072 unsigned scripts = 0; | 1063 unsigned scripts = 0; |
| 1073 unsigned scriptMisses = 0; | 1064 unsigned scriptMisses = 0; |
| 1074 unsigned stylesheets = 0; | 1065 unsigned stylesheets = 0; |
| 1075 unsigned stylesheetMisses = 0; | 1066 unsigned stylesheetMisses = 0; |
| 1076 unsigned images = 0; | 1067 unsigned images = 0; |
| 1077 unsigned imageMisses = 0; | 1068 unsigned imageMisses = 0; |
| 1069 unsigned fonts = 0; |
| 1070 unsigned fontMisses = 0; |
| 1071 unsigned medias = 0; |
| 1072 unsigned mediaMisses = 0; |
| 1073 unsigned textTracks = 0; |
| 1074 unsigned textTrackMisses = 0; |
| 1075 unsigned imports = 0; |
| 1076 unsigned importMisses = 0; |
| 1077 unsigned raws = 0; |
| 1078 unsigned rawMisses = 0; |
| 1078 for (auto resource : *m_preloads) { | 1079 for (auto resource : *m_preloads) { |
| 1079 if (resource->getPreloadResult() == Resource::PreloadNotReferenced) | 1080 int missCount = resource->getPreloadResult() == Resource::PreloadNotRefe
renced ? 1 : 0; |
| 1080 printf("!! UNREFERENCED PRELOAD %s\n", resource->url().string().lati
n1().data()); | 1081 switch (resource->getType()) { |
| 1081 else if (resource->getPreloadResult() == Resource::PreloadReferencedWhil
eComplete) | 1082 case Resource::Image: |
| 1082 printf("HIT COMPLETE PRELOAD %s\n", resource->url().string().latin1(
).data()); | 1083 images++; |
| 1083 else if (resource->getPreloadResult() == Resource::PreloadReferencedWhil
eLoading) | 1084 imageMisses += missCount; |
| 1084 printf("HIT LOADING PRELOAD %s\n", resource->url().string().latin1()
.data()); | 1085 break; |
| 1085 | 1086 case Resource::Script: |
| 1086 if (resource->getType() == Resource::Script) { | |
| 1087 scripts++; | 1087 scripts++; |
| 1088 if (resource->getPreloadResult() < Resource::PreloadReferencedWhileL
oading) | 1088 scriptMisses += missCount; |
| 1089 scriptMisses++; | 1089 break; |
| 1090 } else if (resource->getType() == Resource::CSSStyleSheet) { | 1090 case Resource::CSSStyleSheet: |
| 1091 stylesheets++; | 1091 stylesheets++; |
| 1092 if (resource->getPreloadResult() < Resource::PreloadReferencedWhileL
oading) | 1092 stylesheetMisses += missCount; |
| 1093 stylesheetMisses++; | 1093 break; |
| 1094 } else { | 1094 case Resource::Font: |
| 1095 images++; | 1095 fonts++; |
| 1096 if (resource->getPreloadResult() < Resource::PreloadReferencedWhileL
oading) | 1096 fontMisses += missCount; |
| 1097 imageMisses++; | 1097 break; |
| 1098 case Resource::Media: |
| 1099 medias++; |
| 1100 mediaMisses += missCount; |
| 1101 break; |
| 1102 case Resource::TextTrack: |
| 1103 textTracks++; |
| 1104 textTrackMisses += missCount; |
| 1105 break; |
| 1106 case Resource::ImportResource: |
| 1107 imports++; |
| 1108 importMisses += missCount; |
| 1109 break; |
| 1110 case Resource::Raw: |
| 1111 raws++; |
| 1112 rawMisses += missCount; |
| 1113 break; |
| 1114 default: |
| 1115 ASSERT_NOT_REACHED(); |
| 1098 } | 1116 } |
| 1099 | |
| 1100 if (resource->errorOccurred()) | |
| 1101 memoryCache()->remove(resource.get()); | |
| 1102 | |
| 1103 resource->decreasePreloadCount(); | |
| 1104 } | 1117 } |
| 1105 m_preloads.clear(); | 1118 DEFINE_STATIC_LOCAL(CustomCountHistogram, imagePreloads, ("PreloadScanner.Co
unts.Image", 0, 100, 5)); |
| 1106 | 1119 DEFINE_STATIC_LOCAL(CustomCountHistogram, imagePreloadMisses, ("PreloadScann
er.Counts.Miss.Image", 0, 100, 5)); |
| 1120 DEFINE_STATIC_LOCAL(CustomCountHistogram, scriptPreloads, ("PreloadScanner.C
ounts.Script", 0, 100, 5)); |
| 1121 DEFINE_STATIC_LOCAL(CustomCountHistogram, scriptPreloadMisses, ("PreloadScan
ner.Counts.Miss.Script", 0, 100, 5)); |
| 1122 DEFINE_STATIC_LOCAL(CustomCountHistogram, stylesheetPreloads, ("PreloadScann
er.Counts.CSSStyleSheet", 0, 100, 5)); |
| 1123 DEFINE_STATIC_LOCAL(CustomCountHistogram, stylesheetPreloadMisses, ("Preload
Scanner.Counts.Miss.CSSStyleSheet", 0, 100, 5)); |
| 1124 DEFINE_STATIC_LOCAL(CustomCountHistogram, fontPreloads, ("PreloadScanner.Cou
nts.Font", 0, 100, 5)); |
| 1125 DEFINE_STATIC_LOCAL(CustomCountHistogram, fontPreloadMisses, ("PreloadScanne
r.Counts.Miss.Font", 0, 100, 5)); |
| 1126 DEFINE_STATIC_LOCAL(CustomCountHistogram, mediaPreloads, ("PreloadScanner.Co
unts.Media", 0, 100, 5)); |
| 1127 DEFINE_STATIC_LOCAL(CustomCountHistogram, mediaPreloadMisses, ("PreloadScann
er.Counts.Miss.Media", 0, 100, 5)); |
| 1128 DEFINE_STATIC_LOCAL(CustomCountHistogram, textTrackPreloads, ("PreloadScanne
r.Counts.TextTrack", 0, 100, 5)); |
| 1129 DEFINE_STATIC_LOCAL(CustomCountHistogram, textTrackPreloadMisses, ("PreloadS
canner.Counts.Miss.TextTrack", 0, 100, 5)); |
| 1130 DEFINE_STATIC_LOCAL(CustomCountHistogram, importPreloads, ("PreloadScanner.C
ounts.Import", 0, 100, 5)); |
| 1131 DEFINE_STATIC_LOCAL(CustomCountHistogram, importPreloadMisses, ("PreloadScan
ner.Counts.Miss.Import", 0, 100, 5)); |
| 1132 DEFINE_STATIC_LOCAL(CustomCountHistogram, rawPreloads, ("PreloadScanner.Coun
ts.Raw", 0, 100, 5)); |
| 1133 DEFINE_STATIC_LOCAL(CustomCountHistogram, rawPreloadMisses, ("PreloadScanner
.Counts.Miss.Raw", 0, 100, 5)); |
| 1134 if (images) |
| 1135 imagePreloads.count(images); |
| 1136 if (imageMisses) |
| 1137 imagePreloadMisses.count(imageMisses); |
| 1107 if (scripts) | 1138 if (scripts) |
| 1108 printf("SCRIPTS: %d (%d hits, hit rate %d%%)\n", scripts, scripts - scri
ptMisses, (scripts - scriptMisses) * 100 / scripts); | 1139 scriptPreloads.count(scripts); |
| 1140 if (scriptMisses) |
| 1141 scriptPreloadMisses.count(scriptMisses); |
| 1109 if (stylesheets) | 1142 if (stylesheets) |
| 1110 printf("STYLESHEETS: %d (%d hits, hit rate %d%%)\n", stylesheets, styles
heets - stylesheetMisses, (stylesheets - stylesheetMisses) * 100 / stylesheets); | 1143 stylesheetPreloads.count(stylesheets); |
| 1111 if (images) | 1144 if (stylesheetMisses) |
| 1112 printf("IMAGES: %d (%d hits, hit rate %d%%)\n", images, images - imageM
isses, (images - imageMisses) * 100 / images); | 1145 stylesheetPreloadMisses.count(stylesheetMisses); |
| 1146 if (fonts) |
| 1147 fontPreloads.count(fonts); |
| 1148 if (fontMisses) |
| 1149 fontPreloadMisses.count(fontMisses); |
| 1150 if (medias) |
| 1151 mediaPreloads.count(medias); |
| 1152 if (mediaMisses) |
| 1153 mediaPreloadMisses.count(mediaMisses); |
| 1154 if (textTracks) |
| 1155 textTrackPreloads.count(textTracks); |
| 1156 if (textTrackMisses) |
| 1157 textTrackPreloadMisses.count(textTrackMisses); |
| 1158 if (imports) |
| 1159 importPreloads.count(imports); |
| 1160 if (importMisses) |
| 1161 importPreloadMisses.count(importMisses); |
| 1162 if (raws) |
| 1163 rawPreloads.count(raws); |
| 1164 if (rawMisses) |
| 1165 rawPreloadMisses.count(rawMisses); |
| 1113 } | 1166 } |
| 1114 #endif | |
| 1115 | 1167 |
| 1116 const ResourceLoaderOptions& ResourceFetcher::defaultResourceOptions() | 1168 const ResourceLoaderOptions& ResourceFetcher::defaultResourceOptions() |
| 1117 { | 1169 { |
| 1118 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, options, (BufferData, AllowStored
Credentials, ClientRequestedCredentials, CheckContentSecurityPolicy, DocumentCon
text)); | 1170 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, options, (BufferData, AllowStored
Credentials, ClientRequestedCredentials, CheckContentSecurityPolicy, DocumentCon
text)); |
| 1119 return options; | 1171 return options; |
| 1120 } | 1172 } |
| 1121 | 1173 |
| 1122 String ResourceFetcher::getCacheIdentifier() const | 1174 String ResourceFetcher::getCacheIdentifier() const |
| 1123 { | 1175 { |
| 1124 if (context().isControlledByServiceWorker()) | 1176 if (context().isControlledByServiceWorker()) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1164 visitor->trace(m_context); | 1216 visitor->trace(m_context); |
| 1165 visitor->trace(m_archive); | 1217 visitor->trace(m_archive); |
| 1166 visitor->trace(m_loaders); | 1218 visitor->trace(m_loaders); |
| 1167 visitor->trace(m_nonBlockingLoaders); | 1219 visitor->trace(m_nonBlockingLoaders); |
| 1168 visitor->trace(m_documentResources); | 1220 visitor->trace(m_documentResources); |
| 1169 visitor->trace(m_preloads); | 1221 visitor->trace(m_preloads); |
| 1170 visitor->trace(m_resourceTimingInfoMap); | 1222 visitor->trace(m_resourceTimingInfoMap); |
| 1171 } | 1223 } |
| 1172 | 1224 |
| 1173 } // namespace blink | 1225 } // namespace blink |
| OLD | NEW |