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

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

Issue 2845513002: [WIP] Add Resource::IsShareable
Patch Set: fix Created 3 years, 7 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 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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 resource->SetStatus(ResourceStatus::kPending); 435 resource->SetStatus(ResourceStatus::kPending);
436 resource->NotifyStartLoad(); 436 resource->NotifyStartLoad();
437 resource->ResponseReceived(response, nullptr); 437 resource->ResponseReceived(response, nullptr);
438 resource->SetDataBufferingPolicy(kBufferData); 438 resource->SetDataBufferingPolicy(kBufferData);
439 if (data->size()) 439 if (data->size())
440 resource->SetResourceBuffer(data); 440 resource->SetResourceBuffer(data);
441 resource->SetIdentifier(CreateUniqueIdentifier()); 441 resource->SetIdentifier(CreateUniqueIdentifier());
442 resource->SetCacheIdentifier(cache_identifier); 442 resource->SetCacheIdentifier(cache_identifier);
443 resource->Finish(); 443 resource->Finish();
444 444
445 if (!substitute_data.IsValid()) 445 if (!substitute_data.IsValid() && resource->IsShareable())
446 GetMemoryCache()->Add(resource); 446 GetMemoryCache()->Add(resource);
447 447
448 return resource; 448 return resource;
449 } 449 }
450 450
451 Resource* ResourceFetcher::ResourceForBlockedRequest( 451 Resource* ResourceFetcher::ResourceForBlockedRequest(
452 const FetchParameters& params, 452 const FetchParameters& params,
453 const ResourceFactory& factory, 453 const ResourceFactory& factory,
454 ResourceRequestBlockedReason blocked_reason) { 454 ResourceRequestBlockedReason blocked_reason) {
455 Resource* resource = factory.Create(params.GetResourceRequest(), 455 Resource* resource = factory.Create(params.GetResourceRequest(),
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 << params.GetResourceRequest().Url().ElidedString(); 790 << params.GetResourceRequest().Url().ElidedString();
791 791
792 Resource* resource = 792 Resource* resource =
793 factory.Create(params.GetResourceRequest(), params.Options(), charset); 793 factory.Create(params.GetResourceRequest(), params.Options(), charset);
794 resource->SetLinkPreload(params.IsLinkPreload()); 794 resource->SetLinkPreload(params.IsLinkPreload());
795 if (params.IsSpeculativePreload()) { 795 if (params.IsSpeculativePreload()) {
796 resource->SetPreloadDiscoveryTime(params.PreloadDiscoveryTime()); 796 resource->SetPreloadDiscoveryTime(params.PreloadDiscoveryTime());
797 } 797 }
798 resource->SetCacheIdentifier(cache_identifier); 798 resource->SetCacheIdentifier(cache_identifier);
799 799
800 // - Don't add main resource to cache to prevent reuse. 800 if (resource->IsShareable())
801 // - Don't add the resource if its body will not be stored.
802 if (IsMainThread() && factory.GetType() != Resource::kMainResource &&
803 params.Options().data_buffering_policy != kDoNotBufferData) {
804 GetMemoryCache()->Add(resource); 801 GetMemoryCache()->Add(resource);
805 }
806 return resource; 802 return resource;
807 } 803 }
808 804
809 void ResourceFetcher::StorePerformanceTimingInitiatorInformation( 805 void ResourceFetcher::StorePerformanceTimingInitiatorInformation(
810 Resource* resource) { 806 Resource* resource) {
811 const AtomicString& fetch_initiator = resource->Options().initiator_info.name; 807 const AtomicString& fetch_initiator = resource->Options().initiator_info.name;
812 if (fetch_initiator == FetchInitiatorTypeNames::internal) 808 if (fetch_initiator == FetchInitiatorTypeNames::internal)
813 return; 809 return;
814 810
815 bool is_main_resource = resource->GetType() == Resource::kMainResource; 811 bool is_main_resource = resource->GetType() == Resource::kMainResource;
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after
1659 visitor->Trace(archive_); 1655 visitor->Trace(archive_);
1660 visitor->Trace(loaders_); 1656 visitor->Trace(loaders_);
1661 visitor->Trace(non_blocking_loaders_); 1657 visitor->Trace(non_blocking_loaders_);
1662 visitor->Trace(document_resources_); 1658 visitor->Trace(document_resources_);
1663 visitor->Trace(preloads_); 1659 visitor->Trace(preloads_);
1664 visitor->Trace(matched_preloads_); 1660 visitor->Trace(matched_preloads_);
1665 visitor->Trace(resource_timing_info_map_); 1661 visitor->Trace(resource_timing_info_map_);
1666 } 1662 }
1667 1663
1668 } // namespace blink 1664 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698