| 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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 return policy != Use || resource->stillNeedsLoad(); | 294 return policy != Use || resource->stillNeedsLoad(); |
| 295 } | 295 } |
| 296 | 296 |
| 297 // Limit the number of URLs in m_validatedURLs to avoid memory bloat. | 297 // Limit the number of URLs in m_validatedURLs to avoid memory bloat. |
| 298 // http://crbug.com/52411 | 298 // http://crbug.com/52411 |
| 299 static const int kMaxValidatedURLsSize = 10000; | 299 static const int kMaxValidatedURLsSize = 10000; |
| 300 | 300 |
| 301 void ResourceFetcher::requestLoadStarted(unsigned long identifier, | 301 void ResourceFetcher::requestLoadStarted(unsigned long identifier, |
| 302 Resource* resource, | 302 Resource* resource, |
| 303 const FetchRequest& request, | 303 const FetchRequest& request, |
| 304 ResourceLoadStartType type, | 304 RevalidationPolicy policy, |
| 305 bool isStaticData) { | 305 bool isStaticData) { |
| 306 if (type == ResourceLoadingFromCache && | 306 if (policy == Use && resource->getStatus() == ResourceStatus::Cached && |
| 307 resource->getStatus() == ResourceStatus::Cached && | |
| 308 !m_validatedURLs.contains(resource->url())) { | 307 !m_validatedURLs.contains(resource->url())) { |
| 309 context().dispatchDidLoadResourceFromMemoryCache( | 308 // Loaded from MemoryCache. |
| 310 identifier, resource, request.resourceRequest().frameType(), | 309 didLoadResourceFromMemoryCache(identifier, resource, |
| 311 request.resourceRequest().requestContext()); | 310 request.resourceRequest()); |
| 312 } | 311 } |
| 313 | 312 |
| 314 if (isStaticData) | 313 if (isStaticData) |
| 315 return; | 314 return; |
| 316 | 315 |
| 317 if (type == ResourceLoadingFromCache && !resource->stillNeedsLoad() && | 316 if (policy == Use && !resource->stillNeedsLoad() && |
| 318 !m_validatedURLs.contains(request.resourceRequest().url())) { | 317 !m_validatedURLs.contains(request.resourceRequest().url())) { |
| 319 // Resources loaded from memory cache should be reported the first time | 318 // Resources loaded from memory cache should be reported the first time |
| 320 // they're used. | 319 // they're used. |
| 321 RefPtr<ResourceTimingInfo> info = ResourceTimingInfo::create( | 320 RefPtr<ResourceTimingInfo> info = ResourceTimingInfo::create( |
| 322 request.options().initiatorInfo.name, monotonicallyIncreasingTime(), | 321 request.options().initiatorInfo.name, monotonicallyIncreasingTime(), |
| 323 resource->getType() == Resource::MainResource); | 322 resource->getType() == Resource::MainResource); |
| 324 populateTimingInfo(info.get(), resource); | 323 populateTimingInfo(info.get(), resource); |
| 325 info->clearLoadTimings(); | 324 info->clearLoadTimings(); |
| 326 info->setLoadFinishTime(info->initialTime()); | 325 info->setLoadFinishTime(info->initialTime()); |
| 327 m_scheduledResourceTimingReports.push_back(info.release()); | 326 m_scheduledResourceTimingReports.push_back(info.release()); |
| 328 if (!m_resourceTimingReportTimer.isActive()) | 327 if (!m_resourceTimingReportTimer.isActive()) |
| 329 m_resourceTimingReportTimer.startOneShot(0, BLINK_FROM_HERE); | 328 m_resourceTimingReportTimer.startOneShot(0, BLINK_FROM_HERE); |
| 330 } | 329 } |
| 331 | 330 |
| 332 if (m_validatedURLs.size() >= kMaxValidatedURLsSize) { | 331 if (m_validatedURLs.size() >= kMaxValidatedURLsSize) { |
| 333 m_validatedURLs.clear(); | 332 m_validatedURLs.clear(); |
| 334 } | 333 } |
| 335 m_validatedURLs.insert(request.resourceRequest().url()); | 334 m_validatedURLs.insert(request.resourceRequest().url()); |
| 336 } | 335 } |
| 337 | 336 |
| 337 void ResourceFetcher::didLoadResourceFromMemoryCache( |
| 338 unsigned long identifier, |
| 339 Resource* resource, |
| 340 const ResourceRequest& originalResourceRequest) { |
| 341 ResourceRequest resourceRequest(resource->url()); |
| 342 resourceRequest.setFrameType(originalResourceRequest.frameType()); |
| 343 resourceRequest.setRequestContext(originalResourceRequest.requestContext()); |
| 344 context().dispatchDidLoadResourceFromMemoryCache(identifier, resourceRequest, |
| 345 resource->response()); |
| 346 context().dispatchWillSendRequest(identifier, resourceRequest, |
| 347 ResourceResponse() /* redirects */, |
| 348 resource->options().initiatorInfo); |
| 349 context().dispatchDidReceiveResponse( |
| 350 identifier, resource->response(), resourceRequest.frameType(), |
| 351 resourceRequest.requestContext(), resource, |
| 352 FetchContext::ResourceResponseType::kFromMemoryCache); |
| 353 |
| 354 if (resource->encodedSize() > 0) |
| 355 context().dispatchDidReceiveData(identifier, 0, resource->encodedSize()); |
| 356 |
| 357 context().dispatchDidFinishLoading(identifier, 0, 0, |
| 358 resource->response().decodedBodyLength()); |
| 359 } |
| 360 |
| 338 static std::unique_ptr<TracedValue> urlForTraceEvent(const KURL& url) { | 361 static std::unique_ptr<TracedValue> urlForTraceEvent(const KURL& url) { |
| 339 std::unique_ptr<TracedValue> value = TracedValue::create(); | 362 std::unique_ptr<TracedValue> value = TracedValue::create(); |
| 340 value->setString("url", url.getString()); | 363 value->setString("url", url.getString()); |
| 341 return value; | 364 return value; |
| 342 } | 365 } |
| 343 | 366 |
| 344 Resource* ResourceFetcher::resourceForStaticData( | 367 Resource* ResourceFetcher::resourceForStaticData( |
| 345 const FetchRequest& request, | 368 const FetchRequest& request, |
| 346 const ResourceFactory& factory, | 369 const ResourceFactory& factory, |
| 347 const SubstituteData& substituteData) { | 370 const SubstituteData& substituteData) { |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 // and then another reference to the image is parsed (which would be at a | 634 // and then another reference to the image is parsed (which would be at a |
| 612 // lower priority). | 635 // lower priority). |
| 613 if (resourceRequest.priority() > resource->resourceRequest().priority()) | 636 if (resourceRequest.priority() > resource->resourceRequest().priority()) |
| 614 resource->didChangePriority(resourceRequest.priority(), 0); | 637 resource->didChangePriority(resourceRequest.priority(), 0); |
| 615 // TODO(yoav): I'd expect the stated scenario to not go here, as its policy | 638 // TODO(yoav): I'd expect the stated scenario to not go here, as its policy |
| 616 // would be Use. | 639 // would be Use. |
| 617 } | 640 } |
| 618 | 641 |
| 619 // If only the fragment identifiers differ, it is the same resource. | 642 // If only the fragment identifiers differ, it is the same resource. |
| 620 DCHECK(equalIgnoringFragmentIdentifier(resource->url(), request.url())); | 643 DCHECK(equalIgnoringFragmentIdentifier(resource->url(), request.url())); |
| 621 requestLoadStarted( | 644 requestLoadStarted(identifier, resource, request, policy, isStaticData); |
| 622 identifier, resource, request, | |
| 623 policy == Use ? ResourceLoadingFromCache : ResourceLoadingFromNetwork, | |
| 624 isStaticData); | |
| 625 m_documentResources.set( | 645 m_documentResources.set( |
| 626 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), resource); | 646 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), resource); |
| 627 | 647 |
| 628 // Returns with an existing resource if the resource does not need to start | 648 // Returns with an existing resource if the resource does not need to start |
| 629 // loading immediately. If revalidation policy was determined as |Revalidate|, | 649 // loading immediately. If revalidation policy was determined as |Revalidate|, |
| 630 // the resource was already initialized for the revalidation here, but won't | 650 // the resource was already initialized for the revalidation here, but won't |
| 631 // start loading. | 651 // start loading. |
| 632 if (!resourceNeedsLoad(resource, request, policy)) | 652 if (!resourceNeedsLoad(resource, request, policy)) |
| 633 return resource; | 653 return resource; |
| 634 | 654 |
| (...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1494 const AtomicString& initiatorName) { | 1514 const AtomicString& initiatorName) { |
| 1495 if (cachedResource(url)) | 1515 if (cachedResource(url)) |
| 1496 return; | 1516 return; |
| 1497 ResourceRequest resourceRequest(url); | 1517 ResourceRequest resourceRequest(url); |
| 1498 resourceRequest.setRequestContext(requestContext); | 1518 resourceRequest.setRequestContext(requestContext); |
| 1499 FetchRequest request(resourceRequest, initiatorName, resource->options()); | 1519 FetchRequest request(resourceRequest, initiatorName, resource->options()); |
| 1500 context().canRequest(resource->getType(), resource->lastResourceRequest(), | 1520 context().canRequest(resource->getType(), resource->lastResourceRequest(), |
| 1501 resource->lastResourceRequest().url(), request.options(), | 1521 resource->lastResourceRequest().url(), request.options(), |
| 1502 SecurityViolationReportingPolicy::Report, | 1522 SecurityViolationReportingPolicy::Report, |
| 1503 request.getOriginRestriction()); | 1523 request.getOriginRestriction()); |
| 1504 requestLoadStarted(resource->identifier(), resource, request, | 1524 requestLoadStarted(resource->identifier(), resource, request, Use); |
| 1505 ResourceLoadingFromCache); | |
| 1506 } | 1525 } |
| 1507 | 1526 |
| 1508 ResourceFetcher::DeadResourceStatsRecorder::DeadResourceStatsRecorder() | 1527 ResourceFetcher::DeadResourceStatsRecorder::DeadResourceStatsRecorder() |
| 1509 : m_useCount(0), m_revalidateCount(0), m_loadCount(0) {} | 1528 : m_useCount(0), m_revalidateCount(0), m_loadCount(0) {} |
| 1510 | 1529 |
| 1511 ResourceFetcher::DeadResourceStatsRecorder::~DeadResourceStatsRecorder() { | 1530 ResourceFetcher::DeadResourceStatsRecorder::~DeadResourceStatsRecorder() { |
| 1512 DEFINE_THREAD_SAFE_STATIC_LOCAL( | 1531 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
| 1513 CustomCountHistogram, hitCountHistogram, | 1532 CustomCountHistogram, hitCountHistogram, |
| 1514 new CustomCountHistogram("WebCore.ResourceFetcher.HitCount", 0, 1000, | 1533 new CustomCountHistogram("WebCore.ResourceFetcher.HitCount", 0, 1000, |
| 1515 50)); | 1534 50)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1546 visitor->trace(m_context); | 1565 visitor->trace(m_context); |
| 1547 visitor->trace(m_archive); | 1566 visitor->trace(m_archive); |
| 1548 visitor->trace(m_loaders); | 1567 visitor->trace(m_loaders); |
| 1549 visitor->trace(m_nonBlockingLoaders); | 1568 visitor->trace(m_nonBlockingLoaders); |
| 1550 visitor->trace(m_documentResources); | 1569 visitor->trace(m_documentResources); |
| 1551 visitor->trace(m_preloads); | 1570 visitor->trace(m_preloads); |
| 1552 visitor->trace(m_resourceTimingInfoMap); | 1571 visitor->trace(m_resourceTimingInfoMap); |
| 1553 } | 1572 } |
| 1554 | 1573 |
| 1555 } // namespace blink | 1574 } // namespace blink |
| OLD | NEW |