Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/fetch/ResourceLoadPriorityOptimizer.h" | 32 #include "core/fetch/ResourceLoadPriorityOptimizer.h" |
| 33 #include "core/rendering/RenderObject.h" | |
| 34 | |
| 35 #include "wtf/Vector.h" | |
| 33 | 36 |
| 34 namespace WebCore { | 37 namespace WebCore { |
| 35 | 38 |
| 39 ResourceLoadPriorityOptimizer* resourceLoadPriorityOptimizer() | |
| 40 { | |
| 41 DEFINE_STATIC_LOCAL(ResourceLoadPriorityOptimizer, s_renderLoadOptimizer, () ); | |
| 42 return &s_renderLoadOptimizer; | |
| 43 } | |
| 44 | |
| 36 ResourceLoadPriorityOptimizer::ResourceAndVisibility::ResourceAndVisibility(Imag eResource* image, VisibilityStatus v) | 45 ResourceLoadPriorityOptimizer::ResourceAndVisibility::ResourceAndVisibility(Imag eResource* image, VisibilityStatus v) |
| 37 : imageResource(image) | 46 : imageResource(image) |
| 38 , status(v) | 47 , status(v) |
| 39 { | 48 { |
| 40 } | 49 } |
| 41 | 50 |
| 42 ResourceLoadPriorityOptimizer::ResourceAndVisibility::~ResourceAndVisibility() | 51 ResourceLoadPriorityOptimizer::ResourceAndVisibility::~ResourceAndVisibility() |
| 43 { | 52 { |
| 44 } | 53 } |
| 45 | 54 |
| 46 ResourceLoadPriorityOptimizer::ResourceLoadPriorityOptimizer() | 55 ResourceLoadPriorityOptimizer::ResourceLoadPriorityOptimizer() |
| 47 { | 56 { |
| 48 } | 57 } |
| 49 | 58 |
| 50 ResourceLoadPriorityOptimizer::~ResourceLoadPriorityOptimizer() | 59 ResourceLoadPriorityOptimizer::~ResourceLoadPriorityOptimizer() |
| 51 { | 60 { |
| 61 } | |
| 62 | |
| 63 void ResourceLoadPriorityOptimizer::addRenderObject(RenderObject* o) | |
|
esprehn
2014/01/15 01:27:45
object or renderer, no single letter vars please.
shatch
2014/01/15 19:28:52
Done.
| |
| 64 { | |
| 65 m_objectCache.add(o); | |
| 66 } | |
| 67 | |
| 68 void ResourceLoadPriorityOptimizer::removeRenderObject(RenderObject* o) | |
| 69 { | |
| 70 m_objectCache.remove(o); | |
|
esprehn
2014/01/15 01:27:45
m_objects or something, I'd not use objectCache, t
shatch
2014/01/15 19:28:52
Done.
| |
| 71 } | |
| 72 | |
| 73 void ResourceLoadPriorityOptimizer::updateAllImageResourcePriorities() | |
| 74 { | |
| 75 m_imageResources.clear(); | |
| 76 | |
| 77 Vector<RenderObject*> objectsToRemove; | |
| 78 for (RenderObjectSet::iterator it = m_objectCache.begin(); it != m_objectCac he.end(); ++it) { | |
| 79 RenderObject* obj = *it; | |
| 80 if (!obj->updateImageLoadingPriorities()) { | |
| 81 objectsToRemove.append(obj); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 for (Vector<RenderObject*>::iterator it = objectsToRemove.begin(); it != obj ectsToRemove.end(); ++it) | |
| 86 m_objectCache.remove(*it); | |
| 87 | |
| 52 updateImageResourcesWithLoadPriority(); | 88 updateImageResourcesWithLoadPriority(); |
| 53 } | 89 } |
| 54 | 90 |
| 55 void ResourceLoadPriorityOptimizer::updateImageResourcesWithLoadPriority() | 91 void ResourceLoadPriorityOptimizer::updateImageResourcesWithLoadPriority() |
| 56 { | 92 { |
| 57 for (ImageResourceMap::iterator it = m_imageResources.begin(); it != m_image Resources.end(); ++it) { | 93 for (ImageResourceMap::iterator it = m_imageResources.begin(); it != m_image Resources.end(); ++it) { |
| 58 ResourceLoadPriority priority = it->value->status == Visible ? | 94 ResourceLoadPriority priority = it->value->status == Visible ? |
| 59 ResourceLoadPriorityLow : ResourceLoadPriorityVeryLow; | 95 ResourceLoadPriorityLow : ResourceLoadPriorityVeryLow; |
| 60 | 96 |
| 61 if (priority != it->value->imageResource->resourceRequest().priority()) { | 97 if (priority != it->value->imageResource->resourceRequest().priority()) { |
| 62 it->value->imageResource->resourceRequest().setPriority(priority); | 98 it->value->imageResource->resourceRequest().setPriority(priority); |
| 63 it->value->imageResource->didChangePriority(priority); | 99 it->value->imageResource->didChangePriority(priority); |
| 64 } | 100 } |
| 65 } | 101 } |
| 66 m_imageResources.clear(); | 102 m_imageResources.clear(); |
| 67 } | 103 } |
| 68 | 104 |
| 69 void ResourceLoadPriorityOptimizer::notifyImageResourceVisibility(ImageResource* img, VisibilityStatus status) | 105 void ResourceLoadPriorityOptimizer::notifyImageResourceVisibility(ImageResource* img, VisibilityStatus status) |
| 70 { | 106 { |
| 71 if (!img || img->isLoaded()) | 107 if (!img || img->isLoaded()) |
| 72 return; | 108 return; |
| 73 | 109 |
| 74 ImageResourceMap::AddResult result = m_imageResources.add(img->identifier(), adoptPtr(new ResourceAndVisibility(img, status))); | 110 ImageResourceMap::AddResult result = m_imageResources.add(img->identifier(), adoptPtr(new ResourceAndVisibility(img, status))); |
| 75 if (!result.isNewEntry && status == Visible) | 111 if (!result.isNewEntry && status == Visible) |
| 76 result.iterator->value->status = status; | 112 result.iterator->value->status = status; |
| 77 } | 113 } |
| 78 | 114 |
| 79 } | 115 } |
| OLD | NEW |