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

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

Issue 2642823005: Phase II Step 1: Remove updateImage() reentrancy around decodeError() (Closed)
Patch Set: Rebase Created 3 years, 11 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 return m_resource->isAccessAllowed(securityOrigin, 92 return m_resource->isAccessAllowed(securityOrigin,
93 doesCurrentFrameHasSingleSecurityOrigin); 93 doesCurrentFrameHasSingleSecurityOrigin);
94 } 94 }
95 bool hasCacheControlNoStoreHeader() const override { 95 bool hasCacheControlNoStoreHeader() const override {
96 return m_resource->hasCacheControlNoStoreHeader(); 96 return m_resource->hasCacheControlNoStoreHeader();
97 } 97 }
98 const ResourceError& resourceError() const override { 98 const ResourceError& resourceError() const override {
99 return m_resource->resourceError(); 99 return m_resource->resourceError();
100 } 100 }
101 101
102 void decodeError(bool allDataReceived) override {
103 m_resource->decodeError(allDataReceived);
104 }
105 void setIsPlaceholder(bool isPlaceholder) override { 102 void setIsPlaceholder(bool isPlaceholder) override {
106 m_resource->m_isPlaceholder = isPlaceholder; 103 m_resource->m_isPlaceholder = isPlaceholder;
107 } 104 }
108 void setDecodedSize(size_t size) override { 105 void setDecodedSize(size_t size) override {
109 m_resource->setDecodedSize(size); 106 m_resource->setDecodedSize(size);
110 } 107 }
111 void willAddClientOrObserver() override { 108 void willAddClientOrObserver() override {
112 m_resource->willAddClientOrObserver(Resource::MarkAsReferenced); 109 m_resource->willAddClientOrObserver(Resource::MarkAsReferenced);
113 } 110 }
114 void didRemoveClientOrObserver() override { 111 void didRemoveClientOrObserver() override {
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 } 319 }
323 320
324 void ImageResource::decodeError(bool allDataReceived) { 321 void ImageResource::decodeError(bool allDataReceived) {
325 size_t size = encodedSize(); 322 size_t size = encodedSize();
326 323
327 clearData(); 324 clearData();
328 setEncodedSize(0); 325 setEncodedSize(0);
329 if (!errorOccurred()) 326 if (!errorOccurred())
330 setStatus(ResourceStatus::DecodeError); 327 setStatus(ResourceStatus::DecodeError);
331 328
329 // Finishes loading if needed, and notifies observers.
332 if (!allDataReceived && loader()) { 330 if (!allDataReceived && loader()) {
331 // Observers are notified via ImageResource::finish().
333 // TODO(hiroshige): Do not call didFinishLoading() directly. 332 // TODO(hiroshige): Do not call didFinishLoading() directly.
334 loader()->didFinishLoading(monotonicallyIncreasingTime(), size, size); 333 loader()->didFinishLoading(monotonicallyIncreasingTime(), size, size);
334 } else {
335 auto result = getContent()->updateImage(
336 nullptr, ImageResourceContent::ClearImageAndNotifyObservers,
337 allDataReceived);
338 DCHECK_EQ(result, ImageResourceContent::UpdateImageResult::NoDecodeError);
335 } 339 }
336 340
337 memoryCache()->remove(this); 341 memoryCache()->remove(this);
338 } 342 }
339 343
340 void ImageResource::updateImageAndClearBuffer() { 344 void ImageResource::updateImageAndClearBuffer() {
341 updateImage(data(), ImageResourceContent::ClearAndUpdateImage, true); 345 updateImage(data(), ImageResourceContent::ClearAndUpdateImage, true);
342 clearData(); 346 clearData();
343 } 347 }
344 348
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 } 511 }
508 512
509 ResourcePriority ImageResource::priorityFromObservers() { 513 ResourcePriority ImageResource::priorityFromObservers() {
510 return getContent()->priorityFromObservers(); 514 return getContent()->priorityFromObservers();
511 } 515 }
512 516
513 void ImageResource::updateImage( 517 void ImageResource::updateImage(
514 PassRefPtr<SharedBuffer> sharedBuffer, 518 PassRefPtr<SharedBuffer> sharedBuffer,
515 ImageResourceContent::UpdateImageOption updateImageOption, 519 ImageResourceContent::UpdateImageOption updateImageOption,
516 bool allDataReceived) { 520 bool allDataReceived) {
517 getContent()->updateImage(std::move(sharedBuffer), updateImageOption, 521 auto result = getContent()->updateImage(std::move(sharedBuffer),
518 allDataReceived); 522 updateImageOption, allDataReceived);
523 if (result == ImageResourceContent::UpdateImageResult::ShouldDecodeError) {
524 // In case of decode error, we call imageNotifyFinished() iff we don't
525 // initiate reloading:
526 // [(a): when this is in the middle of loading, or (b): otherwise]
527 // 1. The updateImage() call above doesn't call notifyObservers().
528 // 2. notifyObservers(ShouldNotifyFinish) is called
529 // (a) via updateImage() called in ImageResource::finish()
530 // called via didFinishLoading() called in decodeError(), or
531 // (b) via updateImage() called in decodeError().
532 // imageNotifyFinished() is called here iff we will not initiate
533 // reloading in Step 3 due to notifyObservers()'s
534 // schedulingReloadOrShouldReloadBrokenPlaceholder() check.
535 // 3. reloadIfLoFiOrPlaceholderImage() is called via ResourceFetcher
536 // (a) via didFinishLoading() called in decodeError(), or
537 // (b) after returning ImageResource::updateImage().
538 decodeError(allDataReceived);
539 }
519 } 540 }
520 541
521 } // namespace blink 542 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698