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

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

Issue 2746343002: Phase III Step 1: Make ImageResourceContent manage its own ResourceStatus (Closed)
Patch Set: Rewind Created 3 years, 9 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 const KURL& url() const override { return m_resource->url(); } 72 const KURL& url() const override { return m_resource->url(); }
73 bool hasDevicePixelRatioHeaderValue() const override { 73 bool hasDevicePixelRatioHeaderValue() const override {
74 return m_resource->m_hasDevicePixelRatioHeaderValue; 74 return m_resource->m_hasDevicePixelRatioHeaderValue;
75 } 75 }
76 float devicePixelRatioHeaderValue() const override { 76 float devicePixelRatioHeaderValue() const override {
77 return m_resource->m_devicePixelRatioHeaderValue; 77 return m_resource->m_devicePixelRatioHeaderValue;
78 } 78 }
79 const ResourceResponse& response() const override { 79 const ResourceResponse& response() const override {
80 return m_resource->response(); 80 return m_resource->response();
81 } 81 }
82 ResourceStatus getStatus() const override { return m_resource->getStatus(); }
83 bool shouldShowPlaceholder() const override { 82 bool shouldShowPlaceholder() const override {
84 return m_resource->shouldShowPlaceholder(); 83 return m_resource->shouldShowPlaceholder();
85 } 84 }
86 bool isCacheValidator() const override { 85 bool isCacheValidator() const override {
87 return m_resource->isCacheValidator(); 86 return m_resource->isCacheValidator();
88 } 87 }
89 bool isAccessAllowed( 88 bool isAccessAllowed(
90 SecurityOrigin* securityOrigin, 89 SecurityOrigin* securityOrigin,
91 DoesCurrentFrameHaveSingleSecurityOrigin 90 DoesCurrentFrameHaveSingleSecurityOrigin
92 doesCurrentFrameHasSingleSecurityOrigin) const override { 91 doesCurrentFrameHasSingleSecurityOrigin) const override {
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 if (loader()) 326 if (loader())
328 loader()->reloadIfLoFiOrPlaceholderImage(this); 327 loader()->reloadIfLoFiOrPlaceholderImage(this);
329 328
330 // Finishes loading if needed, and notifies observers. 329 // Finishes loading if needed, and notifies observers.
331 if (!allDataReceived && loader()) { 330 if (!allDataReceived && loader()) {
332 // Observers are notified via ImageResource::finish(). 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);
335 } else if (getContent()) { 334 } else if (getContent()) {
336 auto result = getContent()->updateImage( 335 auto result = getContent()->updateImage(
337 nullptr, ImageResourceContent::ClearImageAndNotifyObservers, 336 nullptr, getStatus(),
338 allDataReceived); 337 ImageResourceContent::ClearImageAndNotifyObservers, allDataReceived);
339 DCHECK_EQ(result, ImageResourceContent::UpdateImageResult::NoDecodeError); 338 DCHECK_EQ(result, ImageResourceContent::UpdateImageResult::NoDecodeError);
340 } 339 }
341 340
342 memoryCache()->remove(this); 341 memoryCache()->remove(this);
343 } 342 }
344 343
345 void ImageResource::updateImageAndClearBuffer() { 344 void ImageResource::updateImageAndClearBuffer() {
346 updateImage(data(), ImageResourceContent::ClearAndUpdateImage, true); 345 updateImage(data(), ImageResourceContent::ClearAndUpdateImage, true);
347 clearData(); 346 clearData();
348 } 347 }
349 348
349 void ImageResource::notifyStartLoad() {
350 if (!getContent())
351 return;
352 CHECK_EQ(getStatus(), ResourceStatus::Pending);
353 getContent()->notifyStartLoad();
354 }
355
350 void ImageResource::finish(double loadFinishTime) { 356 void ImageResource::finish(double loadFinishTime) {
351 if (m_multipartParser) { 357 if (m_multipartParser) {
352 m_multipartParser->finish(); 358 m_multipartParser->finish();
353 if (data()) 359 if (data())
354 updateImageAndClearBuffer(); 360 updateImageAndClearBuffer();
355 } else { 361 } else {
356 updateImage(data(), ImageResourceContent::UpdateImage, true); 362 updateImage(data(), ImageResourceContent::UpdateImage, true);
357 // As encoded image data can be created from m_image (see 363 // As encoded image data can be created from m_image (see
358 // ImageResource::resourceBuffer(), we don't have to keep m_data. Let's 364 // ImageResource::resourceBuffer(), we don't have to keep m_data. Let's
359 // clear this. As for the lifetimes of m_image and m_data, see this 365 // clear this. As for the lifetimes of m_image and m_data, see this
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 return ResourcePriority(); 590 return ResourcePriority();
585 return getContent()->priorityFromObservers(); 591 return getContent()->priorityFromObservers();
586 } 592 }
587 593
588 void ImageResource::updateImage( 594 void ImageResource::updateImage(
589 PassRefPtr<SharedBuffer> sharedBuffer, 595 PassRefPtr<SharedBuffer> sharedBuffer,
590 ImageResourceContent::UpdateImageOption updateImageOption, 596 ImageResourceContent::UpdateImageOption updateImageOption,
591 bool allDataReceived) { 597 bool allDataReceived) {
592 if (!getContent()) 598 if (!getContent())
593 return; 599 return;
594 auto result = getContent()->updateImage(std::move(sharedBuffer), 600 auto result = getContent()->updateImage(std::move(sharedBuffer), getStatus(),
595 updateImageOption, allDataReceived); 601 updateImageOption, allDataReceived);
596 if (result == ImageResourceContent::UpdateImageResult::ShouldDecodeError) { 602 if (result == ImageResourceContent::UpdateImageResult::ShouldDecodeError) {
597 // TODO before commit (hiroshige): Update the comment. 603 // TODO before commit (hiroshige): Update the comment.
598 // In case of decode error, we call imageNotifyFinished() iff we don't 604 // In case of decode error, we call imageNotifyFinished() iff we don't
599 // initiate reloading: 605 // initiate reloading:
600 // [(a): when this is in the middle of loading, or (b): otherwise] 606 // [(a): when this is in the middle of loading, or (b): otherwise]
601 // 1. The updateImage() call above doesn't call notifyObservers(). 607 // 1. The updateImage() call above doesn't call notifyObservers().
602 // 2. notifyObservers(ShouldNotifyFinish) is called 608 // 2. notifyObservers(ShouldNotifyFinish) is called
603 // (a) via updateImage() called in ImageResource::finish() 609 // (a) via updateImage() called in ImageResource::finish()
604 // called via didFinishLoading() called in decodeError(), or 610 // called via didFinishLoading() called in decodeError(), or
605 // (b) via updateImage() called in decodeError(). 611 // (b) via updateImage() called in decodeError().
606 // imageNotifyFinished() is called here iff we will not initiate 612 // imageNotifyFinished() is called here iff we will not initiate
607 // reloading in Step 3 due to notifyObservers()'s 613 // reloading in Step 3 due to notifyObservers()'s
608 // schedulingReloadOrShouldReloadBrokenPlaceholder() check. 614 // schedulingReloadOrShouldReloadBrokenPlaceholder() check.
609 // 3. reloadIfLoFiOrPlaceholderImage() is called via ResourceFetcher 615 // 3. reloadIfLoFiOrPlaceholderImage() is called via ResourceFetcher
610 // (a) via didFinishLoading() called in decodeError(), or 616 // (a) via didFinishLoading() called in decodeError(), or
611 // (b) after returning ImageResource::updateImage(). 617 // (b) after returning ImageResource::updateImage().
612 decodeError(allDataReceived); 618 decodeError(allDataReceived);
613 } 619 }
614 } 620 }
615 621
616 } // namespace blink 622 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698