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 18de9a4285356fd2ddb05e57b41507077369464a..fabcdd4f396b1e550665357f8f878ada258897ce 100644 |
| --- a/third_party/WebKit/Source/core/fetch/ImageResource.cpp |
| +++ b/third_party/WebKit/Source/core/fetch/ImageResource.cpp |
| @@ -115,20 +115,6 @@ void ImageResource::markClientsAndObserversFinished() |
| Resource::markClientsAndObserversFinished(); |
| } |
| -void ImageResource::ensureImage() |
| -{ |
| - if (m_data && !m_image && !errorOccurred()) { |
| - createImage(); |
| - m_image->setData(m_data, true); |
| - } |
| -} |
| - |
| -void ImageResource::didAddClient(ResourceClient* client) |
| -{ |
| - ensureImage(); |
| - Resource::didAddClient(client); |
| -} |
| - |
| void ImageResource::addObserver(ImageResourceObserver* observer) |
| { |
| willAddClientOrObserver(); |
| @@ -138,7 +124,7 @@ void ImageResource::addObserver(ImageResourceObserver* observer) |
| if (isCacheValidator()) |
| return; |
| - ensureImage(); |
| + DCHECK(!m_data || m_image); |
| if (m_image && !m_image->isNull()) { |
| observer->imageChanged(this); |
| @@ -207,12 +193,10 @@ void ImageResource::destroyDecodedDataForFailedRevalidation() |
| void ImageResource::destroyDecodedDataIfPossible() |
| { |
| - if (!hasClientsOrObservers() && !isLoading() && (!m_image || (m_image->hasOneRef() && m_image->isBitmapImage()))) { |
| - clearImage(); |
| - setDecodedSize(0); |
| - } else if (m_image && !errorOccurred()) { |
| + if (!m_image) |
| + return; |
| + if ((!hasClientsOrObservers() && !isLoading() && m_image->hasOneRef() && m_image->isBitmapImage()) || !errorOccurred()) |
| m_image->destroyDecodedData(); |
| - } |
| } |
| void ImageResource::doResetAnimation() |
| @@ -237,6 +221,15 @@ void ImageResource::allClientsAndObserversRemoved() |
| Resource::allClientsAndObserversRemoved(); |
| } |
| +PassRefPtr<SharedBuffer> ImageResource::resourceBuffer() const |
| +{ |
| + if (m_data) |
| + return m_data.get(); |
| + if (m_image) |
| + return m_image->data(); |
| + return nullptr; |
| +} |
| + |
| void ImageResource::appendData(const char* data, size_t length) |
| { |
| if (m_multipartParser) { |
| @@ -381,8 +374,10 @@ void ImageResource::updateImage(bool allDataReceived) |
| // Have the image update its data from its internal buffer. |
| // It will not do anything now, but will delay decoding until |
| // queried for info (like size or specific image frames). |
| - if (m_image) |
| + if (m_data) { |
| + DCHECK(m_image); |
| sizeAvailable = m_image->setData(m_data, allDataReceived); |
| + } |
| // Go ahead and tell our observers to try to draw if we have either |
| // received all the data or the size is known. Each chunk from the |
| @@ -418,6 +413,11 @@ void ImageResource::finish(double loadFinishTime) |
| updateImageAndClearBuffer(); |
| } else { |
| updateImage(true); |
| + // As encoded image data can be created from m_image, we don't have to |
| + // keep m_data. Let's clear this. As for the lifetimes of m_image and |
| + // m_data, see this document: |
| + // https://docs.google.com/document/d/1v0yTAZ6wkqX2U_M6BNIGUJpM1s0TIw1VsqpxoL7aciY/edit?usp=sharing |
| + m_data.clear(); |
| } |
| Resource::finish(loadFinishTime); |
| } |
| @@ -528,8 +528,6 @@ void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) |
| m_resourceRequest.setLoFiState(WebURLRequest::LoFiOff); |
| if (isLoading()) |
| m_loader->cancel(); |
| - else |
| - updateImageAndClearBuffer(); |
|
haraken
2016/07/13 08:07:42
Why can we remove this? Now you're not calling m_d
|
| setStatus(NotStarted); |
| fetcher->startLoad(this); |
| } |