| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 void reloadLoFiImages(); | 153 void reloadLoFiImages(); |
| 155 | 154 |
| 156 // This is only exposed for testing purposes. | 155 // This is only exposed for testing purposes. |
| 157 WillBeHeapListHashSet<RawPtrWillBeMember<Resource>>* preloads() { return m_p
reloads.get(); } | 156 WillBeHeapListHashSet<RefPtrWillBeMember<Resource>>* preloads() { return m_p
reloads.get(); } |
| 158 | 157 |
| 159 private: | 158 private: |
| 160 friend class ResourceCacheValidationSuppressor; | 159 friend class ResourceCacheValidationSuppressor; |
| 161 | 160 |
| 162 explicit ResourceFetcher(FetchContext*); | 161 explicit ResourceFetcher(FetchContext*); |
| 163 | 162 |
| 164 void initializeRevalidation(const FetchRequest&, Resource*); | 163 void initializeRevalidation(const FetchRequest&, Resource*); |
| 165 ResourcePtr<Resource> createResourceForLoading(FetchRequest&, const String&
charset, const ResourceFactory&); | 164 PassRefPtrWillBeRawPtr<Resource> createResourceForLoading(FetchRequest&, con
st String& charset, const ResourceFactory&); |
| 166 void storeResourceTimingInitiatorInformation(Resource*); | 165 void storeResourceTimingInitiatorInformation(Resource*); |
| 167 bool scheduleArchiveLoad(Resource*, const ResourceRequest&); | 166 bool scheduleArchiveLoad(Resource*, const ResourceRequest&); |
| 168 ResourcePtr<Resource> preCacheData(const FetchRequest&, const ResourceFactor
y&, const SubstituteData&); | 167 void preCacheData(const FetchRequest&, const ResourceFactory&, const Substit
uteData&); |
| 169 | 168 |
| 170 // RevalidationPolicy enum values are used in UMAs https://crbug.com/579496. | 169 // RevalidationPolicy enum values are used in UMAs https://crbug.com/579496. |
| 171 enum RevalidationPolicy { Use, Revalidate, Reload, Load }; | 170 enum RevalidationPolicy { Use, Revalidate, Reload, Load }; |
| 172 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; |
| 173 | 172 |
| 174 void moveCachedNonBlockingResourceToBlocking(Resource*, const FetchRequest&)
; | 173 void moveCachedNonBlockingResourceToBlocking(Resource*, const FetchRequest&)
; |
| 175 | 174 |
| 176 void initializeResourceRequest(ResourceRequest&, Resource::Type); | 175 void initializeResourceRequest(ResourceRequest&, Resource::Type); |
| 177 | 176 |
| 178 static bool resourceNeedsLoad(Resource*, const FetchRequest&, RevalidationPo
licy); | 177 static bool resourceNeedsLoad(Resource*, const FetchRequest&, RevalidationPo
licy); |
| 179 | 178 |
| 180 void resourceTimingReportTimerFired(Timer<ResourceFetcher>*); | 179 void resourceTimingReportTimerFired(Timer<ResourceFetcher>*); |
| 181 | 180 |
| 182 void reloadImagesIfNotDeferred(); | 181 void reloadImagesIfNotDeferred(); |
| 183 | 182 |
| 184 void willTerminateResourceLoader(ResourceLoader*); | 183 void willTerminateResourceLoader(ResourceLoader*); |
| 185 | 184 |
| 186 ResourceLoadPriority modifyPriorityForExperiments(ResourceLoadPriority, Reso
urce::Type, const FetchRequest&); | 185 ResourceLoadPriority modifyPriorityForExperiments(ResourceLoadPriority, Reso
urce::Type, const FetchRequest&); |
| 187 | 186 |
| 188 Member<FetchContext> m_context; | 187 Member<FetchContext> m_context; |
| 189 | 188 |
| 190 HashSet<String> m_validatedURLs; | 189 HashSet<String> m_validatedURLs; |
| 191 mutable DocumentResourceMap m_documentResources; | 190 mutable DocumentResourceMap m_documentResources; |
| 192 | 191 |
| 193 // We intentionally use a Member instead of a ResourcePtr. | 192 OwnPtrWillBeMember<WillBeHeapListHashSet<RefPtrWillBeMember<Resource>>> m_pr
eloads; |
| 194 // Using a ResourcePtrs can lead to a wrong behavior because | |
| 195 // the underlying Resource of the ResourcePtr is updated when the Resource | |
| 196 // is revalidated. What we really want to hold here is not the ResourcePtr | |
| 197 // but the underlying Resource. | |
| 198 OwnPtrWillBeMember<WillBeHeapListHashSet<RawPtrWillBeMember<Resource>>> m_pr
eloads; | |
| 199 RefPtrWillBeMember<MHTMLArchive> m_archive; | 193 RefPtrWillBeMember<MHTMLArchive> m_archive; |
| 200 | 194 |
| 201 Timer<ResourceFetcher> m_resourceTimingReportTimer; | 195 Timer<ResourceFetcher> m_resourceTimingReportTimer; |
| 202 | 196 |
| 203 // We intentionally use a Member instead of a ResourcePtr. | |
| 204 // See the comment on m_preloads. | |
| 205 using ResourceTimingInfoMap = WillBeHeapHashMap<RawPtrWillBeMember<Resource>
, OwnPtr<ResourceTimingInfo>>; | 197 using ResourceTimingInfoMap = WillBeHeapHashMap<RawPtrWillBeMember<Resource>
, OwnPtr<ResourceTimingInfo>>; |
| 206 ResourceTimingInfoMap m_resourceTimingInfoMap; | 198 ResourceTimingInfoMap m_resourceTimingInfoMap; |
| 207 | 199 |
| 208 Vector<OwnPtr<ResourceTimingInfo>> m_scheduledResourceTimingReports; | 200 Vector<OwnPtr<ResourceTimingInfo>> m_scheduledResourceTimingReports; |
| 209 | 201 |
| 210 Member<ResourceLoaderSet> m_loaders; | 202 Member<ResourceLoaderSet> m_loaders; |
| 211 Member<ResourceLoaderSet> m_nonBlockingLoaders; | 203 Member<ResourceLoaderSet> m_nonBlockingLoaders; |
| 212 | 204 |
| 213 // Used in hit rate histograms. | 205 // Used in hit rate histograms. |
| 214 class DeadResourceStatsRecorder { | 206 class DeadResourceStatsRecorder { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 m_loader->m_allowStaleResources = m_previousState; | 243 m_loader->m_allowStaleResources = m_previousState; |
| 252 } | 244 } |
| 253 private: | 245 private: |
| 254 Member<ResourceFetcher> m_loader; | 246 Member<ResourceFetcher> m_loader; |
| 255 bool m_previousState; | 247 bool m_previousState; |
| 256 }; | 248 }; |
| 257 | 249 |
| 258 } // namespace blink | 250 } // namespace blink |
| 259 | 251 |
| 260 #endif // ResourceFetcher_h | 252 #endif // ResourceFetcher_h |
| OLD | NEW |