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

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: 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..45f80c728f9763c48e59c5b825e3211cb4ec37f1 100644
--- a/third_party/WebKit/Source/core/fetch/ImageResource.cpp
+++ b/third_party/WebKit/Source/core/fetch/ImageResource.cpp
@@ -104,7 +104,7 @@ void ImageResource::checkNotify() {
void ImageResource::notifyObserversInternal(
MarkFinishedOption markFinishedOption) {
- if (isLoading())
+ if (isLoading() || isNotifyClientsOfCompletionProhibited())
return;
for (auto* observer : m_observers.asVector()) {
@@ -150,7 +150,7 @@ void ImageResource::addObserver(ImageResourceObserver* observer) {
observer->imageChanged(this);
}
- if (isLoaded()) {
+ if (isLoaded() && !isNotifyClientsOfCompletionProhibited()) {
markObserverFinished(observer);
observer->imageNotifyFinished(this);
}
@@ -532,14 +532,30 @@ void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) {
if (isLoaded() &&
!response().httpHeaderField("chrome-proxy").contains("q=low"))
return;
- setCachePolicyBypassingCache();
- setLoFiStateOff();
- if (isLoading())
- loader()->cancel();
- clear();
- notifyObservers();
- setStatus(NotStarted);
+ {
Nate Chapin 2016/10/10 23:47:49 I don't think you need to force this to have a nar
sclittle 2016/10/11 02:56:56 AIUI we only want to prevent completion callbacks
Nate Chapin 2016/10/12 22:56:17 If startLoad() is someday allowed to complete the
sclittle 2016/10/12 23:38:16 Fair enough :) I've removed the dependency on Auto
+ // 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.
+ Resource::ProhibitNotifyClientsOfCompletionInScope
Nate Chapin 2016/10/10 23:47:49 AutoReset<bool> instead of a custom helper?
sclittle 2016/10/11 02:56:56 I don't see an easy way to do that, unless we want
Nate Chapin 2016/10/12 22:56:17 Let's use AutoReset if and only if we settle on mo
sclittle 2016/10/12 23:38:16 I've removed the dependency on AutoReset and chang
+ scopedProhibitNotifyCompletion(this);
+
+ setCachePolicyBypassingCache();
+ setLoFiStateOff();
+ if (isLoading()) {
+ loader()->cancel();
Nate Chapin 2016/10/10 23:47:49 Is this the only case where you want to suppress c
sclittle 2016/10/11 02:56:56 loader()->cancel() is the main case I'm worried ab
Nate Chapin 2016/10/12 22:56:17 clear() is trivial, but notifyObservers() could ha
sclittle 2016/10/12 23:38:16 Acknowledged.
+ // 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);
+ }
+
fetcher->startLoad(this);
}

Powered by Google App Engine
This is Rietveld 408576698