| 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 bool autoLoadImages() const { return m_autoLoadImages; } | 83 bool autoLoadImages() const { return m_autoLoadImages; } |
| 84 void setAutoLoadImages(bool); | 84 void setAutoLoadImages(bool); |
| 85 | 85 |
| 86 void setImagesEnabled(bool); | 86 void setImagesEnabled(bool); |
| 87 | 87 |
| 88 bool shouldDeferImageLoad(const KURL&) const; | 88 bool shouldDeferImageLoad(const KURL&) const; |
| 89 | 89 |
| 90 FetchContext& context() const { return m_context ? *m_context.get() : FetchC
ontext::nullInstance(); } | 90 FetchContext& context() const { return m_context ? *m_context.get() : FetchC
ontext::nullInstance(); } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 static void determineRequestContext(ResourceRequest&, Resource::Type, bool i
sMainFrame); | 146 static void determineRequestContext(ResourceRequest&, Resource::Type, bool i
sMainFrame); |
| 147 void determineRequestContext(ResourceRequest&, Resource::Type); | 147 void determineRequestContext(ResourceRequest&, Resource::Type); |
| 148 | 148 |
| 149 WebTaskRunner* loadingTaskRunner(); | 149 WebTaskRunner* loadingTaskRunner(); |
| 150 | 150 |
| 151 void updateAllImageResourcePriorities(); | 151 void updateAllImageResourcePriorities(); |
| 152 | 152 |
| 153 void reloadLoFiImages(); | 153 void reloadLoFiImages(); |
| 154 | 154 |
| 155 // This is only exposed for testing purposes. | 155 // This is only exposed for testing purposes. |
| 156 WillBeHeapListHashSet<RefPtrWillBeMember<Resource>>* preloads() { return m_p
reloads.get(); } | 156 HeapListHashSet<Member<Resource>>* preloads() { return m_preloads.get(); } |
| 157 | 157 |
| 158 private: | 158 private: |
| 159 friend class ResourceCacheValidationSuppressor; | 159 friend class ResourceCacheValidationSuppressor; |
| 160 | 160 |
| 161 explicit ResourceFetcher(FetchContext*); | 161 explicit ResourceFetcher(FetchContext*); |
| 162 | 162 |
| 163 void initializeRevalidation(const FetchRequest&, Resource*); | 163 void initializeRevalidation(const FetchRequest&, Resource*); |
| 164 PassRefPtrWillBeRawPtr<Resource> createResourceForLoading(FetchRequest&, con
st String& charset, const ResourceFactory&); | 164 RawPtr<Resource> createResourceForLoading(FetchRequest&, const String& chars
et, const ResourceFactory&); |
| 165 void storeResourceTimingInitiatorInformation(Resource*); | 165 void storeResourceTimingInitiatorInformation(Resource*); |
| 166 bool scheduleArchiveLoad(Resource*, const ResourceRequest&); | 166 bool scheduleArchiveLoad(Resource*, const ResourceRequest&); |
| 167 void preCacheData(const FetchRequest&, const ResourceFactory&, const Substit
uteData&); | 167 void preCacheData(const FetchRequest&, const ResourceFactory&, const Substit
uteData&); |
| 168 | 168 |
| 169 // RevalidationPolicy enum values are used in UMAs https://crbug.com/579496. | 169 // RevalidationPolicy enum values are used in UMAs https://crbug.com/579496. |
| 170 enum RevalidationPolicy { Use, Revalidate, Reload, Load }; | 170 enum RevalidationPolicy { Use, Revalidate, Reload, Load }; |
| 171 RevalidationPolicy determineRevalidationPolicy(Resource::Type, const FetchRe
quest&, Resource* existingResource, bool isStaticData) const; | 171 RevalidationPolicy determineRevalidationPolicy(Resource::Type, const FetchRe
quest&, Resource* existingResource, bool isStaticData) const; |
| 172 | 172 |
| 173 void moveCachedNonBlockingResourceToBlocking(Resource*, const FetchRequest&)
; | 173 void moveCachedNonBlockingResourceToBlocking(Resource*, const FetchRequest&)
; |
| 174 | 174 |
| 175 void initializeResourceRequest(ResourceRequest&, Resource::Type); | 175 void initializeResourceRequest(ResourceRequest&, Resource::Type); |
| 176 | 176 |
| 177 static bool resourceNeedsLoad(Resource*, const FetchRequest&, RevalidationPo
licy); | 177 static bool resourceNeedsLoad(Resource*, const FetchRequest&, RevalidationPo
licy); |
| 178 | 178 |
| 179 void resourceTimingReportTimerFired(Timer<ResourceFetcher>*); | 179 void resourceTimingReportTimerFired(Timer<ResourceFetcher>*); |
| 180 | 180 |
| 181 void reloadImagesIfNotDeferred(); | 181 void reloadImagesIfNotDeferred(); |
| 182 | 182 |
| 183 void willTerminateResourceLoader(ResourceLoader*); | 183 void willTerminateResourceLoader(ResourceLoader*); |
| 184 | 184 |
| 185 ResourceLoadPriority modifyPriorityForExperiments(ResourceLoadPriority, Reso
urce::Type, const FetchRequest&); | 185 ResourceLoadPriority modifyPriorityForExperiments(ResourceLoadPriority, Reso
urce::Type, const FetchRequest&); |
| 186 | 186 |
| 187 Member<FetchContext> m_context; | 187 Member<FetchContext> m_context; |
| 188 | 188 |
| 189 HashSet<String> m_validatedURLs; | 189 HashSet<String> m_validatedURLs; |
| 190 mutable DocumentResourceMap m_documentResources; | 190 mutable DocumentResourceMap m_documentResources; |
| 191 | 191 |
| 192 OwnPtrWillBeMember<WillBeHeapListHashSet<RefPtrWillBeMember<Resource>>> m_pr
eloads; | 192 Member<HeapListHashSet<Member<Resource>>> m_preloads; |
| 193 RefPtrWillBeMember<MHTMLArchive> m_archive; | 193 Member<MHTMLArchive> m_archive; |
| 194 | 194 |
| 195 Timer<ResourceFetcher> m_resourceTimingReportTimer; | 195 Timer<ResourceFetcher> m_resourceTimingReportTimer; |
| 196 | 196 |
| 197 using ResourceTimingInfoMap = WillBeHeapHashMap<RawPtrWillBeMember<Resource>
, OwnPtr<ResourceTimingInfo>>; | 197 using ResourceTimingInfoMap = HeapHashMap<Member<Resource>, OwnPtr<ResourceT
imingInfo>>; |
| 198 ResourceTimingInfoMap m_resourceTimingInfoMap; | 198 ResourceTimingInfoMap m_resourceTimingInfoMap; |
| 199 | 199 |
| 200 Vector<OwnPtr<ResourceTimingInfo>> m_scheduledResourceTimingReports; | 200 Vector<OwnPtr<ResourceTimingInfo>> m_scheduledResourceTimingReports; |
| 201 | 201 |
| 202 Member<ResourceLoaderSet> m_loaders; | 202 Member<ResourceLoaderSet> m_loaders; |
| 203 Member<ResourceLoaderSet> m_nonBlockingLoaders; | 203 Member<ResourceLoaderSet> m_nonBlockingLoaders; |
| 204 | 204 |
| 205 // Used in hit rate histograms. | 205 // Used in hit rate histograms. |
| 206 class DeadResourceStatsRecorder { | 206 class DeadResourceStatsRecorder { |
| 207 DISALLOW_NEW(); | 207 DISALLOW_NEW(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 m_loader->m_allowStaleResources = m_previousState; | 243 m_loader->m_allowStaleResources = m_previousState; |
| 244 } | 244 } |
| 245 private: | 245 private: |
| 246 Member<ResourceFetcher> m_loader; | 246 Member<ResourceFetcher> m_loader; |
| 247 bool m_previousState; | 247 bool m_previousState; |
| 248 }; | 248 }; |
| 249 | 249 |
| 250 } // namespace blink | 250 } // namespace blink |
| 251 | 251 |
| 252 #endif // ResourceFetcher_h | 252 #endif // ResourceFetcher_h |
| OLD | NEW |