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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 | 290 |
291 // Limit the number of URLs in m_validatedURLs to avoid memory bloat. | 291 // Limit the number of URLs in m_validatedURLs to avoid memory bloat. |
292 // http://crbug.com/52411 | 292 // http://crbug.com/52411 |
293 static const int kMaxValidatedURLsSize = 10000; | 293 static const int kMaxValidatedURLsSize = 10000; |
294 | 294 |
295 void ResourceFetcher::requestLoadStarted(unsigned long identifier, | 295 void ResourceFetcher::requestLoadStarted(unsigned long identifier, |
296 Resource* resource, | 296 Resource* resource, |
297 const FetchRequest& request, | 297 const FetchRequest& request, |
298 ResourceLoadStartType type, | 298 ResourceLoadStartType type, |
299 bool isStaticData) { | 299 bool isStaticData) { |
300 if (type == ResourceLoadingFromCache && | 300 if (type == ResourceLoadStartType::kFromMemoryCache && |
301 resource->getStatus() == ResourceStatus::Cached && | 301 resource->getStatus() == ResourceStatus::Cached && |
302 !m_validatedURLs.contains(resource->url())) { | 302 !m_validatedURLs.contains(resource->url())) { |
303 context().dispatchDidLoadResourceFromMemoryCache( | 303 // Loaded from MemoryCache. |
304 identifier, resource, request.resourceRequest().frameType(), | 304 didLoadResourceFromMemoryCache(identifier, resource, request); |
305 request.resourceRequest().requestContext()); | |
306 } | 305 } |
307 | 306 |
308 if (isStaticData) | 307 if (isStaticData) |
309 return; | 308 return; |
310 | 309 |
311 if (type == ResourceLoadingFromCache && !resource->stillNeedsLoad() && | 310 if (type == ResourceLoadStartType::kFromMemoryCache && |
311 !resource->stillNeedsLoad() && | |
312 !m_validatedURLs.contains(request.resourceRequest().url())) { | 312 !m_validatedURLs.contains(request.resourceRequest().url())) { |
313 // Resources loaded from memory cache should be reported the first time | 313 // Resources loaded from memory cache should be reported the first time |
314 // they're used. | 314 // they're used. |
315 RefPtr<ResourceTimingInfo> info = ResourceTimingInfo::create( | 315 RefPtr<ResourceTimingInfo> info = ResourceTimingInfo::create( |
316 request.options().initiatorInfo.name, monotonicallyIncreasingTime(), | 316 request.options().initiatorInfo.name, monotonicallyIncreasingTime(), |
317 resource->getType() == Resource::MainResource); | 317 resource->getType() == Resource::MainResource); |
318 populateTimingInfo(info.get(), resource); | 318 populateTimingInfo(info.get(), resource); |
319 info->clearLoadTimings(); | 319 info->clearLoadTimings(); |
320 info->setLoadFinishTime(info->initialTime()); | 320 info->setLoadFinishTime(info->initialTime()); |
321 m_scheduledResourceTimingReports.push_back(info.release()); | 321 m_scheduledResourceTimingReports.push_back(info.release()); |
322 if (!m_resourceTimingReportTimer.isActive()) | 322 if (!m_resourceTimingReportTimer.isActive()) |
323 m_resourceTimingReportTimer.startOneShot(0, BLINK_FROM_HERE); | 323 m_resourceTimingReportTimer.startOneShot(0, BLINK_FROM_HERE); |
324 } | 324 } |
325 | 325 |
326 if (m_validatedURLs.size() >= kMaxValidatedURLsSize) { | 326 if (m_validatedURLs.size() >= kMaxValidatedURLsSize) { |
327 m_validatedURLs.clear(); | 327 m_validatedURLs.clear(); |
328 } | 328 } |
329 m_validatedURLs.insert(request.resourceRequest().url()); | 329 m_validatedURLs.insert(request.resourceRequest().url()); |
330 } | 330 } |
331 | 331 |
332 void ResourceFetcher::didLoadResourceFromMemoryCache( | |
333 unsigned long identifier, | |
334 Resource* resource, | |
335 const FetchRequest& request) { | |
Nate Chapin
2017/03/22 19:02:02
Nit: take const ResourceRequest& instead of const
kinuko
2017/03/24 13:51:51
Done.
| |
336 context().dispatchDidLoadResourceFromMemoryCache( | |
337 identifier, request.resourceRequest(), resource->response()); | |
Nate Chapin
2017/03/22 19:02:02
We're sending a different ResoruceRequest for disp
kinuko
2017/03/24 13:51:51
Done.
| |
338 { | |
339 // dispatchWillSendRequest can modify resourceRequest, while we don't | |
340 // really use the modified request here. | |
341 // TODO(https://crbug.com/632580): Avoid allowing dispatchWillSendRequest | |
342 // to modify requests. | |
343 ResourceRequest resourceRequest(resource->url()); | |
344 resourceRequest.setFrameType(request.resourceRequest().frameType()); | |
345 resourceRequest.setRequestContext( | |
346 request.resourceRequest().requestContext()); | |
347 context().dispatchWillSendRequest(identifier, resourceRequest, | |
348 ResourceResponse() /* redirects */, | |
349 resource->options().initiatorInfo); | |
350 } | |
351 context().dispatchDidReceiveResponse( | |
352 identifier, resource->response(), request.resourceRequest().frameType(), | |
353 request.resourceRequest().requestContext(), resource, | |
354 ResourceLoadStartType::kFromMemoryCache); | |
355 | |
356 if (resource->encodedSize() > 0) | |
357 context().dispatchDidReceiveData(identifier, 0, resource->encodedSize()); | |
358 | |
359 context().dispatchDidFinishLoading(identifier, 0, 0, | |
360 resource->response().decodedBodyLength()); | |
361 } | |
362 | |
332 static std::unique_ptr<TracedValue> urlForTraceEvent(const KURL& url) { | 363 static std::unique_ptr<TracedValue> urlForTraceEvent(const KURL& url) { |
333 std::unique_ptr<TracedValue> value = TracedValue::create(); | 364 std::unique_ptr<TracedValue> value = TracedValue::create(); |
334 value->setString("url", url.getString()); | 365 value->setString("url", url.getString()); |
335 return value; | 366 return value; |
336 } | 367 } |
337 | 368 |
338 Resource* ResourceFetcher::resourceForStaticData( | 369 Resource* ResourceFetcher::resourceForStaticData( |
339 const FetchRequest& request, | 370 const FetchRequest& request, |
340 const ResourceFactory& factory, | 371 const ResourceFactory& factory, |
341 const SubstituteData& substituteData) { | 372 const SubstituteData& substituteData) { |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
601 // and then another reference to the image is parsed (which would be at a | 632 // and then another reference to the image is parsed (which would be at a |
602 // lower priority). | 633 // lower priority). |
603 if (resourceRequest.priority() > resource->resourceRequest().priority()) | 634 if (resourceRequest.priority() > resource->resourceRequest().priority()) |
604 resource->didChangePriority(resourceRequest.priority(), 0); | 635 resource->didChangePriority(resourceRequest.priority(), 0); |
605 // TODO(yoav): I'd expect the stated scenario to not go here, as its policy | 636 // TODO(yoav): I'd expect the stated scenario to not go here, as its policy |
606 // would be Use. | 637 // would be Use. |
607 } | 638 } |
608 | 639 |
609 // If only the fragment identifiers differ, it is the same resource. | 640 // If only the fragment identifiers differ, it is the same resource. |
610 DCHECK(equalIgnoringFragmentIdentifier(resource->url(), request.url())); | 641 DCHECK(equalIgnoringFragmentIdentifier(resource->url(), request.url())); |
611 requestLoadStarted( | 642 requestLoadStarted(identifier, resource, request, |
612 identifier, resource, request, | 643 policy == Use ? ResourceLoadStartType::kFromMemoryCache |
613 policy == Use ? ResourceLoadingFromCache : ResourceLoadingFromNetwork, | 644 : ResourceLoadStartType::kNotFromMemoryCache, |
614 isStaticData); | 645 isStaticData); |
615 m_documentResources.set( | 646 m_documentResources.set( |
616 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), resource); | 647 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), resource); |
617 | 648 |
618 // Returns with an existing resource if the resource does not need to start | 649 // Returns with an existing resource if the resource does not need to start |
619 // loading immediately. If revalidation policy was determined as |Revalidate|, | 650 // loading immediately. If revalidation policy was determined as |Revalidate|, |
620 // the resource was already initialized for the revalidation here, but won't | 651 // the resource was already initialized for the revalidation here, but won't |
621 // start loading. | 652 // start loading. |
622 if (!resourceNeedsLoad(resource, request, policy)) | 653 if (!resourceNeedsLoad(resource, request, policy)) |
623 return resource; | 654 return resource; |
624 | 655 |
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1495 if (cachedResource(url)) | 1526 if (cachedResource(url)) |
1496 return; | 1527 return; |
1497 ResourceRequest resourceRequest(url); | 1528 ResourceRequest resourceRequest(url); |
1498 resourceRequest.setRequestContext(requestContext); | 1529 resourceRequest.setRequestContext(requestContext); |
1499 FetchRequest request(resourceRequest, initiatorName, resource->options()); | 1530 FetchRequest request(resourceRequest, initiatorName, resource->options()); |
1500 context().canRequest(resource->getType(), resource->lastResourceRequest(), | 1531 context().canRequest(resource->getType(), resource->lastResourceRequest(), |
1501 resource->lastResourceRequest().url(), request.options(), | 1532 resource->lastResourceRequest().url(), request.options(), |
1502 SecurityViolationReportingPolicy::Report, | 1533 SecurityViolationReportingPolicy::Report, |
1503 request.getOriginRestriction()); | 1534 request.getOriginRestriction()); |
1504 requestLoadStarted(resource->identifier(), resource, request, | 1535 requestLoadStarted(resource->identifier(), resource, request, |
1505 ResourceLoadingFromCache); | 1536 ResourceLoadStartType::kFromMemoryCache); |
1506 } | 1537 } |
1507 | 1538 |
1508 ResourceFetcher::DeadResourceStatsRecorder::DeadResourceStatsRecorder() | 1539 ResourceFetcher::DeadResourceStatsRecorder::DeadResourceStatsRecorder() |
1509 : m_useCount(0), m_revalidateCount(0), m_loadCount(0) {} | 1540 : m_useCount(0), m_revalidateCount(0), m_loadCount(0) {} |
1510 | 1541 |
1511 ResourceFetcher::DeadResourceStatsRecorder::~DeadResourceStatsRecorder() { | 1542 ResourceFetcher::DeadResourceStatsRecorder::~DeadResourceStatsRecorder() { |
1512 DEFINE_THREAD_SAFE_STATIC_LOCAL( | 1543 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
1513 CustomCountHistogram, hitCountHistogram, | 1544 CustomCountHistogram, hitCountHistogram, |
1514 new CustomCountHistogram("WebCore.ResourceFetcher.HitCount", 0, 1000, | 1545 new CustomCountHistogram("WebCore.ResourceFetcher.HitCount", 0, 1000, |
1515 50)); | 1546 50)); |
(...skipping 30 matching lines...) Expand all Loading... | |
1546 visitor->trace(m_context); | 1577 visitor->trace(m_context); |
1547 visitor->trace(m_archive); | 1578 visitor->trace(m_archive); |
1548 visitor->trace(m_loaders); | 1579 visitor->trace(m_loaders); |
1549 visitor->trace(m_nonBlockingLoaders); | 1580 visitor->trace(m_nonBlockingLoaders); |
1550 visitor->trace(m_documentResources); | 1581 visitor->trace(m_documentResources); |
1551 visitor->trace(m_preloads); | 1582 visitor->trace(m_preloads); |
1552 visitor->trace(m_resourceTimingInfoMap); | 1583 visitor->trace(m_resourceTimingInfoMap); |
1553 } | 1584 } |
1554 | 1585 |
1555 } // namespace blink | 1586 } // namespace blink |
OLD | NEW |