Changeset 163318 in webkit
- Timestamp:
- Feb 3, 2014 11:34:30 AM (10 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r163317 r163318 1 2014-02-03 David Kilzer <ddkilzer@apple.com> 2 3 Remove CachedImageManual class 4 <http://webkit.org/b/128043> 5 6 Reviewed by Darin Adler. 7 8 Get rid of the CachedImageManual class by inlining its 9 functionality into CachedImage. This makes it possible to 10 de-virtual-ize isManual() (renamed to isManuallyCached()) and to 11 make CachedImage final. The size of CachedImage does not 12 increase because we turn an existing bool into a bitfield to add 13 an m_isManuallyCached bit, and create a static CachedImageClient 14 in MemoryCache.cpp as the "fake" client to keep the manually 15 cached image alive in the cache. 16 17 * loader/cache/CachedImage.cpp: 18 (WebCore::CachedImage::CachedImage): Set m_isManuallyCached 19 bitfield. For one overloaded constructor, move the 20 CachedImageManual code into the CachedImage constructor. 21 (WebCore::CachedImageManual::CachedImageManual): Remove. 22 (WebCore::CachedImage::mustRevalidateDueToCacheHeaders): Move 23 method from CachedImageManual to CachedImage, and put 24 ManuallyCached behavior behind a check. 25 * loader/cache/CachedImage.h: Update includes. Make CachedImage 26 final. Add CachedImage::CacheBehaviorType enum when manually 27 cached images are created. Move CachedImageManual methods into 28 CachedImage, remove addFakeClient() and removeFakeClient() 29 methods (MemoryCache methods use addClient() and removeClient() 30 with a static CachedImageClient), and remove the 31 CachedImageManual class definition. Change 32 m_shouldPaintBrokenImage to a bitfield and add 33 m_isManuallyCached bitfield. 34 35 * loader/cache/MemoryCache.cpp: 36 (WebCore::MemoryCache::addImageToCache): Use std::unique_ptr and 37 remove useless NULL check after calling CachedImage constructor. 38 (WebCore::MemoryCache::removeImageFromCache): 39 - Update to use CachedImage class instead of CachedImageManual. 40 1 41 2014-02-03 Zan Dobersek <zdobersek@igalia.com> 2 42 -
trunk/Source/WebCore/loader/cache/CachedImage.cpp
r163148 r163318 67 67 : CachedResource(resourceRequest, ImageResource) 68 68 , m_image(0) 69 , m_isManuallyCached(false) 69 70 , m_shouldPaintBrokenImage(true) 70 71 { … … 75 76 : CachedResource(ResourceRequest(), ImageResource) 76 77 , m_image(image) 78 , m_isManuallyCached(false) 77 79 , m_shouldPaintBrokenImage(true) 78 80 { … … 81 83 } 82 84 83 CachedImage::CachedImage(const URL& url, Image* image )85 CachedImage::CachedImage(const URL& url, Image* image, CachedImage::CacheBehaviorType type) 84 86 : CachedResource(ResourceRequest(url), ImageResource) 85 87 , m_image(image) 88 , m_isManuallyCached(type == CachedImage::ManuallyCached) 86 89 , m_shouldPaintBrokenImage(true) 87 90 { 88 91 setStatus(Cached); 89 92 setLoading(false); 93 if (UNLIKELY(isManuallyCached())) { 94 // Use the incoming URL in the response field. This ensures that code 95 // using the response directly, such as origin checks for security, 96 // actually see something. 97 m_response.setURL(url); 98 } 90 99 } 91 100 … … 613 622 } 614 623 615 #if USE(CF) 616 // FIXME: We should look to incorporate the functionality of CachedImageManual 617 // into CachedImage or find a better place for this class. 618 // FIXME: Remove the USE(CF) once we make MemoryCache::addImageToCache() platform-independent. 619 CachedImageManual::CachedImageManual(const URL& url, Image* image) 620 : CachedImage(url, image) 621 , m_fakeClient(std::make_unique<CachedImageClient>()) 622 { 623 // Use the incoming URL in the response field. This ensures that code 624 // using the response directly, such as origin checks for security, 625 // actually see something. 626 m_response.setURL(url); 627 } 628 629 bool CachedImageManual::mustRevalidateDueToCacheHeaders(CachePolicy) const 630 { 631 // Do not revalidate manually cached images. This mechanism is used as a 632 // way to efficiently share an image from the client to content and 633 // the URL for that image may not represent a resource that can be 634 // retrieved by standard means. If the manual caching SPI is used, it is 635 // incumbent on the client to only use valid resources. 636 return false; 637 } 638 #endif 624 bool CachedImage::mustRevalidateDueToCacheHeaders(CachePolicy policy) const 625 { 626 if (UNLIKELY(isManuallyCached())) { 627 // Do not revalidate manually cached images. This mechanism is used as a 628 // way to efficiently share an image from the client to content and 629 // the URL for that image may not represent a resource that can be 630 // retrieved by standard means. If the manual caching SPI is used, it is 631 // incumbent on the client to only use valid resources. 632 return false; 633 } 634 return CachedResource::mustRevalidateDueToCacheHeaders(policy); 635 } 639 636 640 637 } // namespace WebCore -
trunk/Source/WebCore/loader/cache/CachedImage.h
r163242 r163318 45 45 struct Length; 46 46 47 class CachedImage : public CachedResource, public ImageObserver {47 class CachedImage final : public CachedResource, public ImageObserver { 48 48 friend class MemoryCache; 49 49 50 50 public: 51 enum CacheBehaviorType { AutomaticallyCached, ManuallyCached }; 52 51 53 CachedImage(const ResourceRequest&); 52 54 CachedImage(Image*); 53 CachedImage(const URL&, Image* );55 CachedImage(const URL&, Image*, CacheBehaviorType = AutomaticallyCached); 54 56 virtual ~CachedImage(); 55 57 … … 80 82 void computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio); 81 83 82 #if USE(CF) 83 // FIXME: Remove the USE(CF) once we make MemoryCache::addImageToCache() platform-independent. 84 virtual bool isManual() const { return false; } 85 #endif 84 bool isManuallyCached() const { return m_isManuallyCached; } 85 virtual bool mustRevalidateDueToCacheHeaders(CachePolicy) const; 86 86 87 87 static void resumeAnimatingImagesForLoader(CachedResourceLoader*); … … 143 143 std::unique_ptr<SVGImageCache> m_svgImageCache; 144 144 #endif 145 bool m_shouldPaintBrokenImage; 145 unsigned char m_isManuallyCached : 1; 146 unsigned char m_shouldPaintBrokenImage : 1; 146 147 }; 147 148 148 #if USE(CF)149 // FIXME: We should look to incorporate the functionality of CachedImageManual150 // into CachedImage or find a better place for this class.151 // FIXME: Remove the USE(CF) once we make MemoryCache::addImageToCache() platform-independent.152 class CachedImageManual final : public CachedImage {153 public:154 CachedImageManual(const URL&, Image*);155 void addFakeClient() { addClient(m_fakeClient.get()); }156 void removeFakeClient() { removeClient(m_fakeClient.get()); }157 virtual bool isManual() const override { return true; }158 virtual bool mustRevalidateDueToCacheHeaders(CachePolicy) const;159 private:160 std::unique_ptr<CachedResourceClient> m_fakeClient;161 };162 #endif163 164 149 CACHED_RESOURCE_TYPE_CASTS(CachedImage, CachedResource, CachedResource::ImageResource) 165 #if USE(CF)166 TYPE_CASTS_BASE(CachedImageManual, CachedImage, resource, resource->isManual(), resource.isManual())167 #endif168 150 169 151 } -
trunk/Source/WebCore/loader/cache/MemoryCache.cpp
r163148 r163318 26 26 #include "BitmapImage.h" 27 27 #include "CachedImage.h" 28 #include "CachedImageClient.h" 28 29 #include "CachedResource.h" 29 30 #include "CachedResourceHandle.h" … … 216 217 // FIXME: Remove the USE(CG) once we either make NativeImagePtr a smart pointer on all platforms or 217 218 // remove the usage of CFRetain() in MemoryCache::addImageToCache() so as to make the code platform-independent. 219 static CachedImageClient& dummyCachedImageClient() 220 { 221 DEFINE_STATIC_LOCAL(CachedImageClient, client, ()); 222 return client; 223 } 224 218 225 bool MemoryCache::addImageToCache(NativeImagePtr image, const URL& url, const String& cachePartition) 219 226 { … … 225 232 return false; 226 233 227 CachedImageManual* cachedImage = new CachedImageManual(url, bitmapImage.get()); 228 if (!cachedImage) 229 return false; 234 std::unique_ptr<CachedImage> cachedImage = std::make_unique<CachedImage>(url, bitmapImage.get(), CachedImage::ManuallyCached); 230 235 231 236 // Actual release of the CGImageRef is done in BitmapImage. 232 237 CFRetain(image); 233 cachedImage->add FakeClient();238 cachedImage->addClient(&dummyCachedImageClient()); 234 239 cachedImage->setDecodedSize(bitmapImage->decodedSize()); 235 240 #if ENABLE(CACHE_PARTITIONING) 236 241 cachedImage->resourceRequest().setCachePartition(cachePartition); 237 242 #endif 238 add(cachedImage );243 add(cachedImage.release()); 239 244 return true; 240 245 } … … 256 261 257 262 // A resource exists and is not a manually cached image, so just remove it. 258 if (!resource->isImage() || !toCachedImage(resource)->isManual ()) {263 if (!resource->isImage() || !toCachedImage(resource)->isManuallyCached()) { 259 264 evict(resource); 260 265 return; … … 266 271 // removing the last client triggers a MemoryCache::prune, so the 267 272 // resource may be deleted after this call. 268 toCachedImage Manual(toCachedImage(resource))->removeFakeClient();273 toCachedImage(resource)->removeClient(&dummyCachedImageClient()); 269 274 } 270 275 #endif
Note: See TracChangeset
for help on using the changeset viewer.