// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-'use strict';
-
/**
* Client used to connect to the remote ImageLoader extension. Client class runs
* in the extension, where the client.js is included (eg. Files.app).
function ImageLoaderClient() {
/**
* Hash array with active tasks.
- * @type {Object}
+ * @type {!Object}
* @private
*/
this.tasks_ = {};
/**
* Returns a singleton instance.
- * @return {Client} Client instance.
+ * @return {ImageLoaderClient} Client instance.
*/
ImageLoaderClient.getInstance = function() {
if (!ImageLoaderClient.instance_)
*/
ImageLoaderClient.sendMessage_ = function(request, opt_callback) {
opt_callback = opt_callback || function(response) {};
- var sendMessage = chrome.runtime ? chrome.runtime.sendMessage :
- chrome.extension.sendMessage;
- sendMessage(ImageLoaderClient.EXTENSION_ID, request, opt_callback);
+ chrome.runtime.sendMessage(
+ ImageLoaderClient.EXTENSION_ID, request, opt_callback);
};
/**
* which are not valid anymore, which will reduce cpu consumption.
*
* @param {string} url Url of the requested image.
- * @param {function} callback Callback used to return response.
+ * @param {function(Object)} callback Callback used to return response.
* @param {Object=} opt_options Loader options, such as: scale, maxHeight,
* width, height and/or cache.
* @param {function(): boolean=} opt_isValid Function returning false in case
*/
ImageLoaderClient.prototype.load = function(
url, callback, opt_options, opt_isValid) {
- opt_options = opt_options || {};
+ opt_options = /** @type {{cache: (boolean|undefined)}} */(opt_options || {});
opt_isValid = opt_isValid || function() { return true; };
// Record cache usage.
var task = this.tasks_[taskKey];
if (!task.isValid()) {
// Cancel this task since it is not valid anymore.
- this.cancel(taskKey);
+ this.cancel(parseInt(taskKey, 10));
delete this.tasks_[taskKey];
}
}
var cacheKey = ImageLoaderClient.Cache.createKey(url, opt_options);
if (opt_options.cache) {
// Load from cache.
- ImageLoaderClient.recordBinary('Cached', 1);
+ ImageLoaderClient.recordBinary('Cached', true);
var cachedData = this.cache_.loadImage(cacheKey, opt_options.timestamp);
if (cachedData) {
- ImageLoaderClient.recordBinary('Cache.HitMiss', 1);
+ ImageLoaderClient.recordBinary('Cache.HitMiss', true);
callback({status: 'success', data: cachedData});
return null;
} else {
- ImageLoaderClient.recordBinary('Cache.HitMiss', 0);
+ ImageLoaderClient.recordBinary('Cache.HitMiss', false);
}
} else {
// Remove from cache.
- ImageLoaderClient.recordBinary('Cached', 0);
+ ImageLoaderClient.recordBinary('Cached', false);
this.cache_.removeImage(cacheKey);
}
this.removeImage(key);
if (ImageLoaderClient.Cache.MEMORY_LIMIT - this.size_ < data.length) {
- ImageLoaderClient.recordBinary('Evicted', 1);
+ ImageLoaderClient.recordBinary('Evicted', true);
this.evictCache_(data.length);
} else {
- ImageLoaderClient.recordBinary('Evicted', 0);
+ ImageLoaderClient.recordBinary('Evicted', false);
}
if (ImageLoaderClient.Cache.MEMORY_LIMIT - this.size_ >= data.length) {
* which are not valid anymore, which will reduce cpu consumption.
*
* @param {string} url Url of the requested image.
- * @param {Image} image Image node to load the requested picture into.
+ * @param {HTMLImageElement} image Image node to load the requested picture
+ * into.
* @param {Object} options Loader options, such as: orientation, scale,
* maxHeight, width, height and/or cache.
- * @param {function} onSuccess Callback for success.
- * @param {function} onError Callback for failure.
- * @param {function=} opt_isValid Function returning false in case
+ * @param {function()} onSuccess Callback for success.
+ * @param {function()} onError Callback for failure.
+ * @param {function(): boolean=} opt_isValid Function returning false in case
* a request is not valid anymore, eg. parent node has been detached.
* @return {?number} Remote task id or null if loaded from cache.
*/