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

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

Issue 1237983003: Revalidate using the same Resource, attempt #2 (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 5 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 | Annotate | Revision Log
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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 295
296 const RevalidationPolicy policy = determineRevalidationPolicy(factory.type() , request, resource.get()); 296 const RevalidationPolicy policy = determineRevalidationPolicy(factory.type() , request, resource.get());
297 switch (policy) { 297 switch (policy) {
298 case Reload: 298 case Reload:
299 memoryCache()->remove(resource.get()); 299 memoryCache()->remove(resource.get());
300 // Fall through 300 // Fall through
301 case Load: 301 case Load:
302 resource = createResourceForLoading(request, request.charset(), factory) ; 302 resource = createResourceForLoading(request, request.charset(), factory) ;
303 break; 303 break;
304 case Revalidate: 304 case Revalidate:
305 resource = createResourceForRevalidation(request, resource.get(), factor y); 305 initializeRevalidation(request, resource.get());
306 break; 306 break;
307 case Use: 307 case Use:
308 memoryCache()->updateForAccess(resource.get()); 308 memoryCache()->updateForAccess(resource.get());
309 break; 309 break;
310 } 310 }
311 311
312 if (!resource) 312 if (!resource)
313 return nullptr; 313 return nullptr;
314 if (resource->type() != factory.type()) { 314 if (resource->type() != factory.type()) {
315 ASSERT(request.forPreload()); 315 ASSERT(request.forPreload());
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 if (request.cachePolicy() == UseProtocolCachePolicy) 396 if (request.cachePolicy() == UseProtocolCachePolicy)
397 request.setCachePolicy(context().resourceRequestCachePolicy(request, typ e)); 397 request.setCachePolicy(context().resourceRequestCachePolicy(request, typ e));
398 if (request.requestContext() == WebURLRequest::RequestContextUnspecified) 398 if (request.requestContext() == WebURLRequest::RequestContextUnspecified)
399 determineRequestContext(request, type); 399 determineRequestContext(request, type);
400 if (type == Resource::LinkPrefetch || type == Resource::LinkSubresource) 400 if (type == Resource::LinkPrefetch || type == Resource::LinkSubresource)
401 request.setHTTPHeaderField("Purpose", "prefetch"); 401 request.setHTTPHeaderField("Purpose", "prefetch");
402 402
403 context().addAdditionalRequestHeaders(request, (type == Resource::MainResour ce) ? FetchMainResource : FetchSubresource); 403 context().addAdditionalRequestHeaders(request, (type == Resource::MainResour ce) ? FetchMainResource : FetchSubresource);
404 } 404 }
405 405
406 ResourcePtr<Resource> ResourceFetcher::createResourceForRevalidation(const Fetch Request& request, Resource* resource, const ResourceFactory& factory) 406 void ResourceFetcher::initializeRevalidation(const FetchRequest& request, Resour ce* resource)
407 { 407 {
408 ASSERT(resource); 408 ASSERT(resource);
409 ASSERT(memoryCache()->contains(resource)); 409 ASSERT(memoryCache()->contains(resource));
410 ASSERT(resource->isLoaded()); 410 ASSERT(resource->isLoaded());
411 ASSERT(resource->canUseCacheValidator()); 411 ASSERT(resource->canUseCacheValidator());
412 ASSERT(!resource->resourceToRevalidate()); 412 ASSERT(!resource->isCacheValidator());
413 ASSERT(!context().isControlledByServiceWorker()); 413 ASSERT(!context().isControlledByServiceWorker());
414 414
415 ResourceRequest revalidatingRequest(resource->resourceRequest()); 415 ResourceRequest revalidatingRequest(resource->resourceRequest());
416 revalidatingRequest.clearHTTPReferrer(); 416 revalidatingRequest.clearHTTPReferrer();
417 addAdditionalRequestHeaders(revalidatingRequest, resource->type()); 417 addAdditionalRequestHeaders(revalidatingRequest, resource->type());
418 418
419 const AtomicString& lastModified = resource->response().httpHeaderField("Las t-Modified"); 419 const AtomicString& lastModified = resource->response().httpHeaderField("Las t-Modified");
420 const AtomicString& eTag = resource->response().httpHeaderField("ETag"); 420 const AtomicString& eTag = resource->response().httpHeaderField("ETag");
421 if (!lastModified.isEmpty() || !eTag.isEmpty()) { 421 if (!lastModified.isEmpty() || !eTag.isEmpty()) {
422 ASSERT(context().cachePolicy() != CachePolicyReload); 422 ASSERT(context().cachePolicy() != CachePolicyReload);
423 if (context().cachePolicy() == CachePolicyRevalidate) 423 if (context().cachePolicy() == CachePolicyRevalidate)
424 revalidatingRequest.setHTTPHeaderField("Cache-Control", "max-age=0") ; 424 revalidatingRequest.setHTTPHeaderField("Cache-Control", "max-age=0") ;
425 } 425 }
426 if (!lastModified.isEmpty()) 426 if (!lastModified.isEmpty())
427 revalidatingRequest.setHTTPHeaderField("If-Modified-Since", lastModified ); 427 revalidatingRequest.setHTTPHeaderField("If-Modified-Since", lastModified );
428 if (!eTag.isEmpty()) 428 if (!eTag.isEmpty())
429 revalidatingRequest.setHTTPHeaderField("If-None-Match", eTag); 429 revalidatingRequest.setHTTPHeaderField("If-None-Match", eTag);
430 430
431 double stalenessLifetime = resource->stalenessLifetime(); 431 double stalenessLifetime = resource->stalenessLifetime();
432 if (std::isfinite(stalenessLifetime) && stalenessLifetime > 0) { 432 if (std::isfinite(stalenessLifetime) && stalenessLifetime > 0) {
433 revalidatingRequest.setHTTPHeaderField("Resource-Freshness", AtomicStrin g(String::format("max-age=%.0lf,stale-while-revalidate=%.0lf,age=%.0lf", resourc e->freshnessLifetime(), stalenessLifetime, resource->currentAge()))); 433 revalidatingRequest.setHTTPHeaderField("Resource-Freshness", AtomicStrin g(String::format("max-age=%.0lf,stale-while-revalidate=%.0lf,age=%.0lf", resourc e->freshnessLifetime(), stalenessLifetime, resource->currentAge())));
434 } 434 }
435 435
436 ResourcePtr<Resource> newResource = factory.create(revalidatingRequest, reso urce->encoding()); 436 resource->setRevalidatingRequest(revalidatingRequest);
437 WTF_LOG(ResourceLoading, "Resource %p created to revalidate %p", newResource .get(), resource);
438
439 newResource->setResourceToRevalidate(resource);
440 newResource->setCacheIdentifier(resource->cacheIdentifier());
441
442 memoryCache()->remove(resource);
443 memoryCache()->add(newResource.get());
444 return newResource;
445 } 437 }
446 438
447 ResourcePtr<Resource> ResourceFetcher::createResourceForLoading(FetchRequest& re quest, const String& charset, const ResourceFactory& factory) 439 ResourcePtr<Resource> ResourceFetcher::createResourceForLoading(FetchRequest& re quest, const String& charset, const ResourceFactory& factory)
448 { 440 {
449 const String cacheIdentifier = getCacheIdentifier(); 441 const String cacheIdentifier = getCacheIdentifier();
450 ASSERT(!memoryCache()->resourceForURL(request.resourceRequest().url(), cache Identifier)); 442 ASSERT(!memoryCache()->resourceForURL(request.resourceRequest().url(), cache Identifier));
451 443
452 WTF_LOG(ResourceLoading, "Loading Resource for '%s'.", request.resourceReque st().url().elidedString().latin1().data()); 444 WTF_LOG(ResourceLoading, "Loading Resource for '%s'.", request.resourceReque st().url().elidedString().latin1().data());
453 445
454 addAdditionalRequestHeaders(request.mutableResourceRequest(), factory.type() ); 446 addAdditionalRequestHeaders(request.mutableResourceRequest(), factory.type() );
455 ResourcePtr<Resource> resource = factory.create(request.resourceRequest(), c harset); 447 ResourcePtr<Resource> resource = factory.create(request.resourceRequest(), c harset);
456 resource->setCacheIdentifier(cacheIdentifier); 448 resource->setCacheIdentifier(cacheIdentifier);
457 449
458 memoryCache()->add(resource.get()); 450 memoryCache()->add(resource.get());
459 return resource; 451 return resource;
460 } 452 }
461 453
462 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource ) 454 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource )
463 { 455 {
464 if (resource->options().initiatorInfo.name == FetchInitiatorTypeNames::inter nal) 456 if (resource->options().initiatorInfo.name == FetchInitiatorTypeNames::inter nal)
465 return; 457 return;
466 458
467 OwnPtr<ResourceTimingInfo> info = ResourceTimingInfo::create(resource->optio ns().initiatorInfo.name, monotonicallyIncreasingTime(), resource->type() == Reso urce::MainResource); 459 OwnPtr<ResourceTimingInfo> info = ResourceTimingInfo::create(resource->optio ns().initiatorInfo.name, monotonicallyIncreasingTime(), resource->type() == Reso urce::MainResource);
468 460
469 if (resource->isCacheValidator()) { 461 if (resource->isCacheValidator()) {
470 const AtomicString& timingAllowOrigin = resource->resourceToRevalidate() ->response().httpHeaderField("Timing-Allow-Origin"); 462 const AtomicString& timingAllowOrigin = resource->response().httpHeaderF ield("Timing-Allow-Origin");
471 if (!timingAllowOrigin.isEmpty()) 463 if (!timingAllowOrigin.isEmpty())
472 info->setOriginalTimingAllowOrigin(timingAllowOrigin); 464 info->setOriginalTimingAllowOrigin(timingAllowOrigin);
473 } 465 }
474 466
475 if (resource->type() != Resource::MainResource || context().updateTimingInfo ForIFrameNavigation(info.get())) 467 if (resource->type() != Resource::MainResource || context().updateTimingInfo ForIFrameNavigation(info.get()))
476 m_resourceTimingInfoMap.add(resource, info.release()); 468 m_resourceTimingInfoMap.add(resource, info.release());
477 } 469 }
478 470
479 ResourceFetcher::RevalidationPolicy ResourceFetcher::determineRevalidationPolicy (Resource::Type type, const FetchRequest& fetchRequest, Resource* existingResour ce) const 471 ResourceFetcher::RevalidationPolicy ResourceFetcher::determineRevalidationPolicy (Resource::Type type, const FetchRequest& fetchRequest, Resource* existingResour ce) const
480 { 472 {
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 1044
1053 DEFINE_TRACE(ResourceFetcher) 1045 DEFINE_TRACE(ResourceFetcher)
1054 { 1046 {
1055 visitor->trace(m_context); 1047 visitor->trace(m_context);
1056 visitor->trace(m_archiveResourceCollection); 1048 visitor->trace(m_archiveResourceCollection);
1057 visitor->trace(m_loaders); 1049 visitor->trace(m_loaders);
1058 visitor->trace(m_nonBlockingLoaders); 1050 visitor->trace(m_nonBlockingLoaders);
1059 } 1051 }
1060 1052
1061 } 1053 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698