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 | 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All |
6 rights reserved. | 6 rights reserved. |
7 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ | 7 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ |
8 | 8 |
9 This library is free software; you can redistribute it and/or | 9 This library is free software; you can redistribute it and/or |
10 modify it under the terms of the GNU Library General Public | 10 modify it under the terms of the GNU Library General Public |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 if (params.IsSpeculativePreload() || params.IsLinkPreload()) { | 475 if (params.IsSpeculativePreload() || params.IsLinkPreload()) { |
476 DEFINE_RESOURCE_HISTOGRAM("Preload."); | 476 DEFINE_RESOURCE_HISTOGRAM("Preload."); |
477 } else { | 477 } else { |
478 DEFINE_RESOURCE_HISTOGRAM(""); | 478 DEFINE_RESOURCE_HISTOGRAM(""); |
479 } | 479 } |
480 | 480 |
481 // Aims to count Resource only referenced from MemoryCache (i.e. what would be | 481 // Aims to count Resource only referenced from MemoryCache (i.e. what would be |
482 // dead if MemoryCache holds weak references to Resource). Currently we check | 482 // dead if MemoryCache holds weak references to Resource). Currently we check |
483 // references to Resource from ResourceClient and |m_preloads| only, because | 483 // references to Resource from ResourceClient and |m_preloads| only, because |
484 // they are major sources of references. | 484 // they are major sources of references. |
485 if (resource && !resource->IsAlive() && | 485 if (resource && !resource->IsAlive() && !preloads_.Contains(resource)) { |
486 (!preloads_ || !preloads_->Contains(resource))) { | |
487 DEFINE_RESOURCE_HISTOGRAM("Dead."); | 486 DEFINE_RESOURCE_HISTOGRAM("Dead."); |
488 } | 487 } |
489 } | 488 } |
490 | 489 |
491 ResourceFetcher::PrepareRequestResult ResourceFetcher::PrepareRequest( | 490 ResourceFetcher::PrepareRequestResult ResourceFetcher::PrepareRequest( |
492 FetchParameters& params, | 491 FetchParameters& params, |
493 const ResourceFactory& factory, | 492 const ResourceFactory& factory, |
494 const SubstituteData& substitute_data, | 493 const SubstituteData& substitute_data, |
495 unsigned long identifier, | 494 unsigned long identifier, |
496 ResourceRequestBlockedReason& blocked_reason) { | 495 ResourceRequestBlockedReason& blocked_reason) { |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1081 | 1080 |
1082 int ResourceFetcher::BlockingRequestCount() const { | 1081 int ResourceFetcher::BlockingRequestCount() const { |
1083 return loaders_.size(); | 1082 return loaders_.size(); |
1084 } | 1083 } |
1085 | 1084 |
1086 int ResourceFetcher::NonblockingRequestCount() const { | 1085 int ResourceFetcher::NonblockingRequestCount() const { |
1087 return non_blocking_loaders_.size(); | 1086 return non_blocking_loaders_.size(); |
1088 } | 1087 } |
1089 | 1088 |
1090 void ResourceFetcher::PreloadStarted(Resource* resource) { | 1089 void ResourceFetcher::PreloadStarted(Resource* resource) { |
1091 if (preloads_ && preloads_->Contains(resource)) | 1090 if (preloads_.Contains(resource)) |
1092 return; | 1091 return; |
1093 resource->IncreasePreloadCount(); | 1092 resource->IncreasePreloadCount(); |
1094 | 1093 |
1095 if (!preloads_) | 1094 preloads_.insert(resource); |
1096 preloads_ = new HeapListHashSet<Member<Resource>>; | |
1097 preloads_->insert(resource); | |
1098 | 1095 |
1099 if (preloaded_urls_for_test_) | 1096 if (preloaded_urls_for_test_) |
1100 preloaded_urls_for_test_->insert(resource->Url().GetString()); | 1097 preloaded_urls_for_test_->insert(resource->Url().GetString()); |
1101 } | 1098 } |
1102 | 1099 |
1103 void ResourceFetcher::EnableIsPreloadedForTest() { | 1100 void ResourceFetcher::EnableIsPreloadedForTest() { |
1104 if (preloaded_urls_for_test_) | 1101 if (preloaded_urls_for_test_) |
1105 return; | 1102 return; |
1106 preloaded_urls_for_test_ = WTF::WrapUnique(new HashSet<String>); | 1103 preloaded_urls_for_test_ = WTF::WrapUnique(new HashSet<String>); |
1107 | 1104 |
1108 if (preloads_) { | 1105 for (const auto& resource : preloads_) |
1109 for (const auto& resource : *preloads_) | 1106 preloaded_urls_for_test_->insert(resource->Url().GetString()); |
1110 preloaded_urls_for_test_->insert(resource->Url().GetString()); | |
1111 } | |
1112 } | 1107 } |
1113 | 1108 |
1114 bool ResourceFetcher::IsPreloadedForTest(const KURL& url) const { | 1109 bool ResourceFetcher::IsPreloadedForTest(const KURL& url) const { |
1115 DCHECK(preloaded_urls_for_test_); | 1110 DCHECK(preloaded_urls_for_test_); |
1116 return preloaded_urls_for_test_->Contains(url.GetString()); | 1111 return preloaded_urls_for_test_->Contains(url.GetString()); |
1117 } | 1112 } |
1118 | 1113 |
1119 void ResourceFetcher::ClearPreloads(ClearPreloadsPolicy policy) { | 1114 void ResourceFetcher::ClearPreloads(ClearPreloadsPolicy policy) { |
1120 if (!preloads_) | |
1121 return; | |
1122 | |
1123 LogPreloadStats(policy); | 1115 LogPreloadStats(policy); |
1124 | 1116 |
1125 for (const auto& resource : *preloads_) { | 1117 for (const auto& resource : preloads_) { |
1126 if (policy == kClearAllPreloads || !resource->IsLinkPreload()) { | 1118 if (policy == kClearAllPreloads || !resource->IsLinkPreload()) { |
1127 resource->DecreasePreloadCount(); | 1119 resource->DecreasePreloadCount(); |
1128 if (resource->GetPreloadResult() == Resource::kPreloadNotReferenced) | 1120 if (resource->GetPreloadResult() == Resource::kPreloadNotReferenced) |
1129 GetMemoryCache()->Remove(resource.Get()); | 1121 GetMemoryCache()->Remove(resource.Get()); |
1130 preloads_->erase(resource); | 1122 preloads_.erase(resource); |
1131 } | 1123 } |
1132 } | 1124 } |
1133 if (!preloads_->size()) | |
1134 preloads_.Clear(); | |
1135 } | 1125 } |
1136 | 1126 |
1137 void ResourceFetcher::WarnUnusedPreloads() { | 1127 void ResourceFetcher::WarnUnusedPreloads() { |
1138 if (!preloads_) | 1128 for (const auto& resource : preloads_) { |
1139 return; | |
1140 for (const auto& resource : *preloads_) { | |
1141 if (resource && resource->IsLinkPreload() && | 1129 if (resource && resource->IsLinkPreload() && |
1142 resource->GetPreloadResult() == Resource::kPreloadNotReferenced) { | 1130 resource->GetPreloadResult() == Resource::kPreloadNotReferenced) { |
1143 Context().AddConsoleMessage( | 1131 Context().AddConsoleMessage( |
1144 "The resource " + resource->Url().GetString() + | 1132 "The resource " + resource->Url().GetString() + |
1145 " was preloaded using link preload but not used within a few " | 1133 " was preloaded using link preload but not used within a few " |
1146 "seconds from the window's load event. Please make sure it " | 1134 "seconds from the window's load event. Please make sure it " |
1147 "wasn't preloaded for nothing.", | 1135 "wasn't preloaded for nothing.", |
1148 FetchContext::kLogWarningMessage); | 1136 FetchContext::kLogWarningMessage); |
1149 } | 1137 } |
1150 } | 1138 } |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 | 1352 |
1365 void ResourceFetcher::ReloadLoFiImages() { | 1353 void ResourceFetcher::ReloadLoFiImages() { |
1366 for (const auto& document_resource : document_resources_) { | 1354 for (const auto& document_resource : document_resources_) { |
1367 Resource* resource = document_resource.value.Get(); | 1355 Resource* resource = document_resource.value.Get(); |
1368 if (resource) | 1356 if (resource) |
1369 resource->ReloadIfLoFiOrPlaceholderImage(this, Resource::kReloadAlways); | 1357 resource->ReloadIfLoFiOrPlaceholderImage(this, Resource::kReloadAlways); |
1370 } | 1358 } |
1371 } | 1359 } |
1372 | 1360 |
1373 void ResourceFetcher::LogPreloadStats(ClearPreloadsPolicy policy) { | 1361 void ResourceFetcher::LogPreloadStats(ClearPreloadsPolicy policy) { |
1374 if (!preloads_) | |
1375 return; | |
1376 unsigned scripts = 0; | 1362 unsigned scripts = 0; |
1377 unsigned script_misses = 0; | 1363 unsigned script_misses = 0; |
1378 unsigned stylesheets = 0; | 1364 unsigned stylesheets = 0; |
1379 unsigned stylesheet_misses = 0; | 1365 unsigned stylesheet_misses = 0; |
1380 unsigned images = 0; | 1366 unsigned images = 0; |
1381 unsigned image_misses = 0; | 1367 unsigned image_misses = 0; |
1382 unsigned fonts = 0; | 1368 unsigned fonts = 0; |
1383 unsigned font_misses = 0; | 1369 unsigned font_misses = 0; |
1384 unsigned medias = 0; | 1370 unsigned medias = 0; |
1385 unsigned media_misses = 0; | 1371 unsigned media_misses = 0; |
1386 unsigned text_tracks = 0; | 1372 unsigned text_tracks = 0; |
1387 unsigned text_track_misses = 0; | 1373 unsigned text_track_misses = 0; |
1388 unsigned imports = 0; | 1374 unsigned imports = 0; |
1389 unsigned import_misses = 0; | 1375 unsigned import_misses = 0; |
1390 unsigned raws = 0; | 1376 unsigned raws = 0; |
1391 unsigned raw_misses = 0; | 1377 unsigned raw_misses = 0; |
1392 for (const auto& resource : *preloads_) { | 1378 for (const auto& resource : preloads_) { |
1393 // Do not double count link rel preloads. These do not get cleared if the | 1379 // Do not double count link rel preloads. These do not get cleared if the |
1394 // ClearPreloadsPolicy is only clearing speculative markup preloads. | 1380 // ClearPreloadsPolicy is only clearing speculative markup preloads. |
1395 if (resource->IsLinkPreload() && | 1381 if (resource->IsLinkPreload() && |
1396 policy == kClearSpeculativeMarkupPreloads) { | 1382 policy == kClearSpeculativeMarkupPreloads) { |
1397 continue; | 1383 continue; |
1398 } | 1384 } |
1399 int miss_count = | 1385 int miss_count = |
1400 resource->GetPreloadResult() == Resource::kPreloadNotReferenced ? 1 : 0; | 1386 resource->GetPreloadResult() == Resource::kPreloadNotReferenced ? 1 : 0; |
1401 switch (resource->GetType()) { | 1387 switch (resource->GetType()) { |
1402 case Resource::kImage: | 1388 case Resource::kImage: |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1577 visitor->Trace(context_); | 1563 visitor->Trace(context_); |
1578 visitor->Trace(archive_); | 1564 visitor->Trace(archive_); |
1579 visitor->Trace(loaders_); | 1565 visitor->Trace(loaders_); |
1580 visitor->Trace(non_blocking_loaders_); | 1566 visitor->Trace(non_blocking_loaders_); |
1581 visitor->Trace(document_resources_); | 1567 visitor->Trace(document_resources_); |
1582 visitor->Trace(preloads_); | 1568 visitor->Trace(preloads_); |
1583 visitor->Trace(resource_timing_info_map_); | 1569 visitor->Trace(resource_timing_info_map_); |
1584 } | 1570 } |
1585 | 1571 |
1586 } // namespace blink | 1572 } // namespace blink |
OLD | NEW |