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

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

Issue 2407573002: Wait to notify completion until after a Lo-Fi image is reloaded. (Closed)
Patch Set: removed unnecessary m_isSchedulingReload check Created 4 years, 2 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 ab9668033457412d10e819243d1f095f2f7e4f19..ddafecd58c12423894a7069db8f7330578752866 100644
--- a/third_party/WebKit/Source/core/fetch/ImageResource.cpp
+++ b/third_party/WebKit/Source/core/fetch/ImageResource.cpp
@@ -71,7 +71,8 @@ ImageResource::ImageResource(const ResourceRequest& resourceRequest,
: Resource(resourceRequest, Image, options),
m_devicePixelRatioHeaderValue(1.0),
m_image(nullptr),
- m_hasDevicePixelRatioHeaderValue(false) {
+ m_hasDevicePixelRatioHeaderValue(false),
+ m_isSchedulingReload(false) {
RESOURCE_LOADING_DVLOG(1) << "new ImageResource(ResourceRequest) " << this;
}
@@ -80,7 +81,8 @@ ImageResource::ImageResource(blink::Image* image,
: Resource(ResourceRequest(""), Image, options),
m_devicePixelRatioHeaderValue(1.0),
m_image(image),
- m_hasDevicePixelRatioHeaderValue(false) {
+ m_hasDevicePixelRatioHeaderValue(false),
+ m_isSchedulingReload(false) {
RESOURCE_LOADING_DVLOG(1) << "new ImageResource(Image) " << this;
setStatus(Cached);
}
@@ -98,6 +100,11 @@ DEFINE_TRACE(ImageResource) {
}
void ImageResource::checkNotify() {
+ // Don't notify observers and clients of completion if this ImageResource is
+ // about to be reloaded.
+ if (m_isSchedulingReload)
+ return;
+
notifyObserversInternal(MarkFinishedOption::ShouldMarkFinished);
Resource::checkNotify();
}
@@ -125,6 +132,12 @@ void ImageResource::markObserverFinished(ImageResourceObserver* observer) {
void ImageResource::didAddClient(ResourceClient* client) {
DCHECK((m_multipartParser && isLoading()) || !data() || m_image);
+
+ // Don't notify observers and clients of completion if this ImageResource is
+ // about to be reloaded.
+ if (m_isSchedulingReload)
+ return;
+
Resource::didAddClient(client);
}
@@ -150,7 +163,7 @@ void ImageResource::addObserver(ImageResourceObserver* observer) {
observer->imageChanged(this);
}
- if (isLoaded()) {
+ if (isLoaded() && !m_isSchedulingReload) {
markObserverFinished(observer);
observer->imageNotifyFinished(this);
}
@@ -532,14 +545,31 @@ void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) {
if (isLoaded() &&
!response().httpHeaderField("chrome-proxy").contains("q=low"))
return;
+
+ // Prevent clients and observers from being notified of completion while the
+ // reload is being scheduled, so that e.g. canceling an existing load in
+ // progress doesn't cause clients and observers to be notified of completion
+ // prematurely.
+ DCHECK(!m_isSchedulingReload);
+ m_isSchedulingReload = true;
+
setCachePolicyBypassingCache();
setLoFiStateOff();
- if (isLoading())
+ if (isLoading()) {
loader()->cancel();
- clear();
- notifyObservers();
+ // Canceling the loader causes error() to be called, which in turn calls
+ // clear() and notifyObservers(), so there's no need to call these again
+ // here.
+ } else {
+ clear();
+ notifyObservers();
+ }
setStatus(NotStarted);
+
+ DCHECK(m_isSchedulingReload);
+ m_isSchedulingReload = false;
+
fetcher->startLoad(this);
}
« no previous file with comments | « third_party/WebKit/Source/core/fetch/ImageResource.h ('k') | third_party/WebKit/Source/core/fetch/ImageResourceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698