| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 static void determineRequestContext(ResourceRequest&, Resource::Type, bool i
sMainFrame); | 139 static void determineRequestContext(ResourceRequest&, Resource::Type, bool i
sMainFrame); |
| 140 void determineRequestContext(ResourceRequest&, Resource::Type); | 140 void determineRequestContext(ResourceRequest&, Resource::Type); |
| 141 | 141 |
| 142 WebTaskRunner* loadingTaskRunner(); | 142 WebTaskRunner* loadingTaskRunner(); |
| 143 | 143 |
| 144 void updateAllImageResourcePriorities(); | 144 void updateAllImageResourcePriorities(); |
| 145 | 145 |
| 146 void reloadLoFiImages(); | 146 void reloadLoFiImages(); |
| 147 | 147 |
| 148 // This is only exposed for testing purposes. | 148 // This is only exposed for testing purposes. |
| 149 WillBeHeapListHashSet<RefPtrWillBeMember<Resource>>* preloads() { return m_p
reloads.get(); } | 149 HeapListHashSet<Member<Resource>>* preloads() { return m_preloads.get(); } |
| 150 | 150 |
| 151 private: | 151 private: |
| 152 friend class ResourceCacheValidationSuppressor; | 152 friend class ResourceCacheValidationSuppressor; |
| 153 | 153 |
| 154 explicit ResourceFetcher(FetchContext*); | 154 explicit ResourceFetcher(FetchContext*); |
| 155 | 155 |
| 156 void initializeRevalidation(const FetchRequest&, Resource*); | 156 void initializeRevalidation(const FetchRequest&, Resource*); |
| 157 PassRefPtrWillBeRawPtr<Resource> createResourceForLoading(FetchRequest&, con
st String& charset, const ResourceFactory&); | 157 RawPtr<Resource> createResourceForLoading(FetchRequest&, const String& chars
et, const ResourceFactory&); |
| 158 void storeResourceTimingInitiatorInformation(Resource*); | 158 void storeResourceTimingInitiatorInformation(Resource*); |
| 159 | 159 |
| 160 PassRefPtrWillBeRawPtr<Resource> resourceForStaticData(const FetchRequest&,
const ResourceFactory&, const SubstituteData&); | 160 RawPtr<Resource> resourceForStaticData(const FetchRequest&, const ResourceFa
ctory&, const SubstituteData&); |
| 161 | 161 |
| 162 // RevalidationPolicy enum values are used in UMAs https://crbug.com/579496. | 162 // RevalidationPolicy enum values are used in UMAs https://crbug.com/579496. |
| 163 enum RevalidationPolicy { Use, Revalidate, Reload, Load }; | 163 enum RevalidationPolicy { Use, Revalidate, Reload, Load }; |
| 164 RevalidationPolicy determineRevalidationPolicy(Resource::Type, const FetchRe
quest&, Resource* existingResource, bool isStaticData) const; | 164 RevalidationPolicy determineRevalidationPolicy(Resource::Type, const FetchRe
quest&, Resource* existingResource, bool isStaticData) const; |
| 165 | 165 |
| 166 void moveCachedNonBlockingResourceToBlocking(Resource*, const FetchRequest&)
; | 166 void moveCachedNonBlockingResourceToBlocking(Resource*, const FetchRequest&)
; |
| 167 | 167 |
| 168 void initializeResourceRequest(ResourceRequest&, Resource::Type); | 168 void initializeResourceRequest(ResourceRequest&, Resource::Type); |
| 169 | 169 |
| 170 bool resourceNeedsLoad(Resource*, const FetchRequest&, RevalidationPolicy); | 170 bool resourceNeedsLoad(Resource*, const FetchRequest&, RevalidationPolicy); |
| 171 bool shouldDeferImageLoad(const KURL&) const; | 171 bool shouldDeferImageLoad(const KURL&) const; |
| 172 | 172 |
| 173 void resourceTimingReportTimerFired(Timer<ResourceFetcher>*); | 173 void resourceTimingReportTimerFired(Timer<ResourceFetcher>*); |
| 174 | 174 |
| 175 void reloadImagesIfNotDeferred(); | 175 void reloadImagesIfNotDeferred(); |
| 176 | 176 |
| 177 void updateMemoryCacheStats(Resource*, RevalidationPolicy, const FetchReques
t&, const ResourceFactory&, bool isStaticData) const; | 177 void updateMemoryCacheStats(Resource*, RevalidationPolicy, const FetchReques
t&, const ResourceFactory&, bool isStaticData) const; |
| 178 | 178 |
| 179 Member<FetchContext> m_context; | 179 Member<FetchContext> m_context; |
| 180 | 180 |
| 181 HashSet<String> m_validatedURLs; | 181 HashSet<String> m_validatedURLs; |
| 182 mutable DocumentResourceMap m_documentResources; | 182 mutable DocumentResourceMap m_documentResources; |
| 183 | 183 |
| 184 OwnPtrWillBeMember<WillBeHeapListHashSet<RefPtrWillBeMember<Resource>>> m_pr
eloads; | 184 Member<HeapListHashSet<Member<Resource>>> m_preloads; |
| 185 RefPtrWillBeMember<MHTMLArchive> m_archive; | 185 Member<MHTMLArchive> m_archive; |
| 186 | 186 |
| 187 Timer<ResourceFetcher> m_resourceTimingReportTimer; | 187 Timer<ResourceFetcher> m_resourceTimingReportTimer; |
| 188 | 188 |
| 189 using ResourceTimingInfoMap = WillBeHeapHashMap<RawPtrWillBeMember<Resource>
, OwnPtr<ResourceTimingInfo>>; | 189 using ResourceTimingInfoMap = HeapHashMap<Member<Resource>, OwnPtr<ResourceT
imingInfo>>; |
| 190 ResourceTimingInfoMap m_resourceTimingInfoMap; | 190 ResourceTimingInfoMap m_resourceTimingInfoMap; |
| 191 | 191 |
| 192 Vector<OwnPtr<ResourceTimingInfo>> m_scheduledResourceTimingReports; | 192 Vector<OwnPtr<ResourceTimingInfo>> m_scheduledResourceTimingReports; |
| 193 | 193 |
| 194 Member<ResourceLoaderSet> m_loaders; | 194 Member<ResourceLoaderSet> m_loaders; |
| 195 Member<ResourceLoaderSet> m_nonBlockingLoaders; | 195 Member<ResourceLoaderSet> m_nonBlockingLoaders; |
| 196 | 196 |
| 197 // Used in hit rate histograms. | 197 // Used in hit rate histograms. |
| 198 class DeadResourceStatsRecorder { | 198 class DeadResourceStatsRecorder { |
| 199 DISALLOW_NEW(); | 199 DISALLOW_NEW(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 m_loader->m_allowStaleResources = m_previousState; | 235 m_loader->m_allowStaleResources = m_previousState; |
| 236 } | 236 } |
| 237 private: | 237 private: |
| 238 Member<ResourceFetcher> m_loader; | 238 Member<ResourceFetcher> m_loader; |
| 239 bool m_previousState; | 239 bool m_previousState; |
| 240 }; | 240 }; |
| 241 | 241 |
| 242 } // namespace blink | 242 } // namespace blink |
| 243 | 243 |
| 244 #endif // ResourceFetcher_h | 244 #endif // ResourceFetcher_h |
| OLD | NEW |