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) 2006 Samuel Weinig (sam.weinig@gmail.com) | 4 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
rights reserved. | 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
rights reserved. |
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. |
11 | 11 |
12 This library is distributed in the hope that it will be useful, | 12 This library is distributed in the hope that it will be useful, |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 Library General Public License for more details. | 15 Library General Public License for more details. |
16 | 16 |
17 You should have received a copy of the GNU Library General Public License | 17 You should have received a copy of the GNU Library General Public License |
18 along with this library; see the file COPYING.LIB. If not, write to | 18 along with this library; see the file COPYING.LIB. If not, write to |
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 Boston, MA 02110-1301, USA. | 20 Boston, MA 02110-1301, USA. |
21 */ | 21 */ |
22 | 22 |
23 #ifndef Resource_h | 23 #ifndef Resource_h |
24 #define Resource_h | 24 #define Resource_h |
25 | 25 |
| 26 #include "core/fetch/CachedMetadataHandler.h" |
26 #include "core/fetch/ResourceLoaderOptions.h" | 27 #include "core/fetch/ResourceLoaderOptions.h" |
27 #include "platform/Timer.h" | 28 #include "platform/Timer.h" |
28 #include "platform/network/ResourceError.h" | 29 #include "platform/network/ResourceError.h" |
29 #include "platform/network/ResourceLoadPriority.h" | 30 #include "platform/network/ResourceLoadPriority.h" |
30 #include "platform/network/ResourceRequest.h" | 31 #include "platform/network/ResourceRequest.h" |
31 #include "platform/network/ResourceResponse.h" | 32 #include "platform/network/ResourceResponse.h" |
32 #include "public/platform/WebDataConsumerHandle.h" | 33 #include "public/platform/WebDataConsumerHandle.h" |
33 #include "wtf/HashCountedSet.h" | 34 #include "wtf/HashCountedSet.h" |
34 #include "wtf/HashSet.h" | 35 #include "wtf/HashSet.h" |
35 #include "wtf/OwnPtr.h" | 36 #include "wtf/OwnPtr.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 }; | 77 }; |
77 | 78 |
78 enum Status { | 79 enum Status { |
79 Unknown, // let cache decide what to do with it | 80 Unknown, // let cache decide what to do with it |
80 Pending, // only partially loaded | 81 Pending, // only partially loaded |
81 Cached, // regular case | 82 Cached, // regular case |
82 LoadError, | 83 LoadError, |
83 DecodeError | 84 DecodeError |
84 }; | 85 }; |
85 | 86 |
86 enum MetadataCacheType { | |
87 SendToPlatform, // send cache data to blink::Platform::cacheMetadata | |
88 CacheLocally // cache only in Resource's member variables | |
89 }; | |
90 | |
91 Resource(const ResourceRequest&, Type); | 87 Resource(const ResourceRequest&, Type); |
92 #if ENABLE(OILPAN) | 88 #if ENABLE(OILPAN) |
93 virtual ~Resource(); | 89 virtual ~Resource(); |
94 #else | 90 #else |
95 protected: | 91 protected: |
96 // Only deleteIfPossible should delete this. | 92 // Only deleteIfPossible should delete this. |
97 virtual ~Resource(); | 93 virtual ~Resource(); |
98 public: | 94 public: |
99 #endif | 95 #endif |
100 virtual void dispose(); | 96 virtual void dispose(); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 virtual void willFollowRedirect(ResourceRequest&, const ResourceResponse&); | 187 virtual void willFollowRedirect(ResourceRequest&, const ResourceResponse&); |
192 | 188 |
193 virtual void updateRequest(const ResourceRequest&) { } | 189 virtual void updateRequest(const ResourceRequest&) { } |
194 virtual void responseReceived(const ResourceResponse&, PassOwnPtr<WebDataCon
sumerHandle>); | 190 virtual void responseReceived(const ResourceResponse&, PassOwnPtr<WebDataCon
sumerHandle>); |
195 void setResponse(const ResourceResponse& response) { m_response = response;
} | 191 void setResponse(const ResourceResponse& response) { m_response = response;
} |
196 const ResourceResponse& response() const { return m_response; } | 192 const ResourceResponse& response() const { return m_response; } |
197 | 193 |
198 // Sets the serialized metadata retrieved from the platform's cache. | 194 // Sets the serialized metadata retrieved from the platform's cache. |
199 virtual void setSerializedCachedMetadata(const char*, size_t); | 195 virtual void setSerializedCachedMetadata(const char*, size_t); |
200 | 196 |
201 // Caches the given metadata in association with this resource and suggests | 197 // This may return nullptr when the resource isn't cacheable. |
202 // that the platform persist it. The dataTypeID is a pseudo-randomly chosen | 198 CachedMetadataHandler* cacheHandler(); |
203 // identifier that is used to distinguish data generated by the caller. | |
204 void setCachedMetadata(unsigned dataTypeID, const char*, size_t, MetadataCac
heType = SendToPlatform); | |
205 | |
206 // Reset existing metadata, to allow setting new data. | |
207 void clearCachedMetadata(MetadataCacheType = CacheLocally); | |
208 | |
209 // Returns cached metadata of the given type associated with this resource. | |
210 CachedMetadata* cachedMetadata(unsigned dataTypeID) const; | |
211 | 199 |
212 bool hasOneHandle() const; | 200 bool hasOneHandle() const; |
213 bool canDelete() const; | 201 bool canDelete() const; |
214 | 202 |
215 // List of acceptable MIME types separated by ",". | 203 // List of acceptable MIME types separated by ",". |
216 // A MIME type may contain a wildcard, e.g. "text/*". | 204 // A MIME type may contain a wildcard, e.g. "text/*". |
217 AtomicString accept() const { return m_accept; } | 205 AtomicString accept() const { return m_accept; } |
218 void setAccept(const AtomicString& accept) { m_accept = accept; } | 206 void setAccept(const AtomicString& accept) { m_accept = accept; } |
219 | 207 |
220 bool wasCanceled() const { return m_error.isCancellation(); } | 208 bool wasCanceled() const { return m_error.isCancellation(); } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 RefPtrWillBeMember<ResourceLoader> m_loader; | 332 RefPtrWillBeMember<ResourceLoader> m_loader; |
345 ResourceLoaderOptions m_options; | 333 ResourceLoaderOptions m_options; |
346 | 334 |
347 ResourceResponse m_response; | 335 ResourceResponse m_response; |
348 double m_responseTimestamp; | 336 double m_responseTimestamp; |
349 | 337 |
350 RefPtr<SharedBuffer> m_data; | 338 RefPtr<SharedBuffer> m_data; |
351 Timer<Resource> m_cancelTimer; | 339 Timer<Resource> m_cancelTimer; |
352 | 340 |
353 private: | 341 private: |
| 342 class CacheHandler; |
354 bool addClientToSet(ResourceClient*); | 343 bool addClientToSet(ResourceClient*); |
355 void cancelTimerFired(Timer<Resource>*); | 344 void cancelTimerFired(Timer<Resource>*); |
356 | 345 |
357 void revalidationSucceeded(const ResourceResponse&); | 346 void revalidationSucceeded(const ResourceResponse&); |
358 void revalidationFailed(); | 347 void revalidationFailed(); |
359 | 348 |
360 bool unlock(); | 349 bool unlock(); |
361 | 350 |
362 bool hasRightHandleCountApartFromCache(unsigned targetCount) const; | 351 bool hasRightHandleCountApartFromCache(unsigned targetCount) const; |
363 | 352 |
364 void failBeforeStarting(); | 353 void failBeforeStarting(); |
365 | 354 |
| 355 void setCachedMetadata(unsigned dataTypeID, const char*, size_t, CachedMetad
ataHandler::CacheType); |
| 356 void clearCachedMetadata(CachedMetadataHandler::CacheType); |
| 357 CachedMetadata* cachedMetadata(unsigned dataTypeID) const; |
| 358 |
366 String m_fragmentIdentifierForRequest; | 359 String m_fragmentIdentifierForRequest; |
367 | 360 |
368 RefPtr<CachedMetadata> m_cachedMetadata; | 361 RefPtr<CachedMetadata> m_cachedMetadata; |
| 362 OwnPtr<CacheHandler> m_cacheHandler; |
369 | 363 |
370 ResourceError m_error; | 364 ResourceError m_error; |
371 | 365 |
372 double m_loadFinishTime; | 366 double m_loadFinishTime; |
373 | 367 |
374 unsigned long m_identifier; | 368 unsigned long m_identifier; |
375 | 369 |
376 size_t m_encodedSize; | 370 size_t m_encodedSize; |
377 size_t m_decodedSize; | 371 size_t m_decodedSize; |
378 unsigned m_handleCount; | 372 unsigned m_handleCount; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 const char* ResourceTypeName(Resource::Type); | 416 const char* ResourceTypeName(Resource::Type); |
423 #endif | 417 #endif |
424 | 418 |
425 #define DEFINE_RESOURCE_TYPE_CASTS(typeName) \ | 419 #define DEFINE_RESOURCE_TYPE_CASTS(typeName) \ |
426 DEFINE_TYPE_CASTS(typeName##Resource, Resource, resource, resource->type() =
= Resource::typeName, resource.type() == Resource::typeName); \ | 420 DEFINE_TYPE_CASTS(typeName##Resource, Resource, resource, resource->type() =
= Resource::typeName, resource.type() == Resource::typeName); \ |
427 inline typeName##Resource* to##typeName##Resource(const ResourcePtr<Resource
>& ptr) { return to##typeName##Resource(ptr.get()); } | 421 inline typeName##Resource* to##typeName##Resource(const ResourcePtr<Resource
>& ptr) { return to##typeName##Resource(ptr.get()); } |
428 | 422 |
429 } | 423 } |
430 | 424 |
431 #endif | 425 #endif |
OLD | NEW |