Title: [163318] trunk/Source/WebCore
Revision
163318
Author
ddkil...@apple.com
Date
2014-02-03 11:34:30 -0800 (Mon, 03 Feb 2014)

Log Message

Remove CachedImageManual class
<http://webkit.org/b/128043>

Reviewed by Darin Adler.

Get rid of the CachedImageManual class by inlining its
functionality into CachedImage.  This makes it possible to
de-virtual-ize isManual() (renamed to isManuallyCached()) and to
make CachedImage final.  The size of CachedImage does not
increase because we turn an existing bool into a bitfield to add
an m_isManuallyCached bit, and create a static CachedImageClient
in MemoryCache.cpp as the "fake" client to keep the manually
cached image alive in the cache.

* loader/cache/CachedImage.cpp:
(WebCore::CachedImage::CachedImage): Set m_isManuallyCached
bitfield.  For one overloaded constructor, move the
CachedImageManual code into the CachedImage constructor.
(WebCore::CachedImageManual::CachedImageManual): Remove.
(WebCore::CachedImage::mustRevalidateDueToCacheHeaders): Move
method from CachedImageManual to CachedImage, and put
ManuallyCached behavior behind a check.
* loader/cache/CachedImage.h: Update includes.  Make CachedImage
final.  Add CachedImage::CacheBehaviorType enum when manually
cached images are created.  Move CachedImageManual methods into
CachedImage, remove addFakeClient() and removeFakeClient()
methods (MemoryCache methods use addClient() and removeClient()
with a static CachedImageClient), and remove the
CachedImageManual class definition.  Change
m_shouldPaintBrokenImage to a bitfield and add
m_isManuallyCached bitfield.

* loader/cache/MemoryCache.cpp:
(WebCore::MemoryCache::addImageToCache): Use std::unique_ptr and
remove useless NULL check after calling CachedImage constructor.
(WebCore::MemoryCache::removeImageFromCache):
- Update to use CachedImage class instead of CachedImageManual.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (163317 => 163318)


--- trunk/Source/WebCore/ChangeLog	2014-02-03 19:07:29 UTC (rev 163317)
+++ trunk/Source/WebCore/ChangeLog	2014-02-03 19:34:30 UTC (rev 163318)
@@ -1,3 +1,43 @@
+2014-02-03  David Kilzer  <ddkil...@apple.com>
+
+        Remove CachedImageManual class
+        <http://webkit.org/b/128043>
+
+        Reviewed by Darin Adler.
+
+        Get rid of the CachedImageManual class by inlining its
+        functionality into CachedImage.  This makes it possible to
+        de-virtual-ize isManual() (renamed to isManuallyCached()) and to
+        make CachedImage final.  The size of CachedImage does not
+        increase because we turn an existing bool into a bitfield to add
+        an m_isManuallyCached bit, and create a static CachedImageClient
+        in MemoryCache.cpp as the "fake" client to keep the manually
+        cached image alive in the cache.
+
+        * loader/cache/CachedImage.cpp:
+        (WebCore::CachedImage::CachedImage): Set m_isManuallyCached
+        bitfield.  For one overloaded constructor, move the
+        CachedImageManual code into the CachedImage constructor.
+        (WebCore::CachedImageManual::CachedImageManual): Remove.
+        (WebCore::CachedImage::mustRevalidateDueToCacheHeaders): Move
+        method from CachedImageManual to CachedImage, and put
+        ManuallyCached behavior behind a check.
+        * loader/cache/CachedImage.h: Update includes.  Make CachedImage
+        final.  Add CachedImage::CacheBehaviorType enum when manually
+        cached images are created.  Move CachedImageManual methods into
+        CachedImage, remove addFakeClient() and removeFakeClient()
+        methods (MemoryCache methods use addClient() and removeClient()
+        with a static CachedImageClient), and remove the
+        CachedImageManual class definition.  Change
+        m_shouldPaintBrokenImage to a bitfield and add
+        m_isManuallyCached bitfield.
+
+        * loader/cache/MemoryCache.cpp:
+        (WebCore::MemoryCache::addImageToCache): Use std::unique_ptr and
+        remove useless NULL check after calling CachedImage constructor.
+        (WebCore::MemoryCache::removeImageFromCache):
+        - Update to use CachedImage class instead of CachedImageManual.
+
 2014-02-03  Zan Dobersek  <zdober...@igalia.com>
 
         Move the webdatabase module source code to std::unique_ptr

Modified: trunk/Source/WebCore/loader/cache/CachedImage.cpp (163317 => 163318)


--- trunk/Source/WebCore/loader/cache/CachedImage.cpp	2014-02-03 19:07:29 UTC (rev 163317)
+++ trunk/Source/WebCore/loader/cache/CachedImage.cpp	2014-02-03 19:34:30 UTC (rev 163318)
@@ -66,6 +66,7 @@
 CachedImage::CachedImage(const ResourceRequest& resourceRequest)
     : CachedResource(resourceRequest, ImageResource)
     , m_image(0)
+    , m_isManuallyCached(false)
     , m_shouldPaintBrokenImage(true)
 {
     setStatus(Unknown);
@@ -74,19 +75,27 @@
 CachedImage::CachedImage(Image* image)
     : CachedResource(ResourceRequest(), ImageResource)
     , m_image(image)
+    , m_isManuallyCached(false)
     , m_shouldPaintBrokenImage(true)
 {
     setStatus(Cached);
     setLoading(false);
 }
 
-CachedImage::CachedImage(const URL& url, Image* image)
+CachedImage::CachedImage(const URL& url, Image* image, CachedImage::CacheBehaviorType type)
     : CachedResource(ResourceRequest(url), ImageResource)
     , m_image(image)
+    , m_isManuallyCached(type == CachedImage::ManuallyCached)
     , m_shouldPaintBrokenImage(true)
 {
     setStatus(Cached);
     setLoading(false);
+    if (UNLIKELY(isManuallyCached())) {
+        // Use the incoming URL in the response field. This ensures that code
+        // using the response directly, such as origin checks for security,
+        // actually see something.
+        m_response.setURL(url);
+    }
 }
 
 CachedImage::~CachedImage()
@@ -612,29 +621,17 @@
     return !securityOrigin->taintsCanvas(response().url());
 }
 
-#if USE(CF)
-// FIXME: We should look to incorporate the functionality of CachedImageManual
-// into CachedImage or find a better place for this class.
-// FIXME: Remove the USE(CF) once we make MemoryCache::addImageToCache() platform-independent.
-CachedImageManual::CachedImageManual(const URL& url, Image* image)
-    : CachedImage(url, image)
-    , m_fakeClient(std::make_unique<CachedImageClient>())
+bool CachedImage::mustRevalidateDueToCacheHeaders(CachePolicy policy) const
 {
-    // Use the incoming URL in the response field. This ensures that code
-    // using the response directly, such as origin checks for security,
-    // actually see something.
-    m_response.setURL(url);
+    if (UNLIKELY(isManuallyCached())) {
+        // Do not revalidate manually cached images. This mechanism is used as a
+        // way to efficiently share an image from the client to content and
+        // the URL for that image may not represent a resource that can be
+        // retrieved by standard means. If the manual caching SPI is used, it is
+        // incumbent on the client to only use valid resources.
+        return false;
+    }
+    return CachedResource::mustRevalidateDueToCacheHeaders(policy);
 }
 
-bool CachedImageManual::mustRevalidateDueToCacheHeaders(CachePolicy) const
-{
-    // Do not revalidate manually cached images. This mechanism is used as a
-    // way to efficiently share an image from the client to content and
-    // the URL for that image may not represent a resource that can be
-    // retrieved by standard means. If the manual caching SPI is used, it is
-    // incumbent on the client to only use valid resources.
-    return false;
-}
-#endif
-
 } // namespace WebCore

Modified: trunk/Source/WebCore/loader/cache/CachedImage.h (163317 => 163318)


--- trunk/Source/WebCore/loader/cache/CachedImage.h	2014-02-03 19:07:29 UTC (rev 163317)
+++ trunk/Source/WebCore/loader/cache/CachedImage.h	2014-02-03 19:34:30 UTC (rev 163318)
@@ -44,13 +44,15 @@
 
 struct Length;
 
-class CachedImage : public CachedResource, public ImageObserver {
+class CachedImage final : public CachedResource, public ImageObserver {
     friend class MemoryCache;
 
 public:
+    enum CacheBehaviorType { AutomaticallyCached, ManuallyCached };
+
     CachedImage(const ResourceRequest&);
     CachedImage(Image*);
-    CachedImage(const URL&, Image*);
+    CachedImage(const URL&, Image*, CacheBehaviorType = AutomaticallyCached);
     virtual ~CachedImage();
 
     Image* image(); // Returns the nullImage() if the image is not available yet.
@@ -79,10 +81,8 @@
     LayoutSize imageSizeForRenderer(const RenderObject*, float multiplier, SizeType = UsedSize); // returns the size of the complete image.
     void computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio);
 
-#if USE(CF)
-    // FIXME: Remove the USE(CF) once we make MemoryCache::addImageToCache() platform-independent.
-    virtual bool isManual() const { return false; }
-#endif
+    bool isManuallyCached() const { return m_isManuallyCached; }
+    virtual bool mustRevalidateDueToCacheHeaders(CachePolicy) const;
 
     static void resumeAnimatingImagesForLoader(CachedResourceLoader*);
 
@@ -142,29 +142,11 @@
 #if ENABLE(SVG)
     std::unique_ptr<SVGImageCache> m_svgImageCache;
 #endif
-    bool m_shouldPaintBrokenImage;
+    unsigned char m_isManuallyCached : 1;
+    unsigned char m_shouldPaintBrokenImage : 1;
 };
 
-#if USE(CF)
-// FIXME: We should look to incorporate the functionality of CachedImageManual
-// into CachedImage or find a better place for this class.
-// FIXME: Remove the USE(CF) once we make MemoryCache::addImageToCache() platform-independent.
-class CachedImageManual final : public CachedImage {
-public:
-    CachedImageManual(const URL&, Image*);
-    void addFakeClient() { addClient(m_fakeClient.get()); }
-    void removeFakeClient() { removeClient(m_fakeClient.get()); }
-    virtual bool isManual() const override { return true; }
-    virtual bool mustRevalidateDueToCacheHeaders(CachePolicy) const;
-private:
-    std::unique_ptr<CachedResourceClient> m_fakeClient;
-};
-#endif
-
 CACHED_RESOURCE_TYPE_CASTS(CachedImage, CachedResource, CachedResource::ImageResource)
-#if USE(CF)
-TYPE_CASTS_BASE(CachedImageManual, CachedImage, resource, resource->isManual(), resource.isManual())
-#endif
 
 }
 

Modified: trunk/Source/WebCore/loader/cache/MemoryCache.cpp (163317 => 163318)


--- trunk/Source/WebCore/loader/cache/MemoryCache.cpp	2014-02-03 19:07:29 UTC (rev 163317)
+++ trunk/Source/WebCore/loader/cache/MemoryCache.cpp	2014-02-03 19:34:30 UTC (rev 163318)
@@ -25,6 +25,7 @@
 
 #include "BitmapImage.h"
 #include "CachedImage.h"
+#include "CachedImageClient.h"
 #include "CachedResource.h"
 #include "CachedResourceHandle.h"
 #include "CrossThreadTask.h"
@@ -215,6 +216,12 @@
 #if USE(CG)
 // FIXME: Remove the USE(CG) once we either make NativeImagePtr a smart pointer on all platforms or
 // remove the usage of CFRetain() in MemoryCache::addImageToCache() so as to make the code platform-independent.
+static CachedImageClient& dummyCachedImageClient()
+{
+    DEFINE_STATIC_LOCAL(CachedImageClient, client, ());
+    return client;
+}
+
 bool MemoryCache::addImageToCache(NativeImagePtr image, const URL& url, const String& cachePartition)
 {
     ASSERT(image);
@@ -224,18 +231,16 @@
     if (!bitmapImage)
         return false;
 
-    CachedImageManual* cachedImage = new CachedImageManual(url, bitmapImage.get());
-    if (!cachedImage)
-        return false;
+    std::unique_ptr<CachedImage> cachedImage = std::make_unique<CachedImage>(url, bitmapImage.get(), CachedImage::ManuallyCached);
 
     // Actual release of the CGImageRef is done in BitmapImage.
     CFRetain(image);
-    cachedImage->addFakeClient();
+    cachedImage->addClient(&dummyCachedImageClient());
     cachedImage->setDecodedSize(bitmapImage->decodedSize());
 #if ENABLE(CACHE_PARTITIONING)
     cachedImage->resourceRequest().setCachePartition(cachePartition);
 #endif
-    add(cachedImage);
+    add(cachedImage.release());
     return true;
 }
 
@@ -255,7 +260,7 @@
         return;
 
     // A resource exists and is not a manually cached image, so just remove it.
-    if (!resource->isImage() || !toCachedImage(resource)->isManual()) {
+    if (!resource->isImage() || !toCachedImage(resource)->isManuallyCached()) {
         evict(resource);
         return;
     }
@@ -265,7 +270,7 @@
     // dead resources are pruned. That might be immediately since
     // removing the last client triggers a MemoryCache::prune, so the
     // resource may be deleted after this call.
-    toCachedImageManual(toCachedImage(resource))->removeFakeClient();
+    toCachedImage(resource)->removeClient(&dummyCachedImageClient());
 }
 #endif
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to