| 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 d0267f99ccf05b41ce82815333f210a8c96abad3..d3061d29509cae2fec1e8ff9c6cc952ac5c0f12b 100644
|
| --- a/third_party/WebKit/Source/core/fetch/ImageResource.cpp
|
| +++ b/third_party/WebKit/Source/core/fetch/ImageResource.cpp
|
| @@ -44,6 +44,12 @@
|
| #include <v8.h>
|
|
|
| namespace blink {
|
| +namespace {
|
| +// The amount of time to wait before informing the clients that the image has
|
| +// been updated (in seconds). This effectively throttles invalidations that
|
| +// result from new data arriving for this image.
|
| +constexpr double kFlushDelaySeconds = 1.;
|
| +} // namespace
|
|
|
| ImageResource* ImageResource::fetch(FetchRequest& request,
|
| ResourceFetcher* fetcher) {
|
| @@ -136,15 +142,17 @@ void ImageResource::addObserver(ImageResourceObserver* observer) {
|
| if (isCacheValidator())
|
| return;
|
|
|
| - // When the response is not multipart, if |data()| exists, |m_image| must be
|
| - // created. This is assured that |updateImage()| is called when |appendData()|
|
| - // is called.
|
| + // When the response is not multipart, if |data()| exists and image is loaded,
|
| + // |m_image| must be created. This is assured that |updateImage()| is called
|
| + // when the image finishes loading. However, while loading |appendData()| can
|
| + // throttle |updateImage()| calls.
|
| //
|
| // On the other hand, when the response is multipart, |updateImage()| is not
|
| // called in |appendData()|, which means |m_image| might not be created even
|
| // when |data()| exists. This is intentional since creating a |m_image| on
|
| // receiving data might destroy an existing image in a previous part.
|
| - DCHECK((m_multipartParser && isLoading()) || !data() || m_image);
|
| + DCHECK((m_multipartParser && isLoading()) || !data() || m_image ||
|
| + !isLoaded());
|
|
|
| if (m_image && !m_image->isNull()) {
|
| observer->imageChanged(this);
|
| @@ -242,7 +250,25 @@ void ImageResource::appendData(const char* data, size_t length) {
|
| m_multipartParser->appendData(data, length);
|
| } else {
|
| Resource::appendData(data, length);
|
| - updateImage(false);
|
| +
|
| + // If we have an animated image, then update as soon as we have more data.
|
| + if (m_image && m_image->maybeAnimated()) {
|
| + updateImage(false);
|
| + return;
|
| + }
|
| +
|
| + // For other images, only update at |kFlushDelaySeconds| intervals. This
|
| + // throttles how frequently we update |m_image| and how frequently we
|
| + // inform the clients which causes an invalidation of this image. In other
|
| + // words, we only invalidate this image every |kFlushDelaySeconds| seconds
|
| + // while loading.
|
| + double now = WTF::currentTime();
|
| + if (!m_lastFlushTime) {
|
| + m_lastFlushTime = now;
|
| + } else if (m_lastFlushTime + kFlushDelaySeconds <= now) {
|
| + updateImage(false);
|
| + m_lastFlushTime = now;
|
| + }
|
| }
|
| }
|
|
|
|
|