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

Unified Diff: chrome/browser/resources/file_manager/js/image_editor/image_util.js

Issue 16124013: Fix infinite loading for small images in Files.app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/file_manager/js/image_editor/image_util.js
diff --git a/chrome/browser/resources/file_manager/js/image_editor/image_util.js b/chrome/browser/resources/file_manager/js/image_editor/image_util.js
index 33c527d53f028defe6abe241022fbf5973f64a4e..f5617177839ddf9ee59d4ceedf130babf47686cf 100644
--- a/chrome/browser/resources/file_manager/js/image_editor/image_util.js
+++ b/chrome/browser/resources/file_manager/js/image_editor/image_util.js
@@ -482,22 +482,29 @@ ImageUtil.ImageLoader.prototype.load = function(
// The clients of this class sometimes request the same url repeatedly.
// The onload fires only if the src is different from the previous value.
- // To work around that we reset the src temporarily to an 1x1 pixel.
- // Load an empty 1x1 pixel image first.
+ // To work around that we reset the src temporarily to an 1x1 pixel to force
+ // garbage collecting, and then resetting src to an empty value.
var resetImage = function(callback) {
- this.image_.onload = callback;
- this.image_.onerror = onError.bind(this, 'IMAGE_ERROR');
- this.image_.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAA' +
+ var clearSrc = function() {
+ this.image_.onload = callback;
+ this.image_.onerror = callback;
+ this.image_.src = '';
+ }.bind(this);
+ var emptyImage = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAA' +
'AAABAAEAAAICTAEAOw==';
+ if (this.image_.src != emptyImage) {
+ // Load an empty image, then clear src.
+ this.image_.onload = clearSrc;
+ this.image_.onerror = onError.bind(this, 'IMAGE_ERROR');
+ this.image_.src = emptyImage;
+ } else {
+ // Empty image already loaded, so clear src immediately.
+ clearSrc();
+ }
}.bind(this);
- // Loads the image. If already loaded, then forces reloads.
- var startLoad = function() {
- if (this.image_.src == url)
- resetImage(loadImage);
- else
- loadImage();
- }.bind(this);
+ // Loads the image. If already loaded, then forces a reload.
+ var startLoad = resetImage.bind(this, loadImage);
if (opt_delay) {
this.timeout_ = setTimeout(startLoad, opt_delay);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698