Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Unified Diff: third_party/WebKit/Source/core/fetch/ImageResource.cpp

Issue 1706083002: Split ImageResourceClient into ResourceClient and ImageResourceObserver [1/2] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More consistent Client/Observer Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/fetch/ImageResource.cpp
diff --git a/third_party/WebKit/Source/core/fetch/ImageResource.cpp b/third_party/WebKit/Source/core/fetch/ImageResource.cpp
index 8f88b90ba0a770dcfcd0a326e5087cfea1435151..7f5f29f3ac3ee4849bed1272a963992d4bfe8484 100644
--- a/third_party/WebKit/Source/core/fetch/ImageResource.cpp
+++ b/third_party/WebKit/Source/core/fetch/ImageResource.cpp
@@ -23,7 +23,7 @@
#include "core/fetch/ImageResource.h"
-#include "core/fetch/ImageResourceClient.h"
+#include "core/fetch/ImageResourceObserver.h"
#include "core/fetch/MemoryCache.h"
#include "core/fetch/ResourceClient.h"
#include "core/fetch/ResourceClientWalker.h"
@@ -41,6 +41,12 @@
namespace blink {
+namespace {
+
+using ImageResourceObserverWalker = ResourceClientOrObserverWalker<ImageResourceObserver, ImageResourceObserver>;
+
+} // namespace
+
PassRefPtrWillBeRawPtr<ImageResource> ImageResource::fetch(FetchRequest& request, ResourceFetcher* fetcher)
{
if (request.resourceRequest().requestContext() == WebURLRequest::RequestContextUnspecified)
@@ -111,26 +117,44 @@ void ImageResource::load(ResourceFetcher* fetcher, const ResourceLoaderOptions&
setLoading(false);
}
-void ImageResource::didAddClient(ResourceClient* c)
+void ImageResource::addObserver(ImageResourceObserver* observer)
{
+ willAddClient();
+
+ m_observers.add(observer);
+
+ if (!m_revalidatingRequest.isNull())
+ return;
+
if (m_data && !m_image && !errorOccurred()) {
createImage();
m_image->setData(m_data, true);
}
- ASSERT(ImageResourceClient::isExpectedType(c));
if (m_image && !m_image->isNull())
- static_cast<ImageResourceClient*>(c)->imageChanged(this);
-
- Resource::didAddClient(c);
+ observer->imageChanged(this);
}
-void ImageResource::didRemoveClient(ResourceClient* c)
+void ImageResource::removeObserver(ImageResourceObserver* observer)
{
- ASSERT(c);
- ASSERT(ImageResourceClient::isExpectedType(c));
+ ASSERT(observer);
+ ASSERT(m_observers.contains(observer));
+ m_observers.remove(observer);
+ didRemoveClient();
+}
- Resource::didRemoveClient(c);
+ResourcePriority ImageResource::priorityFromClients()
+{
+ ResourcePriority priority;
+ ImageResourceObserverWalker w(m_observers);
+ while (const auto* observer = w.next()) {
+ ResourcePriority nextPriority = observer->computeResourcePriority();
+ if (nextPriority.visibility == ResourcePriority::NotVisible)
+ continue;
+ priority.visibility = ResourcePriority::Visible;
+ priority.intraPriorityValue += nextPriority.intraPriorityValue;
+ }
+ return priority;
}
bool ImageResource::isSafeToUnlock() const
@@ -247,13 +271,10 @@ void ImageResource::computeIntrinsicDimensions(Length& intrinsicWidth, Length& i
void ImageResource::notifyObservers(const IntRect* changeRect)
{
- ResourceClientWalker<ImageResourceClient> w(m_clients);
- while (ImageResourceClient* c = w.next())
- c->imageChanged(this, changeRect);
-
- ResourceClientWalker<ImageResourceClient> w2(m_finishedClients);
- while (ImageResourceClient* c = w2.next())
- c->imageChanged(this, changeRect);
+ ImageResourceObserverWalker w(m_observers);
+ while (auto* observer = w.next()) {
+ observer->imageChanged(this, changeRect);
+ }
}
void ImageResource::clear()
@@ -391,18 +412,11 @@ bool ImageResource::shouldPauseAnimation(const blink::Image* image)
if (!image || image != m_image)
return false;
- ResourceClientWalker<ImageResourceClient> w(m_clients);
- while (ImageResourceClient* c = w.next()) {
- if (c->willRenderImage(this))
- return false;
- }
-
- ResourceClientWalker<ImageResourceClient> w2(m_finishedClients);
- while (ImageResourceClient* c = w2.next()) {
- if (c->willRenderImage(this))
+ ImageResourceObserverWalker w(m_observers);
+ while (auto* observer = w.next()) {
+ if (observer->willRenderImage())
return false;
}
-
return true;
}
@@ -419,15 +433,9 @@ void ImageResource::updateImageAnimationPolicy()
return;
ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed;
- ResourceClientWalker<ImageResourceClient> w(m_clients);
- while (ImageResourceClient* c = w.next()) {
- if (c->getImageAnimationPolicy(this, newPolicy))
- break;
- }
-
- ResourceClientWalker<ImageResourceClient> w2(m_finishedClients);
- while (ImageResourceClient* c = w2.next()) {
- if (c->getImageAnimationPolicy(this, newPolicy))
+ ImageResourceObserverWalker w(m_observers);
+ while (auto* observer = w.next()) {
+ if (observer->getImageAnimationPolicy(newPolicy))
break;
}

Powered by Google App Engine
This is Rietveld 408576698