Chromium Code Reviews| 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 4599b0eef83eec423fa9f4b92dd90f8c9dfa2c0b..8ec830a3354755298d7a5800e9431ef3126b86a5 100644 |
| --- a/third_party/WebKit/Source/core/fetch/ImageResource.cpp |
| +++ b/third_party/WebKit/Source/core/fetch/ImageResource.cpp |
| @@ -101,17 +101,30 @@ DEFINE_TRACE(ImageResource) |
| MultipartImageResourceParser::Client::trace(visitor); |
| } |
| -void ImageResource::notifyObserver(ImageResourceObserver* observer, bool isNotifyingFinish, const IntRect* changeRect) |
| +void ImageResource::checkNotify() |
| { |
| - if (isNotifyingFinish) { |
| + if (isLoading()) |
| + return; |
| + |
| + ImageResourceObserverWalker walker(m_observers); |
| + while (auto* observer = walker.next()) { |
| observer->imageNotifyFinished(this); |
| - if (m_observers.contains(observer)) { |
| - m_finishedObservers.add(observer); |
| - m_observers.remove(observer); |
| + } |
| + |
| + Resource::checkNotify(); |
| +} |
| + |
| +void ImageResource::markClientsAndObserversFinished() |
| +{ |
| + while (!m_observers.isEmpty()) { |
| + HashCountedSet<ImageResourceObserver*>::iterator it = m_observers.begin(); |
| + for (int i = it->value; i; i--) { |
| + m_finishedObservers.add(it->key); |
| + m_observers.remove(it); |
| } |
| } |
| - observer->imageChanged(this, changeRect); |
| + Resource::markClientsAndObserversFinished(); |
| } |
| void ImageResource::addObserver(ImageResourceObserver* observer) |
| @@ -129,8 +142,20 @@ void ImageResource::addObserver(ImageResourceObserver* observer) |
| } |
| if (m_image && !m_image->isNull()) { |
| - bool isNotifyingFinish = !isLoading() && !stillNeedsLoad(); |
| - notifyObserver(observer, isNotifyingFinish); |
| + observer->imageChanged(this); |
| + } |
| + |
| + didAddObserver(observer); |
|
yhirano
2016/04/04 11:07:30
[optional] I'm not sure if it's a good idea to hav
hiroshige
2016/04/05 06:00:50
Done.
|
| +} |
| + |
| +void ImageResource::didAddObserver(ImageResourceObserver* observer) |
| +{ |
| + if (isLoaded()) { |
| + observer->imageNotifyFinished(this); |
| + if (m_observers.contains(observer)) { |
| + m_finishedObservers.add(observer); |
| + m_observers.remove(observer); |
| + } |
| } |
| } |
| @@ -292,16 +317,16 @@ LayoutSize ImageResource::imageSize(RespectImageOrientationEnum shouldRespectIma |
| return size; |
| } |
| -void ImageResource::notifyObservers(bool isNotifyingFinish, const IntRect* changeRect) |
| +void ImageResource::notifyObservers(const IntRect* changeRect) |
| { |
| ImageResourceObserverWalker finishedWalker(m_finishedObservers); |
| while (auto* observer = finishedWalker.next()) { |
| - notifyObserver(observer, false, changeRect); |
| + observer->imageChanged(this, changeRect); |
| } |
| ImageResourceObserverWalker walker(m_observers); |
| while (auto* observer = walker.next()) { |
| - notifyObserver(observer, isNotifyingFinish, changeRect); |
| + observer->imageChanged(this, changeRect); |
| } |
| } |
| @@ -371,7 +396,7 @@ void ImageResource::updateImage(bool allDataReceived) |
| // It would be nice to only redraw the decoded band of the image, but with the current design |
| // (decoding delayed until painting) that seems hard. |
| - notifyObservers(allDataReceived); |
| + notifyObservers(); |
| } |
| } |
| @@ -396,7 +421,7 @@ void ImageResource::error(Resource::Status status) |
| m_multipartParser->cancel(); |
| clear(); |
| Resource::error(status); |
| - notifyObservers(true); |
| + notifyObservers(); |
| } |
| void ImageResource::responseReceived(const ResourceResponse& response, PassOwnPtr<WebDataConsumerHandle> handle) |
| @@ -462,7 +487,7 @@ void ImageResource::animationAdvanced(const blink::Image* image) |
| { |
| if (!image || image != m_image) |
| return; |
| - notifyObservers(false); |
| + notifyObservers(); |
| } |
| void ImageResource::updateImageAnimationPolicy() |
| @@ -504,7 +529,7 @@ void ImageResource::changedInRect(const blink::Image* image, const IntRect& rect |
| { |
| if (!image || image != m_image) |
| return; |
| - notifyObservers(false, &rect); |
| + notifyObservers(&rect); |
| } |
| void ImageResource::onePartInMultipartReceived(const ResourceResponse& response) |