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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 class SubstituteData; | 55 class SubstituteData; |
56 class XSLStyleSheetResource; | 56 class XSLStyleSheetResource; |
57 class KURL; | 57 class KURL; |
58 class ResourceTimingInfo; | 58 class ResourceTimingInfo; |
59 class ResourceLoaderSet; | 59 class ResourceLoaderSet; |
60 | 60 |
61 // The ResourceFetcher provides a per-context interface to the MemoryCache | 61 // The ResourceFetcher provides a per-context interface to the MemoryCache |
62 // and enforces a bunch of security checks and rules for resource revalidation. | 62 // and enforces a bunch of security checks and rules for resource revalidation. |
63 // Its lifetime is roughly per-DocumentLoader, in that it is generally created | 63 // Its lifetime is roughly per-DocumentLoader, in that it is generally created |
64 // in the DocumentLoader constructor and loses its ability to generate network | 64 // in the DocumentLoader constructor and loses its ability to generate network |
65 // requests when the DocumentLoader is destroyed. Documents also hold a | 65 // requests when the DocumentLoader is destroyed. Documents also hold a pointer |
66 // RefPtr<ResourceFetcher> for their lifetime (and will create one if they | 66 // to ResourceFetcher for their lifetime (and will create one if they |
67 // are initialized without a LocalFrame), so a Document can keep a ResourceFetch
er | 67 // are initialized without a LocalFrame), so a Document can keep a ResourceFetch
er |
68 // alive past detach if scripts still reference the Document. | 68 // alive past detach if scripts still reference the Document. |
69 class CORE_EXPORT ResourceFetcher : public RefCountedWillBeGarbageCollectedFinal
ized<ResourceFetcher> { | 69 class CORE_EXPORT ResourceFetcher : public GarbageCollectedFinalized<ResourceFet
cher> { |
70 WTF_MAKE_NONCOPYABLE(ResourceFetcher); WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOV
ED(ResourceFetcher); | 70 WTF_MAKE_NONCOPYABLE(ResourceFetcher); |
71 public: | 71 public: |
72 static PassRefPtrWillBeRawPtr<ResourceFetcher> create(PassOwnPtrWillBeRawPtr
<FetchContext> context) { return adoptRefWillBeNoop(new ResourceFetcher(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 ResourcePtr<Resource> requestResource(FetchRequest&, const ResourceFactory&)
; | 76 ResourcePtr<Resource> requestResource(FetchRequest&, const ResourceFactory&)
; |
77 | 77 |
78 Resource* cachedResource(const KURL&) const; | 78 Resource* cachedResource(const KURL&) const; |
79 | 79 |
80 typedef HashMap<String, ResourcePtr<Resource>> DocumentResourceMap; | 80 typedef HashMap<String, ResourcePtr<Resource>> DocumentResourceMap; |
81 const DocumentResourceMap& allResources() const { return m_documentResources
; } | 81 const DocumentResourceMap& allResources() const { return m_documentResources
; } |
82 | 82 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 142 |
143 String getCacheIdentifier() const; | 143 String getCacheIdentifier() const; |
144 | 144 |
145 void scheduleDocumentResourcesGC(); | 145 void scheduleDocumentResourcesGC(); |
146 bool clientDefersImage(const KURL&) const; | 146 bool clientDefersImage(const KURL&) const; |
147 void determineRequestContext(ResourceRequest&, Resource::Type); | 147 void determineRequestContext(ResourceRequest&, Resource::Type); |
148 | 148 |
149 private: | 149 private: |
150 friend class ResourceCacheValidationSuppressor; | 150 friend class ResourceCacheValidationSuppressor; |
151 | 151 |
152 explicit ResourceFetcher(PassOwnPtrWillBeRawPtr<FetchContext>); | 152 explicit ResourceFetcher(FetchContext*); |
153 | 153 |
154 ResourcePtr<Resource> createResourceForRevalidation(const FetchRequest&, Res
ource*, const ResourceFactory&); | 154 ResourcePtr<Resource> createResourceForRevalidation(const FetchRequest&, Res
ource*, const ResourceFactory&); |
155 ResourcePtr<Resource> createResourceForLoading(FetchRequest&, const String&
charset, const ResourceFactory&); | 155 ResourcePtr<Resource> createResourceForLoading(FetchRequest&, const String&
charset, const ResourceFactory&); |
156 void storeResourceTimingInitiatorInformation(Resource*); | 156 void storeResourceTimingInitiatorInformation(Resource*); |
157 bool scheduleArchiveLoad(Resource*, const ResourceRequest&); | 157 bool scheduleArchiveLoad(Resource*, const ResourceRequest&); |
158 | 158 |
159 enum RevalidationPolicy { Use, Revalidate, Reload, Load }; | 159 enum RevalidationPolicy { Use, Revalidate, Reload, Load }; |
160 RevalidationPolicy determineRevalidationPolicy(Resource::Type, const FetchRe
quest&, Resource* existingResource) const; | 160 RevalidationPolicy determineRevalidationPolicy(Resource::Type, const FetchRe
quest&, Resource* existingResource) const; |
161 | 161 |
162 void addAdditionalRequestHeaders(ResourceRequest&, Resource::Type); | 162 void addAdditionalRequestHeaders(ResourceRequest&, Resource::Type); |
163 | 163 |
164 static bool resourceNeedsLoad(Resource*, const FetchRequest&, RevalidationPo
licy); | 164 static bool resourceNeedsLoad(Resource*, const FetchRequest&, RevalidationPo
licy); |
165 | 165 |
166 void notifyLoadedFromMemoryCache(Resource*); | 166 void notifyLoadedFromMemoryCache(Resource*); |
167 | 167 |
168 void garbageCollectDocumentResourcesTimerFired(Timer<ResourceFetcher>*); | 168 void garbageCollectDocumentResourcesTimerFired(Timer<ResourceFetcher>*); |
169 | 169 |
170 void resourceTimingReportTimerFired(Timer<ResourceFetcher>*); | 170 void resourceTimingReportTimerFired(Timer<ResourceFetcher>*); |
171 | 171 |
172 void reloadImagesIfNotDeferred(); | 172 void reloadImagesIfNotDeferred(); |
173 | 173 |
174 void willTerminateResourceLoader(ResourceLoader*); | 174 void willTerminateResourceLoader(ResourceLoader*); |
175 | 175 |
176 OwnPtrWillBeMember<FetchContext> m_context; | 176 Member<FetchContext> m_context; |
177 | 177 |
178 HashSet<String> m_validatedURLs; | 178 HashSet<String> m_validatedURLs; |
179 mutable DocumentResourceMap m_documentResources; | 179 mutable DocumentResourceMap m_documentResources; |
180 | 180 |
181 OwnPtr<ListHashSet<Resource*>> m_preloads; | 181 OwnPtr<ListHashSet<Resource*>> m_preloads; |
182 OwnPtrWillBeMember<ArchiveResourceCollection> m_archiveResourceCollection; | 182 OwnPtrWillBeMember<ArchiveResourceCollection> m_archiveResourceCollection; |
183 | 183 |
184 Timer<ResourceFetcher> m_garbageCollectDocumentResourcesTimer; | 184 Timer<ResourceFetcher> m_garbageCollectDocumentResourcesTimer; |
185 Timer<ResourceFetcher> m_resourceTimingReportTimer; | 185 Timer<ResourceFetcher> m_resourceTimingReportTimer; |
186 | 186 |
187 typedef HashMap<Resource*, OwnPtr<ResourceTimingInfo>> ResourceTimingInfoMap
; | 187 typedef HashMap<Resource*, OwnPtr<ResourceTimingInfo>> ResourceTimingInfoMap
; |
188 ResourceTimingInfoMap m_resourceTimingInfoMap; | 188 ResourceTimingInfoMap m_resourceTimingInfoMap; |
189 | 189 |
190 Vector<OwnPtr<ResourceTimingInfo>> m_scheduledResourceTimingReports; | 190 Vector<OwnPtr<ResourceTimingInfo>> m_scheduledResourceTimingReports; |
191 | 191 |
192 OwnPtrWillBeMember<ResourceLoaderSet> m_loaders; | 192 Member<ResourceLoaderSet> m_loaders; |
193 OwnPtrWillBeMember<ResourceLoaderSet> m_nonBlockingLoaders; | 193 Member<ResourceLoaderSet> m_nonBlockingLoaders; |
194 | 194 |
195 // Used in hit rate histograms. | 195 // Used in hit rate histograms. |
196 class DeadResourceStatsRecorder { | 196 class DeadResourceStatsRecorder { |
197 public: | 197 public: |
198 DeadResourceStatsRecorder(); | 198 DeadResourceStatsRecorder(); |
199 ~DeadResourceStatsRecorder(); | 199 ~DeadResourceStatsRecorder(); |
200 | 200 |
201 void update(RevalidationPolicy); | 201 void update(RevalidationPolicy); |
202 | 202 |
203 private: | 203 private: |
(...skipping 21 matching lines...) Expand all Loading... |
225 m_previousState = m_loader->m_allowStaleResources; | 225 m_previousState = m_loader->m_allowStaleResources; |
226 m_loader->m_allowStaleResources = true; | 226 m_loader->m_allowStaleResources = true; |
227 } | 227 } |
228 } | 228 } |
229 ~ResourceCacheValidationSuppressor() | 229 ~ResourceCacheValidationSuppressor() |
230 { | 230 { |
231 if (m_loader) | 231 if (m_loader) |
232 m_loader->m_allowStaleResources = m_previousState; | 232 m_loader->m_allowStaleResources = m_previousState; |
233 } | 233 } |
234 private: | 234 private: |
235 RawPtrWillBeMember<ResourceFetcher> m_loader; | 235 Member<ResourceFetcher> m_loader; |
236 bool m_previousState; | 236 bool m_previousState; |
237 }; | 237 }; |
238 | 238 |
239 } // namespace blink | 239 } // namespace blink |
240 | 240 |
241 #endif // ResourceFetcher_h | 241 #endif // ResourceFetcher_h |
OLD | NEW |