| OLD | NEW |
| 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) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
rights reserved. | 4 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
rights reserved. |
| 5 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ | 5 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ |
| 6 | 6 |
| 7 This library is free software; you can redistribute it and/or | 7 This library is free software; you can redistribute it and/or |
| 8 modify it under the terms of the GNU Library General Public | 8 modify it under the terms of the GNU Library General Public |
| 9 License as published by the Free Software Foundation; either | 9 License as published by the Free Software Foundation; either |
| 10 version 2 of the License, or (at your option) any later version. | 10 version 2 of the License, or (at your option) any later version. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 // The ResourceFetcher provides a per-context interface to the MemoryCache | 60 // The ResourceFetcher provides a per-context interface to the MemoryCache |
| 61 // and enforces a bunch of security checks and rules for resource revalidation. | 61 // and enforces a bunch of security checks and rules for resource revalidation. |
| 62 // Its lifetime is roughly per-DocumentLoader, in that it is generally created | 62 // Its lifetime is roughly per-DocumentLoader, in that it is generally created |
| 63 // in the DocumentLoader constructor and loses its ability to generate network | 63 // in the DocumentLoader constructor and loses its ability to generate network |
| 64 // requests when the DocumentLoader is destroyed. Documents also hold a pointer | 64 // requests when the DocumentLoader is destroyed. Documents also hold a pointer |
| 65 // to ResourceFetcher for their lifetime (and will create one if they | 65 // to ResourceFetcher for their lifetime (and will create one if they |
| 66 // are initialized without a LocalFrame), so a Document can keep a ResourceFetch
er | 66 // are initialized without a LocalFrame), so a Document can keep a ResourceFetch
er |
| 67 // alive past detach if scripts still reference the Document. | 67 // alive past detach if scripts still reference the Document. |
| 68 class CORE_EXPORT ResourceFetcher : public GarbageCollectedFinalized<ResourceFet
cher> { | 68 class CORE_EXPORT ResourceFetcher : public GarbageCollectedFinalized<ResourceFet
cher> { |
| 69 WTF_MAKE_NONCOPYABLE(ResourceFetcher); | 69 WTF_MAKE_NONCOPYABLE(ResourceFetcher); |
| 70 WILL_BE_USING_PRE_FINALIZER(ResourceFetcher, clearPreloads); | 70 USING_PRE_FINALIZER(ResourceFetcher, clearPreloads); |
| 71 public: | 71 public: |
| 72 static ResourceFetcher* create(FetchContext* context) { return new ResourceF
etcher(context); } | 72 static ResourceFetcher* create(FetchContext* context) { return new ResourceF
etcher(context); } |
| 73 virtual ~ResourceFetcher(); | 73 virtual ~ResourceFetcher(); |
| 74 DECLARE_VIRTUAL_TRACE(); | 74 DECLARE_VIRTUAL_TRACE(); |
| 75 | 75 |
| 76 PassRefPtrWillBeRawPtr<Resource> requestResource(FetchRequest&, const Resour
ceFactory&, const SubstituteData& = SubstituteData()); | 76 RawPtr<Resource> requestResource(FetchRequest&, const ResourceFactory&, cons
t SubstituteData& = SubstituteData()); |
| 77 | 77 |
| 78 Resource* cachedResource(const KURL&) const; | 78 Resource* cachedResource(const KURL&) const; |
| 79 | 79 |
| 80 using DocumentResourceMap = WillBeHeapHashMap<String, WeakPtrWillBeWeakMembe
r<Resource>>; | 80 using DocumentResourceMap = HeapHashMap<String, WeakMember<Resource>>; |
| 81 const DocumentResourceMap& allResources() const { return m_documentResources
; } | 81 const DocumentResourceMap& allResources() const { return m_documentResources
; } |
| 82 | 82 |
| 83 void setAutoLoadImages(bool); | 83 void setAutoLoadImages(bool); |
| 84 void setImagesEnabled(bool); | 84 void setImagesEnabled(bool); |
| 85 | 85 |
| 86 FetchContext& context() const { return m_context ? *m_context.get() : FetchC
ontext::nullInstance(); } | 86 FetchContext& context() const { return m_context ? *m_context.get() : FetchC
ontext::nullInstance(); } |
| 87 void clearContext() { m_context.clear(); } | 87 void clearContext() { m_context.clear(); } |
| 88 | 88 |
| 89 int requestCount() const; | 89 int requestCount() const; |
| 90 | 90 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 static void determineRequestContext(ResourceRequest&, Resource::Type, bool i
sMainFrame); | 138 static void determineRequestContext(ResourceRequest&, Resource::Type, bool i
sMainFrame); |
| 139 void determineRequestContext(ResourceRequest&, Resource::Type); | 139 void determineRequestContext(ResourceRequest&, Resource::Type); |
| 140 | 140 |
| 141 WebTaskRunner* loadingTaskRunner(); | 141 WebTaskRunner* loadingTaskRunner(); |
| 142 | 142 |
| 143 void updateAllImageResourcePriorities(); | 143 void updateAllImageResourcePriorities(); |
| 144 | 144 |
| 145 void reloadLoFiImages(); | 145 void reloadLoFiImages(); |
| 146 | 146 |
| 147 // This is only exposed for testing purposes. | 147 // This is only exposed for testing purposes. |
| 148 WillBeHeapListHashSet<RefPtrWillBeMember<Resource>>* preloads() { return m_p
reloads.get(); } | 148 HeapListHashSet<Member<Resource>>* preloads() { return m_preloads.get(); } |
| 149 | 149 |
| 150 private: | 150 private: |
| 151 friend class ResourceCacheValidationSuppressor; | 151 friend class ResourceCacheValidationSuppressor; |
| 152 | 152 |
| 153 explicit ResourceFetcher(FetchContext*); | 153 explicit ResourceFetcher(FetchContext*); |
| 154 | 154 |
| 155 void initializeRevalidation(const FetchRequest&, Resource*); | 155 void initializeRevalidation(const FetchRequest&, Resource*); |
| 156 PassRefPtrWillBeRawPtr<Resource> createResourceForLoading(FetchRequest&, con
st String& charset, const ResourceFactory&); | 156 RawPtr<Resource> createResourceForLoading(FetchRequest&, const String& chars
et, const ResourceFactory&); |
| 157 void storeResourceTimingInitiatorInformation(Resource*); | 157 void storeResourceTimingInitiatorInformation(Resource*); |
| 158 | 158 |
| 159 PassRefPtrWillBeRawPtr<Resource> resourceForStaticData(const FetchRequest&,
const ResourceFactory&, const SubstituteData&); | 159 RawPtr<Resource> resourceForStaticData(const FetchRequest&, const ResourceFa
ctory&, const SubstituteData&); |
| 160 | 160 |
| 161 // RevalidationPolicy enum values are used in UMAs https://crbug.com/579496. | 161 // RevalidationPolicy enum values are used in UMAs https://crbug.com/579496. |
| 162 enum RevalidationPolicy { Use, Revalidate, Reload, Load }; | 162 enum RevalidationPolicy { Use, Revalidate, Reload, Load }; |
| 163 RevalidationPolicy determineRevalidationPolicy(Resource::Type, const FetchRe
quest&, Resource* existingResource, bool isStaticData) const; | 163 RevalidationPolicy determineRevalidationPolicy(Resource::Type, const FetchRe
quest&, Resource* existingResource, bool isStaticData) const; |
| 164 | 164 |
| 165 void moveCachedNonBlockingResourceToBlocking(Resource*, const FetchRequest&)
; | 165 void moveCachedNonBlockingResourceToBlocking(Resource*, const FetchRequest&)
; |
| 166 | 166 |
| 167 void initializeResourceRequest(ResourceRequest&, Resource::Type); | 167 void initializeResourceRequest(ResourceRequest&, Resource::Type); |
| 168 | 168 |
| 169 bool resourceNeedsLoad(Resource*, const FetchRequest&, RevalidationPolicy); | 169 bool resourceNeedsLoad(Resource*, const FetchRequest&, RevalidationPolicy); |
| 170 bool shouldDeferImageLoad(const KURL&) const; | 170 bool shouldDeferImageLoad(const KURL&) const; |
| 171 | 171 |
| 172 void resourceTimingReportTimerFired(Timer<ResourceFetcher>*); | 172 void resourceTimingReportTimerFired(Timer<ResourceFetcher>*); |
| 173 | 173 |
| 174 void reloadImagesIfNotDeferred(); | 174 void reloadImagesIfNotDeferred(); |
| 175 | 175 |
| 176 void updateMemoryCacheStats(Resource*, RevalidationPolicy, const FetchReques
t&, const ResourceFactory&, bool isStaticData) const; | 176 void updateMemoryCacheStats(Resource*, RevalidationPolicy, const FetchReques
t&, const ResourceFactory&, bool isStaticData) const; |
| 177 | 177 |
| 178 Member<FetchContext> m_context; | 178 Member<FetchContext> m_context; |
| 179 | 179 |
| 180 HashSet<String> m_validatedURLs; | 180 HashSet<String> m_validatedURLs; |
| 181 mutable DocumentResourceMap m_documentResources; | 181 mutable DocumentResourceMap m_documentResources; |
| 182 | 182 |
| 183 OwnPtrWillBeMember<WillBeHeapListHashSet<RefPtrWillBeMember<Resource>>> m_pr
eloads; | 183 Member<HeapListHashSet<Member<Resource>>> m_preloads; |
| 184 RefPtrWillBeMember<MHTMLArchive> m_archive; | 184 Member<MHTMLArchive> m_archive; |
| 185 | 185 |
| 186 Timer<ResourceFetcher> m_resourceTimingReportTimer; | 186 Timer<ResourceFetcher> m_resourceTimingReportTimer; |
| 187 | 187 |
| 188 using ResourceTimingInfoMap = WillBeHeapHashMap<RawPtrWillBeMember<Resource>
, OwnPtr<ResourceTimingInfo>>; | 188 using ResourceTimingInfoMap = HeapHashMap<Member<Resource>, OwnPtr<ResourceT
imingInfo>>; |
| 189 ResourceTimingInfoMap m_resourceTimingInfoMap; | 189 ResourceTimingInfoMap m_resourceTimingInfoMap; |
| 190 | 190 |
| 191 Vector<OwnPtr<ResourceTimingInfo>> m_scheduledResourceTimingReports; | 191 Vector<OwnPtr<ResourceTimingInfo>> m_scheduledResourceTimingReports; |
| 192 | 192 |
| 193 Member<ResourceLoaderSet> m_loaders; | 193 Member<ResourceLoaderSet> m_loaders; |
| 194 Member<ResourceLoaderSet> m_nonBlockingLoaders; | 194 Member<ResourceLoaderSet> m_nonBlockingLoaders; |
| 195 | 195 |
| 196 // Used in hit rate histograms. | 196 // Used in hit rate histograms. |
| 197 class DeadResourceStatsRecorder { | 197 class DeadResourceStatsRecorder { |
| 198 DISALLOW_NEW(); | 198 DISALLOW_NEW(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 m_loader->m_allowStaleResources = m_previousState; | 234 m_loader->m_allowStaleResources = m_previousState; |
| 235 } | 235 } |
| 236 private: | 236 private: |
| 237 Member<ResourceFetcher> m_loader; | 237 Member<ResourceFetcher> m_loader; |
| 238 bool m_previousState; | 238 bool m_previousState; |
| 239 }; | 239 }; |
| 240 | 240 |
| 241 } // namespace blink | 241 } // namespace blink |
| 242 | 242 |
| 243 #endif // ResourceFetcher_h | 243 #endif // ResourceFetcher_h |
| OLD | NEW |