Index: Source/core/fetch/ResourceLoadPriorityOptimizer.cpp |
diff --git a/Source/core/fetch/ResourceLoadPriorityOptimizer.cpp b/Source/core/fetch/ResourceLoadPriorityOptimizer.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..483f2eb21582f8e2e4f9c156f02dc04b58cdf0d7 |
--- /dev/null |
+++ b/Source/core/fetch/ResourceLoadPriorityOptimizer.cpp |
@@ -0,0 +1,91 @@ |
+/* |
+ * Copyright (C) 2013 Google Inc. All rights reserved. |
+ * |
+ * Redistribution and use in source and binary forms, with or without |
+ * modification, are permitted provided that the following conditions are |
+ * met: |
+ * |
+ * * Redistributions of source code must retain the above copyright |
+ * notice, this list of conditions and the following disclaimer. |
+ * * Redistributions in binary form must reproduce the above |
+ * copyright notice, this list of conditions and the following disclaimer |
+ * in the documentation and/or other materials provided with the |
+ * distribution. |
+ * * Neither the name of Google Inc. nor the names of its |
+ * contributors may be used to endorse or promote products derived from |
+ * this software without specific prior written permission. |
+ * |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ */ |
+ |
+#include "config.h" |
+#include "core/fetch/ResourceLoadPriorityOptimizer.h" |
+ |
+namespace WebCore { |
+ |
+ResourceLoadPriorityOptimizer::ResourceAndVisibility::ResourceAndVisibility(ImageResource* img, bool v) |
+ : imageResource(img) |
+ , visible(v) |
+{ |
+} |
+ |
+ResourceLoadPriorityOptimizer::ResourceAndVisibility::ResourceAndVisibility() |
eseidel
2013/11/25 23:59:30
Shoud this just have one constructor and have it h
shatch
2013/11/26 01:35:18
Both std::map and HashMap seem to want a default c
|
+ : imageResource(0) |
+ , visible(false) |
+{ |
+} |
+ |
+ResourceLoadPriorityOptimizer::ResourceAndVisibility::ResourceAndVisibility(const ResourceLoadPriorityOptimizer::ResourceAndVisibility& o) |
eseidel
2013/11/25 23:59:30
Again, my C++ is a bit weak here. How is this dif
shatch
2013/11/26 01:35:18
Yeah I think you're right, it's not any different,
|
+ : imageResource(o.imageResource) |
+ , visible(o.visible) |
+{ |
+} |
+ |
+ResourceLoadPriorityOptimizer::ResourceAndVisibility::~ResourceAndVisibility() |
+{ |
+} |
+ |
+ResourceLoadPriorityOptimizer::ResourceLoadPriorityOptimizer() |
+{ |
+} |
+ |
+ResourceLoadPriorityOptimizer::~ResourceLoadPriorityOptimizer() |
+{ |
+ updateImageResourcesWithLoadPriority(); |
+} |
+ |
+void ResourceLoadPriorityOptimizer::updateImageResourcesWithLoadPriority() |
+{ |
+ for (ImageResourceMap::iterator it = m_imageResources.begin(); it != m_imageResources.end(); ++it) { |
+ ResourceLoadPriority priority = it->second.visible ? ResourceLoadPriorityLow : ResourceLoadPriorityVeryLow; |
+ it->second.imageResource->didChangePriority(priority); |
+ } |
+ m_imageResources.clear(); |
+} |
+ |
+void ResourceLoadPriorityOptimizer::notifyImageResourceVisibility(ImageResource* img, bool visible) |
+{ |
+ if (!img || img->isLoaded()) |
+ return; |
+ |
+ if (visible) { |
+ m_imageResources[img->identifier()] = ResourceAndVisibility(img, visible); |
+ } else { |
+ // If the resource exists in the map, don't overwrite since it might have been visible from |
+ // some other RenderObject. |
+ if (m_imageResources.find(img->identifier()) == m_imageResources.end()) |
eseidel
2013/11/25 23:59:30
I'm surprised this doesn't have a .contains()? I
shatch
2013/11/26 01:35:18
Yeah it was a std::map, don't believe it has a con
|
+ m_imageResources[img->identifier()] = ResourceAndVisibility(img, visible); |
+ } |
+} |
+ |
+} |