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

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

Issue 1269563003: Revert of Revalidate using the same Resource, attempt #2 (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 4 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
« no previous file with comments | « Source/core/fetch/ResourceFetcher.h ('k') | Source/core/fetch/ResourceLoader.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 initializeRevalidation(request, resource.get()); 305 resource = createResourceForRevalidation(request, resource.get(), factor y);
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 void ResourceFetcher::initializeRevalidation(const FetchRequest& request, Resour ce* resource) 406 ResourcePtr<Resource> ResourceFetcher::createResourceForRevalidation(const Fetch Request& request, Resource* resource, const ResourceFactory& factory)
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->isCacheValidator()); 412 ASSERT(!resource->resourceToRevalidate());
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 resource->setRevalidatingRequest(revalidatingRequest); 436 ResourcePtr<Resource> newResource = factory.create(revalidatingRequest, reso urce->encoding());
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;
437 } 445 }
438 446
439 ResourcePtr<Resource> ResourceFetcher::createResourceForLoading(FetchRequest& re quest, const String& charset, const ResourceFactory& factory) 447 ResourcePtr<Resource> ResourceFetcher::createResourceForLoading(FetchRequest& re quest, const String& charset, const ResourceFactory& factory)
440 { 448 {
441 const String cacheIdentifier = getCacheIdentifier(); 449 const String cacheIdentifier = getCacheIdentifier();
442 ASSERT(!memoryCache()->resourceForURL(request.resourceRequest().url(), cache Identifier)); 450 ASSERT(!memoryCache()->resourceForURL(request.resourceRequest().url(), cache Identifier));
443 451
444 WTF_LOG(ResourceLoading, "Loading Resource for '%s'.", request.resourceReque st().url().elidedString().latin1().data()); 452 WTF_LOG(ResourceLoading, "Loading Resource for '%s'.", request.resourceReque st().url().elidedString().latin1().data());
445 453
446 addAdditionalRequestHeaders(request.mutableResourceRequest(), factory.type() ); 454 addAdditionalRequestHeaders(request.mutableResourceRequest(), factory.type() );
447 ResourcePtr<Resource> resource = factory.create(request.resourceRequest(), c harset); 455 ResourcePtr<Resource> resource = factory.create(request.resourceRequest(), c harset);
448 resource->setCacheIdentifier(cacheIdentifier); 456 resource->setCacheIdentifier(cacheIdentifier);
449 457
450 memoryCache()->add(resource.get()); 458 memoryCache()->add(resource.get());
451 return resource; 459 return resource;
452 } 460 }
453 461
454 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource ) 462 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource )
455 { 463 {
456 if (resource->options().initiatorInfo.name == FetchInitiatorTypeNames::inter nal) 464 if (resource->options().initiatorInfo.name == FetchInitiatorTypeNames::inter nal)
457 return; 465 return;
458 466
459 OwnPtr<ResourceTimingInfo> info = ResourceTimingInfo::create(resource->optio ns().initiatorInfo.name, monotonicallyIncreasingTime(), resource->type() == Reso urce::MainResource); 467 OwnPtr<ResourceTimingInfo> info = ResourceTimingInfo::create(resource->optio ns().initiatorInfo.name, monotonicallyIncreasingTime(), resource->type() == Reso urce::MainResource);
460 468
461 if (resource->isCacheValidator()) { 469 if (resource->isCacheValidator()) {
462 const AtomicString& timingAllowOrigin = resource->response().httpHeaderF ield("Timing-Allow-Origin"); 470 const AtomicString& timingAllowOrigin = resource->resourceToRevalidate() ->response().httpHeaderField("Timing-Allow-Origin");
463 if (!timingAllowOrigin.isEmpty()) 471 if (!timingAllowOrigin.isEmpty())
464 info->setOriginalTimingAllowOrigin(timingAllowOrigin); 472 info->setOriginalTimingAllowOrigin(timingAllowOrigin);
465 } 473 }
466 474
467 if (resource->type() != Resource::MainResource || context().updateTimingInfo ForIFrameNavigation(info.get())) 475 if (resource->type() != Resource::MainResource || context().updateTimingInfo ForIFrameNavigation(info.get()))
468 m_resourceTimingInfoMap.add(resource, info.release()); 476 m_resourceTimingInfoMap.add(resource, info.release());
469 } 477 }
470 478
471 ResourceFetcher::RevalidationPolicy ResourceFetcher::determineRevalidationPolicy (Resource::Type type, const FetchRequest& fetchRequest, Resource* existingResour ce) const 479 ResourceFetcher::RevalidationPolicy ResourceFetcher::determineRevalidationPolicy (Resource::Type type, const FetchRequest& fetchRequest, Resource* existingResour ce) const
472 { 480 {
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 1052
1045 DEFINE_TRACE(ResourceFetcher) 1053 DEFINE_TRACE(ResourceFetcher)
1046 { 1054 {
1047 visitor->trace(m_context); 1055 visitor->trace(m_context);
1048 visitor->trace(m_archiveResourceCollection); 1056 visitor->trace(m_archiveResourceCollection);
1049 visitor->trace(m_loaders); 1057 visitor->trace(m_loaders);
1050 visitor->trace(m_nonBlockingLoaders); 1058 visitor->trace(m_nonBlockingLoaders);
1051 } 1059 }
1052 1060
1053 } 1061 }
OLDNEW
« no previous file with comments | « Source/core/fetch/ResourceFetcher.h ('k') | Source/core/fetch/ResourceLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698