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

Side by Side Diff: chrome/browser/resources/image_loader/client.js

Issue 14623021: Introduce a priority queue to the image loader. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var ImageLoader = ImageLoader || {}; 5 var ImageLoader = ImageLoader || {};
6 6
7 /** 7 /**
8 * Image loader's extension id. 8 * Image loader's extension id.
9 * @const 9 * @const
10 * @type {string} 10 * @type {string}
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 /** 262 /**
263 * Saves an image in the cache. 263 * Saves an image in the cache.
264 * 264 *
265 * @param {string} key Cache key. 265 * @param {string} key Cache key.
266 * @param {string} data Image data. 266 * @param {string} data Image data.
267 * @param {number=} opt_timestamp Last modification timestamp. Used to detect 267 * @param {number=} opt_timestamp Last modification timestamp. Used to detect
268 * if the cache entry becomes out of date. 268 * if the cache entry becomes out of date.
269 */ 269 */
270 ImageLoader.Client.Cache.prototype.saveImage = function( 270 ImageLoader.Client.Cache.prototype.saveImage = function(
271 key, data, opt_timestamp) { 271 key, data, opt_timestamp) {
272
273 // If the image is currently in cache, then remove it. 272 // If the image is currently in cache, then remove it.
274 if (this.images_[key]) 273 if (this.images_[key])
275 this.removeImage(key); 274 this.removeImage(key);
276 275
277 if (ImageLoader.Client.Cache.MEMORY_LIMIT - this.size_ < data.length) { 276 if (ImageLoader.Client.Cache.MEMORY_LIMIT - this.size_ < data.length) {
278 ImageLoader.Client.recordBinary('Evicted', 1); 277 ImageLoader.Client.recordBinary('Evicted', 1);
279 this.evictCache_(data.length); 278 this.evictCache_(data.length);
280 } else { 279 } else {
281 ImageLoader.Client.recordBinary('Evicted', 0); 280 ImageLoader.Client.recordBinary('Evicted', 0);
282 } 281 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 * @param {Object} options Loader options, such as: orientation, scale, 345 * @param {Object} options Loader options, such as: orientation, scale,
347 * maxHeight, width, height and/or cache. 346 * maxHeight, width, height and/or cache.
348 * @param {function=} onSuccess Callback for success. 347 * @param {function=} onSuccess Callback for success.
349 * @param {function=} onError Callback for failure. 348 * @param {function=} onError Callback for failure.
350 * @param {function=} opt_isValid Function returning false in case 349 * @param {function=} opt_isValid Function returning false in case
351 * a request is not valid anymore, eg. parent node has been detached. 350 * a request is not valid anymore, eg. parent node has been detached.
352 * @return {?number} Remote task id or null if loaded from cache. 351 * @return {?number} Remote task id or null if loaded from cache.
353 */ 352 */
354 ImageLoader.Client.loadToImage = function(url, image, options, onSuccess, 353 ImageLoader.Client.loadToImage = function(url, image, options, onSuccess,
355 onError, opt_isValid) { 354 onError, opt_isValid) {
355 options.cache = false;
356 var callback = function(result) { 356 var callback = function(result) {
357 if (result.status == 'error') { 357 if (result.status == 'error') {
358 onError(); 358 onError();
359 return; 359 return;
360 } 360 }
361 image.src = result.data; 361 image.src = result.data;
362 onSuccess(); 362 onSuccess();
363 }; 363 };
364 364
365 return ImageLoader.Client.getInstance().load( 365 return ImageLoader.Client.getInstance().load(
366 url, callback, options, opt_isValid); 366 url, callback, options, opt_isValid);
367 }; 367 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698