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

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

Issue 1398523004: Revalidate using the same Resource, attempt #3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 369
370 const RevalidationPolicy policy = determineRevalidationPolicy(factory.type() , request, resource.get(), isStaticData); 370 const RevalidationPolicy policy = determineRevalidationPolicy(factory.type() , request, resource.get(), isStaticData);
371 switch (policy) { 371 switch (policy) {
372 case Reload: 372 case Reload:
373 memoryCache()->remove(resource.get()); 373 memoryCache()->remove(resource.get());
374 // Fall through 374 // Fall through
375 case Load: 375 case Load:
376 resource = createResourceForLoading(request, request.charset(), factory) ; 376 resource = createResourceForLoading(request, request.charset(), factory) ;
377 break; 377 break;
378 case Revalidate: 378 case Revalidate:
379 resource = createResourceForRevalidation(request, resource.get(), factor y); 379 initializeRevalidation(request, resource.get());
380 break; 380 break;
381 case Use: 381 case Use:
382 memoryCache()->updateForAccess(resource.get()); 382 memoryCache()->updateForAccess(resource.get());
383 break; 383 break;
384 } 384 }
385 385
386 if (!resource) 386 if (!resource)
387 return nullptr; 387 return nullptr;
388 if (resource->type() != factory.type()) { 388 if (resource->type() != factory.type()) {
389 ASSERT(request.forPreload()); 389 ASSERT(request.forPreload());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 if (request.cachePolicy() == UseProtocolCachePolicy) 468 if (request.cachePolicy() == UseProtocolCachePolicy)
469 request.setCachePolicy(context().resourceRequestCachePolicy(request, typ e)); 469 request.setCachePolicy(context().resourceRequestCachePolicy(request, typ e));
470 if (request.requestContext() == WebURLRequest::RequestContextUnspecified) 470 if (request.requestContext() == WebURLRequest::RequestContextUnspecified)
471 determineRequestContext(request, type); 471 determineRequestContext(request, type);
472 if (type == Resource::LinkPrefetch || type == Resource::LinkSubresource) 472 if (type == Resource::LinkPrefetch || type == Resource::LinkSubresource)
473 request.setHTTPHeaderField("Purpose", "prefetch"); 473 request.setHTTPHeaderField("Purpose", "prefetch");
474 474
475 context().addAdditionalRequestHeaders(request, (type == Resource::MainResour ce) ? FetchMainResource : FetchSubresource); 475 context().addAdditionalRequestHeaders(request, (type == Resource::MainResour ce) ? FetchMainResource : FetchSubresource);
476 } 476 }
477 477
478 ResourcePtr<Resource> ResourceFetcher::createResourceForRevalidation(const Fetch Request& request, Resource* resource, const ResourceFactory& factory) 478 void ResourceFetcher::initializeRevalidation(const FetchRequest& request, Resour ce* resource)
479 { 479 {
480 ASSERT(resource); 480 ASSERT(resource);
481 ASSERT(memoryCache()->contains(resource)); 481 ASSERT(memoryCache()->contains(resource));
482 ASSERT(resource->isLoaded()); 482 ASSERT(resource->isLoaded());
483 ASSERT(resource->canUseCacheValidator()); 483 ASSERT(resource->canUseCacheValidator());
484 ASSERT(!resource->resourceToRevalidate()); 484 ASSERT(!resource->isCacheValidator());
485 ASSERT(!context().isControlledByServiceWorker()); 485 ASSERT(!context().isControlledByServiceWorker());
486 486
487 ResourceRequest revalidatingRequest(resource->resourceRequest()); 487 ResourceRequest revalidatingRequest(resource->resourceRequest());
488 revalidatingRequest.clearHTTPReferrer(); 488 revalidatingRequest.clearHTTPReferrer();
489 initializeResourceRequest(revalidatingRequest, resource->type()); 489 initializeResourceRequest(revalidatingRequest, resource->type());
490 490
491 const AtomicString& lastModified = resource->response().httpHeaderField("Las t-Modified"); 491 const AtomicString& lastModified = resource->response().httpHeaderField("Las t-Modified");
492 const AtomicString& eTag = resource->response().httpHeaderField("ETag"); 492 const AtomicString& eTag = resource->response().httpHeaderField("ETag");
493 if (!lastModified.isEmpty() || !eTag.isEmpty()) { 493 if (!lastModified.isEmpty() || !eTag.isEmpty()) {
494 ASSERT(context().cachePolicy() != CachePolicyReload); 494 ASSERT(context().cachePolicy() != CachePolicyReload);
495 if (context().cachePolicy() == CachePolicyRevalidate) 495 if (context().cachePolicy() == CachePolicyRevalidate)
496 revalidatingRequest.setHTTPHeaderField("Cache-Control", "max-age=0") ; 496 revalidatingRequest.setHTTPHeaderField("Cache-Control", "max-age=0") ;
497 } 497 }
498 if (!lastModified.isEmpty()) 498 if (!lastModified.isEmpty())
499 revalidatingRequest.setHTTPHeaderField("If-Modified-Since", lastModified ); 499 revalidatingRequest.setHTTPHeaderField("If-Modified-Since", lastModified );
500 if (!eTag.isEmpty()) 500 if (!eTag.isEmpty())
501 revalidatingRequest.setHTTPHeaderField("If-None-Match", eTag); 501 revalidatingRequest.setHTTPHeaderField("If-None-Match", eTag);
502 502
503 double stalenessLifetime = resource->stalenessLifetime(); 503 double stalenessLifetime = resource->stalenessLifetime();
504 if (std::isfinite(stalenessLifetime) && stalenessLifetime > 0) { 504 if (std::isfinite(stalenessLifetime) && stalenessLifetime > 0) {
505 revalidatingRequest.setHTTPHeaderField("Resource-Freshness", AtomicStrin g(String::format("max-age=%.0lf,stale-while-revalidate=%.0lf,age=%.0lf", resourc e->freshnessLifetime(), stalenessLifetime, resource->currentAge()))); 505 revalidatingRequest.setHTTPHeaderField("Resource-Freshness", AtomicStrin g(String::format("max-age=%.0lf,stale-while-revalidate=%.0lf,age=%.0lf", resourc e->freshnessLifetime(), stalenessLifetime, resource->currentAge())));
506 } 506 }
507 507
508 ResourcePtr<Resource> newResource = factory.create(revalidatingRequest, reso urce->encoding()); 508 resource->setRevalidatingRequest(revalidatingRequest);
509 WTF_LOG(ResourceLoading, "Resource %p created to revalidate %p", newResource .get(), resource);
510
511 newResource->setResourceToRevalidate(resource);
512 newResource->setCacheIdentifier(resource->cacheIdentifier());
513
514 memoryCache()->remove(resource);
515 memoryCache()->add(newResource.get());
516 return newResource;
517 } 509 }
518 510
519 ResourcePtr<Resource> ResourceFetcher::createResourceForLoading(FetchRequest& re quest, const String& charset, const ResourceFactory& factory) 511 ResourcePtr<Resource> ResourceFetcher::createResourceForLoading(FetchRequest& re quest, const String& charset, const ResourceFactory& factory)
520 { 512 {
521 const String cacheIdentifier = getCacheIdentifier(); 513 const String cacheIdentifier = getCacheIdentifier();
522 ASSERT(!memoryCache()->resourceForURL(request.resourceRequest().url(), cache Identifier)); 514 ASSERT(!memoryCache()->resourceForURL(request.resourceRequest().url(), cache Identifier));
523 515
524 WTF_LOG(ResourceLoading, "Loading Resource for '%s'.", request.resourceReque st().url().elidedString().latin1().data()); 516 WTF_LOG(ResourceLoading, "Loading Resource for '%s'.", request.resourceReque st().url().elidedString().latin1().data());
525 517
526 initializeResourceRequest(request.mutableResourceRequest(), factory.type()); 518 initializeResourceRequest(request.mutableResourceRequest(), factory.type());
527 ResourcePtr<Resource> resource = factory.create(request.resourceRequest(), c harset); 519 ResourcePtr<Resource> resource = factory.create(request.resourceRequest(), c harset);
528 resource->setCacheIdentifier(cacheIdentifier); 520 resource->setCacheIdentifier(cacheIdentifier);
529 521
530 memoryCache()->add(resource.get()); 522 memoryCache()->add(resource.get());
531 return resource; 523 return resource;
532 } 524 }
533 525
534 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource ) 526 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource )
535 { 527 {
536 if (resource->options().initiatorInfo.name == FetchInitiatorTypeNames::inter nal) 528 if (resource->options().initiatorInfo.name == FetchInitiatorTypeNames::inter nal)
537 return; 529 return;
538 530
539 OwnPtr<ResourceTimingInfo> info = ResourceTimingInfo::create(resource->optio ns().initiatorInfo.name, monotonicallyIncreasingTime(), resource->type() == Reso urce::MainResource); 531 OwnPtr<ResourceTimingInfo> info = ResourceTimingInfo::create(resource->optio ns().initiatorInfo.name, monotonicallyIncreasingTime(), resource->type() == Reso urce::MainResource);
540 532
541 if (resource->isCacheValidator()) { 533 if (resource->isCacheValidator()) {
542 const AtomicString& timingAllowOrigin = resource->resourceToRevalidate() ->response().httpHeaderField("Timing-Allow-Origin"); 534 const AtomicString& timingAllowOrigin = resource->response().httpHeaderF ield("Timing-Allow-Origin");
543 if (!timingAllowOrigin.isEmpty()) 535 if (!timingAllowOrigin.isEmpty())
544 info->setOriginalTimingAllowOrigin(timingAllowOrigin); 536 info->setOriginalTimingAllowOrigin(timingAllowOrigin);
545 } 537 }
546 538
547 if (resource->type() != Resource::MainResource || context().updateTimingInfo ForIFrameNavigation(info.get())) 539 if (resource->type() != Resource::MainResource || context().updateTimingInfo ForIFrameNavigation(info.get()))
548 m_resourceTimingInfoMap.add(resource, info.release()); 540 m_resourceTimingInfoMap.add(resource, info.release());
549 } 541 }
550 542
551 ResourceFetcher::RevalidationPolicy ResourceFetcher::determineRevalidationPolicy (Resource::Type type, const FetchRequest& fetchRequest, Resource* existingResour ce, bool isStaticData) const 543 ResourceFetcher::RevalidationPolicy ResourceFetcher::determineRevalidationPolicy (Resource::Type type, const FetchRequest& fetchRequest, Resource* existingResour ce, bool isStaticData) const
552 { 544 {
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 visitor->trace(m_archiveResourceCollection); 1159 visitor->trace(m_archiveResourceCollection);
1168 visitor->trace(m_loaders); 1160 visitor->trace(m_loaders);
1169 visitor->trace(m_nonBlockingLoaders); 1161 visitor->trace(m_nonBlockingLoaders);
1170 #if ENABLE(OILPAN) 1162 #if ENABLE(OILPAN)
1171 visitor->trace(m_preloads); 1163 visitor->trace(m_preloads);
1172 visitor->trace(m_resourceTimingInfoMap); 1164 visitor->trace(m_resourceTimingInfoMap);
1173 #endif 1165 #endif
1174 } 1166 }
1175 1167
1176 } 1168 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/ResourceFetcher.h ('k') | third_party/WebKit/Source/core/fetch/ResourceLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698