| 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 15 matching lines...) Expand all Loading... |
| 26 #ifndef ResourceFetcher_h | 26 #ifndef ResourceFetcher_h |
| 27 #define ResourceFetcher_h | 27 #define ResourceFetcher_h |
| 28 | 28 |
| 29 #include "core/CoreExport.h" | 29 #include "core/CoreExport.h" |
| 30 #include "core/fetch/CachePolicy.h" | 30 #include "core/fetch/CachePolicy.h" |
| 31 #include "core/fetch/FetchContext.h" | 31 #include "core/fetch/FetchContext.h" |
| 32 #include "core/fetch/FetchInitiatorInfo.h" | 32 #include "core/fetch/FetchInitiatorInfo.h" |
| 33 #include "core/fetch/FetchRequest.h" | 33 #include "core/fetch/FetchRequest.h" |
| 34 #include "core/fetch/Resource.h" | 34 #include "core/fetch/Resource.h" |
| 35 #include "core/fetch/ResourceLoaderOptions.h" | 35 #include "core/fetch/ResourceLoaderOptions.h" |
| 36 #include "core/fetch/ResourcePtr.h" | |
| 37 #include "core/fetch/SubstituteData.h" | 36 #include "core/fetch/SubstituteData.h" |
| 38 #include "platform/Timer.h" | 37 #include "platform/Timer.h" |
| 39 #include "platform/network/ResourceError.h" | 38 #include "platform/network/ResourceError.h" |
| 40 #include "platform/network/ResourceLoadPriority.h" | 39 #include "platform/network/ResourceLoadPriority.h" |
| 41 #include "wtf/HashMap.h" | 40 #include "wtf/HashMap.h" |
| 42 #include "wtf/HashSet.h" | 41 #include "wtf/HashSet.h" |
| 43 #include "wtf/ListHashSet.h" | 42 #include "wtf/ListHashSet.h" |
| 44 #include "wtf/text/StringHash.h" | 43 #include "wtf/text/StringHash.h" |
| 45 | 44 |
| 46 namespace blink { | 45 namespace blink { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 67 // 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 |
| 68 // alive past detach if scripts still reference the Document. | 67 // alive past detach if scripts still reference the Document. |
| 69 class CORE_EXPORT ResourceFetcher : public GarbageCollectedFinalized<ResourceFet
cher> { | 68 class CORE_EXPORT ResourceFetcher : public GarbageCollectedFinalized<ResourceFet
cher> { |
| 70 WTF_MAKE_NONCOPYABLE(ResourceFetcher); | 69 WTF_MAKE_NONCOPYABLE(ResourceFetcher); |
| 71 WILL_BE_USING_PRE_FINALIZER(ResourceFetcher, clearPreloads); | 70 WILL_BE_USING_PRE_FINALIZER(ResourceFetcher, clearPreloads); |
| 72 public: | 71 public: |
| 73 static ResourceFetcher* create(FetchContext* context) { return new ResourceF
etcher(context); } | 72 static ResourceFetcher* create(FetchContext* context) { return new ResourceF
etcher(context); } |
| 74 virtual ~ResourceFetcher(); | 73 virtual ~ResourceFetcher(); |
| 75 DECLARE_VIRTUAL_TRACE(); | 74 DECLARE_VIRTUAL_TRACE(); |
| 76 | 75 |
| 77 ResourcePtr<Resource> requestResource(FetchRequest&, const ResourceFactory&,
const SubstituteData& = SubstituteData()); | 76 PassRefPtrWillBeRawPtr<Resource> requestResource(FetchRequest&, const Resour
ceFactory&, const SubstituteData& = SubstituteData()); |
| 78 | 77 |
| 79 Resource* cachedResource(const KURL&) const; | 78 Resource* cachedResource(const KURL&) const; |
| 80 | 79 |
| 81 using DocumentResourceMap = WillBeHeapHashMap<String, WeakPtrWillBeWeakMembe
r<Resource>>; | 80 using DocumentResourceMap = WillBeHeapHashMap<String, WeakPtrWillBeWeakMembe
r<Resource>>; |
| 82 const DocumentResourceMap& allResources() const { return m_documentResources
; } | 81 const DocumentResourceMap& allResources() const { return m_documentResources
; } |
| 83 | 82 |
| 84 bool autoLoadImages() const { return m_autoLoadImages; } | 83 bool autoLoadImages() const { return m_autoLoadImages; } |
| 85 void setAutoLoadImages(bool); | 84 void setAutoLoadImages(bool); |
| 86 | 85 |
| 87 void setImagesEnabled(bool); | 86 void setImagesEnabled(bool); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 void scheduleDocumentResourcesGC(); | 144 void scheduleDocumentResourcesGC(); |
| 146 bool clientDefersImage(const KURL&) const; | 145 bool clientDefersImage(const KURL&) const; |
| 147 static void determineRequestContext(ResourceRequest&, Resource::Type, bool i
sMainFrame); | 146 static void determineRequestContext(ResourceRequest&, Resource::Type, bool i
sMainFrame); |
| 148 void determineRequestContext(ResourceRequest&, Resource::Type); | 147 void determineRequestContext(ResourceRequest&, Resource::Type); |
| 149 | 148 |
| 150 WebTaskRunner* loadingTaskRunner(); | 149 WebTaskRunner* loadingTaskRunner(); |
| 151 | 150 |
| 152 void updateAllImageResourcePriorities(); | 151 void updateAllImageResourcePriorities(); |
| 153 | 152 |
| 154 // This is only exposed for testing purposes. | 153 // This is only exposed for testing purposes. |
| 155 WillBeHeapListHashSet<RawPtrWillBeMember<Resource>>* preloads() { return m_p
reloads.get(); } | 154 WillBeHeapListHashSet<RefPtrWillBeMember<Resource>>* preloads() { return m_p
reloads.get(); } |
| 156 | 155 |
| 157 private: | 156 private: |
| 158 friend class ResourceCacheValidationSuppressor; | 157 friend class ResourceCacheValidationSuppressor; |
| 159 | 158 |
| 160 explicit ResourceFetcher(FetchContext*); | 159 explicit ResourceFetcher(FetchContext*); |
| 161 | 160 |
| 162 void initializeRevalidation(const FetchRequest&, Resource*); | 161 void initializeRevalidation(const FetchRequest&, Resource*); |
| 163 ResourcePtr<Resource> createResourceForLoading(FetchRequest&, const String&
charset, const ResourceFactory&); | 162 PassRefPtrWillBeRawPtr<Resource> createResourceForLoading(FetchRequest&, con
st String& charset, const ResourceFactory&); |
| 164 void storeResourceTimingInitiatorInformation(Resource*); | 163 void storeResourceTimingInitiatorInformation(Resource*); |
| 165 bool scheduleArchiveLoad(Resource*, const ResourceRequest&); | 164 bool scheduleArchiveLoad(Resource*, const ResourceRequest&); |
| 166 ResourcePtr<Resource> preCacheData(const FetchRequest&, const ResourceFactor
y&, const SubstituteData&); | 165 void preCacheData(const FetchRequest&, const ResourceFactory&, const Substit
uteData&); |
| 167 | 166 |
| 168 // RevalidationPolicy enum values are used in UMAs https://crbug.com/579496. | 167 // RevalidationPolicy enum values are used in UMAs https://crbug.com/579496. |
| 169 enum RevalidationPolicy { Use, Revalidate, Reload, Load }; | 168 enum RevalidationPolicy { Use, Revalidate, Reload, Load }; |
| 170 RevalidationPolicy determineRevalidationPolicy(Resource::Type, const FetchRe
quest&, Resource* existingResource, bool isStaticData) const; | 169 RevalidationPolicy determineRevalidationPolicy(Resource::Type, const FetchRe
quest&, Resource* existingResource, bool isStaticData) const; |
| 171 | 170 |
| 172 void moveCachedNonBlockingResourceToBlocking(Resource*, const FetchRequest&)
; | 171 void moveCachedNonBlockingResourceToBlocking(Resource*, const FetchRequest&)
; |
| 173 | 172 |
| 174 void initializeResourceRequest(ResourceRequest&, Resource::Type); | 173 void initializeResourceRequest(ResourceRequest&, Resource::Type); |
| 175 | 174 |
| 176 static bool resourceNeedsLoad(Resource*, const FetchRequest&, RevalidationPo
licy); | 175 static bool resourceNeedsLoad(Resource*, const FetchRequest&, RevalidationPo
licy); |
| 177 | 176 |
| 178 void resourceTimingReportTimerFired(Timer<ResourceFetcher>*); | 177 void resourceTimingReportTimerFired(Timer<ResourceFetcher>*); |
| 179 | 178 |
| 180 void reloadImagesIfNotDeferred(); | 179 void reloadImagesIfNotDeferred(); |
| 181 | 180 |
| 182 void willTerminateResourceLoader(ResourceLoader*); | 181 void willTerminateResourceLoader(ResourceLoader*); |
| 183 | 182 |
| 184 ResourceLoadPriority modifyPriorityForExperiments(ResourceLoadPriority, Reso
urce::Type, const FetchRequest&); | 183 ResourceLoadPriority modifyPriorityForExperiments(ResourceLoadPriority, Reso
urce::Type, const FetchRequest&); |
| 185 | 184 |
| 186 Member<FetchContext> m_context; | 185 Member<FetchContext> m_context; |
| 187 | 186 |
| 188 HashSet<String> m_validatedURLs; | 187 HashSet<String> m_validatedURLs; |
| 189 mutable DocumentResourceMap m_documentResources; | 188 mutable DocumentResourceMap m_documentResources; |
| 190 | 189 |
| 191 // We intentionally use a Member instead of a ResourcePtr. | 190 OwnPtrWillBeMember<WillBeHeapListHashSet<RefPtrWillBeMember<Resource>>> m_pr
eloads; |
| 192 // Using a ResourcePtrs can lead to a wrong behavior because | |
| 193 // the underlying Resource of the ResourcePtr is updated when the Resource | |
| 194 // is revalidated. What we really want to hold here is not the ResourcePtr | |
| 195 // but the underlying Resource. | |
| 196 OwnPtrWillBeMember<WillBeHeapListHashSet<RawPtrWillBeMember<Resource>>> m_pr
eloads; | |
| 197 RefPtrWillBeMember<MHTMLArchive> m_archive; | 191 RefPtrWillBeMember<MHTMLArchive> m_archive; |
| 198 | 192 |
| 199 Timer<ResourceFetcher> m_resourceTimingReportTimer; | 193 Timer<ResourceFetcher> m_resourceTimingReportTimer; |
| 200 | 194 |
| 201 // We intentionally use a Member instead of a ResourcePtr. | |
| 202 // See the comment on m_preloads. | |
| 203 using ResourceTimingInfoMap = WillBeHeapHashMap<RawPtrWillBeMember<Resource>
, OwnPtr<ResourceTimingInfo>>; | 195 using ResourceTimingInfoMap = WillBeHeapHashMap<RawPtrWillBeMember<Resource>
, OwnPtr<ResourceTimingInfo>>; |
| 204 ResourceTimingInfoMap m_resourceTimingInfoMap; | 196 ResourceTimingInfoMap m_resourceTimingInfoMap; |
| 205 | 197 |
| 206 Vector<OwnPtr<ResourceTimingInfo>> m_scheduledResourceTimingReports; | 198 Vector<OwnPtr<ResourceTimingInfo>> m_scheduledResourceTimingReports; |
| 207 | 199 |
| 208 Member<ResourceLoaderSet> m_loaders; | 200 Member<ResourceLoaderSet> m_loaders; |
| 209 Member<ResourceLoaderSet> m_nonBlockingLoaders; | 201 Member<ResourceLoaderSet> m_nonBlockingLoaders; |
| 210 | 202 |
| 211 // Used in hit rate histograms. | 203 // Used in hit rate histograms. |
| 212 class DeadResourceStatsRecorder { | 204 class DeadResourceStatsRecorder { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 m_loader->m_allowStaleResources = m_previousState; | 241 m_loader->m_allowStaleResources = m_previousState; |
| 250 } | 242 } |
| 251 private: | 243 private: |
| 252 Member<ResourceFetcher> m_loader; | 244 Member<ResourceFetcher> m_loader; |
| 253 bool m_previousState; | 245 bool m_previousState; |
| 254 }; | 246 }; |
| 255 | 247 |
| 256 } // namespace blink | 248 } // namespace blink |
| 257 | 249 |
| 258 #endif // ResourceFetcher_h | 250 #endif // ResourceFetcher_h |
| OLD | NEW |