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

Side by Side Diff: third_party/WebKit/Source/core/fetch/ImageResource.cpp

Issue 2054643003: Remove duplication of encoded image data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address on hiroshige's review Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
6 Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 6 Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 116
117 void ImageResource::addObserver(ImageResourceObserver* observer) 117 void ImageResource::addObserver(ImageResourceObserver* observer)
118 { 118 {
119 willAddClientOrObserver(); 119 willAddClientOrObserver();
120 120
121 m_observers.add(observer); 121 m_observers.add(observer);
122 122
123 if (isCacheValidator()) 123 if (isCacheValidator())
124 return; 124 return;
125 125
126 if (m_data && !m_image && !errorOccurred()) { 126 DCHECK(!m_data || m_image);
127 createImage();
128 m_image->setData(m_data, true);
129 }
130 127
131 if (m_image && !m_image->isNull()) { 128 if (m_image && !m_image->isNull()) {
132 observer->imageChanged(this); 129 observer->imageChanged(this);
133 } 130 }
134 131
135 if (isLoaded()) { 132 if (isLoaded()) {
136 observer->imageNotifyFinished(this); 133 observer->imageNotifyFinished(this);
137 if (m_observers.contains(observer)) { 134 if (m_observers.contains(observer)) {
138 m_finishedObservers.add(observer); 135 m_finishedObservers.add(observer);
139 m_observers.remove(observer); 136 m_observers.remove(observer);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 179 }
183 180
184 bool ImageResource::isSafeToUnlock() const 181 bool ImageResource::isSafeToUnlock() const
185 { 182 {
186 // Note that |m_image| holds a reference to |m_data| in addition to the one held by the Resource parent class. 183 // Note that |m_image| holds a reference to |m_data| in addition to the one held by the Resource parent class.
187 return !m_image || (m_image->hasOneRef() && m_data->refCount() == 2); 184 return !m_image || (m_image->hasOneRef() && m_data->refCount() == 2);
188 } 185 }
189 186
190 void ImageResource::destroyDecodedDataForFailedRevalidation() 187 void ImageResource::destroyDecodedDataForFailedRevalidation()
191 { 188 {
192 m_image = nullptr; 189 m_image->destroyDecodedData();
193 setDecodedSize(0);
194 } 190 }
195 191
196 void ImageResource::destroyDecodedDataIfPossible() 192 void ImageResource::destroyDecodedDataIfPossible()
197 { 193 {
198 if (!hasClientsOrObservers() && !isLoading() && (!m_image || (m_image->hasOn eRef() && m_image->isBitmapImage()))) { 194 if (!hasClientsOrObservers() && !isLoading() && m_image && (m_image->hasOneR ef() && m_image->isBitmapImage())) {
scroggo_chromium 2016/06/20 19:00:43 Are the parentheses around m_image->hasOneRef()
hajimehoshi 2016/06/22 09:42:29 Done.
199 m_image = nullptr; 195 m_image->destroyDecodedData();
200 setDecodedSize(0);
201 } else if (m_image && !errorOccurred()) { 196 } else if (m_image && !errorOccurred()) {
202 m_image->destroyDecodedData(); 197 m_image->destroyDecodedData();
scroggo_chromium 2016/06/20 19:00:43 This else statement appears to do the exact same t
hajimehoshi 2016/06/22 09:42:29 Done.
203 } 198 }
204 } 199 }
205 200
206 void ImageResource::allClientsAndObserversRemoved() 201 void ImageResource::allClientsAndObserversRemoved()
207 { 202 {
208 if (m_image && !errorOccurred()) 203 if (m_image && !errorOccurred())
209 m_image->resetAnimation(); 204 m_image->resetAnimation();
210 if (m_multipartParser) 205 if (m_multipartParser)
211 m_multipartParser->cancel(); 206 m_multipartParser->cancel();
212 Resource::allClientsAndObserversRemoved(); 207 Resource::allClientsAndObserversRemoved();
213 } 208 }
214 209
210 PassRefPtr<SharedBuffer> ImageResource::resourceBuffer() const
211 {
212 RefPtr<SharedBuffer> data = Resource::resourceBuffer();
213 if (data)
214 return data;
215 if (m_image)
216 return m_image->data();
217 return nullptr;
218 }
219
215 void ImageResource::appendData(const char* data, size_t length) 220 void ImageResource::appendData(const char* data, size_t length)
216 { 221 {
217 if (m_multipartParser) { 222 if (m_multipartParser) {
218 m_multipartParser->appendData(data, length); 223 m_multipartParser->appendData(data, length);
219 } else { 224 } else {
220 Resource::appendData(data, length); 225 Resource::appendData(data, length);
221 updateImage(false); 226 updateImage(false);
222 } 227 }
223 } 228 }
224 229
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 TRACE_EVENT0("blink", "ImageResource::updateImage"); 353 TRACE_EVENT0("blink", "ImageResource::updateImage");
349 354
350 if (m_data) 355 if (m_data)
351 createImage(); 356 createImage();
352 357
353 bool sizeAvailable = false; 358 bool sizeAvailable = false;
354 359
355 // Have the image update its data from its internal buffer. 360 // Have the image update its data from its internal buffer.
356 // It will not do anything now, but will delay decoding until 361 // It will not do anything now, but will delay decoding until
357 // queried for info (like size or specific image frames). 362 // queried for info (like size or specific image frames).
358 if (m_image) 363 if (m_image) {
hajimehoshi 2016/06/22 09:42:29 Found that there is a case |m_data| is null (Image
364 DCHECK(m_data);
359 sizeAvailable = m_image->setData(m_data, allDataReceived); 365 sizeAvailable = m_image->setData(m_data, allDataReceived);
366 }
360 367
361 // Go ahead and tell our observers to try to draw if we have either 368 // Go ahead and tell our observers to try to draw if we have either
362 // received all the data or the size is known. Each chunk from the 369 // received all the data or the size is known. Each chunk from the
363 // network causes observers to repaint, which will force that chunk 370 // network causes observers to repaint, which will force that chunk
364 // to decode. 371 // to decode.
365 if (sizeAvailable || allDataReceived) { 372 if (sizeAvailable || allDataReceived) {
366 if (!m_image || m_image->isNull()) { 373 if (!m_image || m_image->isNull()) {
367 if (!errorOccurred()) 374 if (!errorOccurred())
368 setStatus(DecodeError); 375 setStatus(DecodeError);
369 clear(); 376 clear();
370 if (memoryCache()->contains(this)) 377 if (memoryCache()->contains(this))
371 memoryCache()->remove(this); 378 memoryCache()->remove(this);
372 } 379 }
373 380
374 // It would be nice to only redraw the decoded band of the image, but wi th the current design 381 // It would be nice to only redraw the decoded band of the image, but wi th the current design
375 // (decoding delayed until painting) that seems hard. 382 // (decoding delayed until painting) that seems hard.
376 notifyObservers(); 383 notifyObservers();
377 } 384 }
385
386 if (allDataReceived)
387 m_data.clear();
378 } 388 }
379 389
380 void ImageResource::updateImageAndClearBuffer() 390 void ImageResource::updateImageAndClearBuffer()
381 { 391 {
382 clearImage(); 392 clearImage();
383 updateImage(true); 393 updateImage(true);
384 m_data.clear();
385 } 394 }
386 395
387 void ImageResource::finish(double loadFinishTime) 396 void ImageResource::finish(double loadFinishTime)
388 { 397 {
389 if (m_multipartParser) { 398 if (m_multipartParser) {
390 m_multipartParser->finish(); 399 m_multipartParser->finish();
391 if (m_data) 400 if (m_data)
392 updateImageAndClearBuffer(); 401 updateImageAndClearBuffer();
393 } else { 402 } else {
394 updateImage(true); 403 updateImage(true);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 m_image->setAnimationPolicy(newPolicy); 502 m_image->setAnimationPolicy(newPolicy);
494 } 503 }
495 } 504 }
496 505
497 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) 506 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher)
498 { 507 {
499 if (!m_response.httpHeaderField("chrome-proxy").contains("q=low")) 508 if (!m_response.httpHeaderField("chrome-proxy").contains("q=low"))
500 return; 509 return;
501 m_resourceRequest.setCachePolicy(WebCachePolicy::BypassingCache); 510 m_resourceRequest.setCachePolicy(WebCachePolicy::BypassingCache);
502 m_resourceRequest.setLoFiState(WebURLRequest::LoFiOff); 511 m_resourceRequest.setLoFiState(WebURLRequest::LoFiOff);
503 if (isLoading()) 512 if (isLoading()) {
scroggo_chromium 2016/06/20 19:00:43 nit: My understanding of the style guide is that t
hajimehoshi 2016/06/22 09:42:29 Done.
504 m_loader->cancel(); 513 m_loader->cancel();
505 else 514 }
506 updateImageAndClearBuffer();
507 setStatus(NotStarted); 515 setStatus(NotStarted);
508 fetcher->startLoad(this); 516 fetcher->startLoad(this);
509 } 517 }
510 518
511 void ImageResource::changedInRect(const blink::Image* image, const IntRect& rect ) 519 void ImageResource::changedInRect(const blink::Image* image, const IntRect& rect )
512 { 520 {
513 if (!image || image != m_image) 521 if (!image || image != m_image)
514 return; 522 return;
515 notifyObservers(&rect); 523 notifyObservers(&rect);
516 } 524 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 if (response().wasFetchedViaServiceWorker()) 557 if (response().wasFetchedViaServiceWorker())
550 return response().serviceWorkerResponseType() != WebServiceWorkerRespons eTypeOpaque; 558 return response().serviceWorkerResponseType() != WebServiceWorkerRespons eTypeOpaque;
551 if (!getImage()->currentFrameHasSingleSecurityOrigin()) 559 if (!getImage()->currentFrameHasSingleSecurityOrigin())
552 return false; 560 return false;
553 if (passesAccessControlCheck(securityOrigin)) 561 if (passesAccessControlCheck(securityOrigin))
554 return true; 562 return true;
555 return !securityOrigin->taintsCanvas(response().url()); 563 return !securityOrigin->taintsCanvas(response().url());
556 } 564 }
557 565
558 } // namespace blink 566 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698