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

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

Issue 2210473002: Mark ResourceClient/ImageResourceObserver finished just before notifying (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tests Created 4 years, 4 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 36553ba304f6d24fecebb4fe0764a0c8ebe326d5..90aec7cb9a8abe23446957c3bc10a014e1bce17c 100644
--- a/third_party/WebKit/Source/core/fetch/ImageResource.cpp
+++ b/third_party/WebKit/Source/core/fetch/ImageResource.cpp
@@ -92,27 +92,27 @@ DEFINE_TRACE(ImageResource)
MultipartImageResourceParser::Client::trace(visitor);
}
-void ImageResource::checkNotify()
+void ImageResource::checkNotify(MarkFinishedOption markFinishedOption)
{
if (isLoading())
return;
ImageResourceObserverWalker walker(m_observers);
while (auto* observer = walker.next()) {
+ if (markFinishedOption == MarkFinishedOption::ShouldMarkFinished)
+ markObserverFinished(observer);
observer->imageNotifyFinished(this);
}
- Resource::checkNotify();
+ Resource::checkNotify(markFinishedOption);
}
-void ImageResource::markClientsAndObserversFinished()
+void ImageResource::markObserverFinished(ImageResourceObserver* observer)
{
- HashCountedSet<ImageResourceObserver*> observers;
- m_observers.swap(observers);
- for (const auto& it : observers)
- m_finishedObservers.add(it.key, it.value);
-
- Resource::markClientsAndObserversFinished();
+ if (m_observers.contains(observer)) {
+ m_finishedObservers.add(observer);
+ m_observers.remove(observer);
+ }
}
void ImageResource::didAddClient(ResourceClient* client)
@@ -145,11 +145,8 @@ void ImageResource::addObserver(ImageResourceObserver* observer)
}
if (isLoaded()) {
+ markObserverFinished(observer);
observer->imageNotifyFinished(this);
- if (m_observers.contains(observer)) {
- m_finishedObservers.add(observer);
- m_observers.remove(observer);
- }
}
}
@@ -577,7 +574,9 @@ void ImageResource::onePartInMultipartReceived(const ResourceResponse& response)
// Notify finished when the first part ends.
if (!errorOccurred())
setStatus(Cached);
- checkNotify();
+ // We will also notify clients/observers of the finish in
+ // Resource::finish()/error() so we don't mark them finished here.
+ checkNotify(MarkFinishedOption::DoNotMarkFinished);
if (loader())
loader()->didFinishLoadingFirstPartInMultipart();
}

Powered by Google App Engine
This is Rietveld 408576698