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

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

Issue 1410313002: Revert of 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 initializeRevalidation(request, resource.get()); 379 resource = createResourceForRevalidation(request, resource.get(), factor y);
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 void ResourceFetcher::initializeRevalidation(const FetchRequest& request, Resour ce* resource) 478 ResourcePtr<Resource> ResourceFetcher::createResourceForRevalidation(const Fetch Request& request, Resource* resource, const ResourceFactory& factory)
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->isCacheValidator()); 484 ASSERT(!resource->resourceToRevalidate());
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 resource->setRevalidatingRequest(revalidatingRequest); 508 ResourcePtr<Resource> newResource = factory.create(revalidatingRequest, reso urce->encoding());
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;
509 } 517 }
510 518
511 ResourcePtr<Resource> ResourceFetcher::createResourceForLoading(FetchRequest& re quest, const String& charset, const ResourceFactory& factory) 519 ResourcePtr<Resource> ResourceFetcher::createResourceForLoading(FetchRequest& re quest, const String& charset, const ResourceFactory& factory)
512 { 520 {
513 const String cacheIdentifier = getCacheIdentifier(); 521 const String cacheIdentifier = getCacheIdentifier();
514 ASSERT(!memoryCache()->resourceForURL(request.resourceRequest().url(), cache Identifier)); 522 ASSERT(!memoryCache()->resourceForURL(request.resourceRequest().url(), cache Identifier));
515 523
516 WTF_LOG(ResourceLoading, "Loading Resource for '%s'.", request.resourceReque st().url().elidedString().latin1().data()); 524 WTF_LOG(ResourceLoading, "Loading Resource for '%s'.", request.resourceReque st().url().elidedString().latin1().data());
517 525
518 initializeResourceRequest(request.mutableResourceRequest(), factory.type()); 526 initializeResourceRequest(request.mutableResourceRequest(), factory.type());
519 ResourcePtr<Resource> resource = factory.create(request.resourceRequest(), c harset); 527 ResourcePtr<Resource> resource = factory.create(request.resourceRequest(), c harset);
520 resource->setCacheIdentifier(cacheIdentifier); 528 resource->setCacheIdentifier(cacheIdentifier);
521 529
522 memoryCache()->add(resource.get()); 530 memoryCache()->add(resource.get());
523 return resource; 531 return resource;
524 } 532 }
525 533
526 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource ) 534 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource )
527 { 535 {
528 if (resource->options().initiatorInfo.name == FetchInitiatorTypeNames::inter nal) 536 if (resource->options().initiatorInfo.name == FetchInitiatorTypeNames::inter nal)
529 return; 537 return;
530 538
531 OwnPtr<ResourceTimingInfo> info = ResourceTimingInfo::create(resource->optio ns().initiatorInfo.name, monotonicallyIncreasingTime(), resource->type() == Reso urce::MainResource); 539 OwnPtr<ResourceTimingInfo> info = ResourceTimingInfo::create(resource->optio ns().initiatorInfo.name, monotonicallyIncreasingTime(), resource->type() == Reso urce::MainResource);
532 540
533 if (resource->isCacheValidator()) { 541 if (resource->isCacheValidator()) {
534 const AtomicString& timingAllowOrigin = resource->response().httpHeaderF ield("Timing-Allow-Origin"); 542 const AtomicString& timingAllowOrigin = resource->resourceToRevalidate() ->response().httpHeaderField("Timing-Allow-Origin");
535 if (!timingAllowOrigin.isEmpty()) 543 if (!timingAllowOrigin.isEmpty())
536 info->setOriginalTimingAllowOrigin(timingAllowOrigin); 544 info->setOriginalTimingAllowOrigin(timingAllowOrigin);
537 } 545 }
538 546
539 if (resource->type() != Resource::MainResource || context().updateTimingInfo ForIFrameNavigation(info.get())) 547 if (resource->type() != Resource::MainResource || context().updateTimingInfo ForIFrameNavigation(info.get()))
540 m_resourceTimingInfoMap.add(resource, info.release()); 548 m_resourceTimingInfoMap.add(resource, info.release());
541 } 549 }
542 550
543 ResourceFetcher::RevalidationPolicy ResourceFetcher::determineRevalidationPolicy (Resource::Type type, const FetchRequest& fetchRequest, Resource* existingResour ce, bool isStaticData) const 551 ResourceFetcher::RevalidationPolicy ResourceFetcher::determineRevalidationPolicy (Resource::Type type, const FetchRequest& fetchRequest, Resource* existingResour ce, bool isStaticData) const
544 { 552 {
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 visitor->trace(m_archiveResourceCollection); 1167 visitor->trace(m_archiveResourceCollection);
1160 visitor->trace(m_loaders); 1168 visitor->trace(m_loaders);
1161 visitor->trace(m_nonBlockingLoaders); 1169 visitor->trace(m_nonBlockingLoaders);
1162 #if ENABLE(OILPAN) 1170 #if ENABLE(OILPAN)
1163 visitor->trace(m_preloads); 1171 visitor->trace(m_preloads);
1164 visitor->trace(m_resourceTimingInfoMap); 1172 visitor->trace(m_resourceTimingInfoMap);
1165 #endif 1173 #endif
1166 } 1174 }
1167 1175
1168 } 1176 }
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