0

[piexwasm] Remove PiexLoader member from ImageLoader instance

Class ImageLoader is singleton. It creates a new PiexLoader() when its
singleton instance is created, then passes it to the only user of that
PiexLoader, namely ImageRequestTask, on each image loader request.

But the PiexLoader passed is a singleton instance, because ImageLoader
is a singleton instance ;)

Remove this leaky abstraction. ImageLoader does not need to know about
PiexLoader. That is an internal detail of ImageRequestTask, and it can
create its own PiexLoader() singleton instance. Do that, and fix BUILD
rule deps: image_request_task depends on piex_loader, end of story.

No change in behavior. Covered by existing tests.

Bug: 1132695
No-try: true
Change-Id: I2b5ccfabe24d7ccaca2ed0ef01d2266b6e1ff25d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2437579
Commit-Queue: Noel Gordon <noel@chromium.org>
Commit-Queue: Alex Danilo <adanilo@chromium.org>
Auto-Submit: Noel Gordon <noel@chromium.org>
Reviewed-by: Alex Danilo <adanilo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811621}
This commit is contained in:
Noel Gordon
2020-09-29 09:58:21 +00:00
committed by Commit Bot
parent 02c619dc3b
commit 89643447c4
3 changed files with 16 additions and 18 deletions

@ -41,7 +41,6 @@ js_library("image_loader") {
":cache",
":image_request_task",
":load_image_request",
":piex_loader",
":scheduler",
"//ui/file_manager/externs:file_manager_private",
]

@ -21,12 +21,6 @@ function ImageLoader() {
*/
this.scheduler_ = new Scheduler();
/**
* Piex loader for RAW images.
* @private {!PiexLoader}
*/
this.piexLoader_ = new PiexLoader();
// Grant permissions to all volumes, initialize the cache and then start the
// scheduler.
chrome.fileManagerPrivate.getVolumeMetadataList(function(volumeMetadataList) {
@ -155,8 +149,8 @@ ImageLoader.prototype.onMessage_ = function(senderOrigin, request, callback) {
return false; // No callback calls.
} else {
// Create a request task and add it to the scheduler (queue).
const requestTask = new ImageRequestTask(
requestId, this.cache_, this.piexLoader_, request, callback);
const requestTask =
new ImageRequestTask(requestId, this.cache_, request, callback);
this.scheduler_.add(requestTask);
return true; // Request will call the callback.
}

@ -8,12 +8,11 @@
*
* @param {string} id Request ID.
* @param {ImageCache} cache Cache object.
* @param {!PiexLoader} piexLoader Piex loader for RAW file.
* @param {!LoadImageRequest} request Request message as a hash array.
* @param {function(!LoadImageResponse)} callback Response handler.
* @constructor
*/
function ImageRequestTask(id, cache, piexLoader, request, callback) {
function ImageRequestTask(id, cache, request, callback) {
/**
* Global ID (concatenated client ID and client request ID).
* @type {string}
@ -27,12 +26,6 @@ function ImageRequestTask(id, cache, piexLoader, request, callback) {
*/
this.cache_ = cache;
/**
* @type {!PiexLoader}
* @private
*/
this.piexLoader_ = piexLoader;
/**
* @type {!LoadImageRequest}
* @private
@ -339,7 +332,8 @@ ImageRequestTask.prototype.downloadOriginal_ = function(onSuccess, onFailure) {
// Load RAW image source thumbnail.
if (fileType.type === 'raw') {
this.piexLoader_.load(this.request_.url, chrome.runtime.reload)
const piexLoader = ImageRequestTask.getPiexLoaderInstance();
piexLoader.load(this.request_.url, chrome.runtime.reload)
.then(
function(data) {
this.request_.orientation =
@ -636,3 +630,14 @@ ImageRequestTask.prototype.cleanup_ = function() {
this.canvas_.width = 0;
this.canvas_.height = 0;
};
/**
* Returns the singleton instance of the PiexLoader RAW image loader.
* @return {!PiexLoader} PiexLoader object.
*/
ImageRequestTask.getPiexLoaderInstance = function() {
if (!ImageRequestTask.piexLoaderInstance_) {
ImageRequestTask.piexLoaderInstance_ = new PiexLoader();
}
return ImageRequestTask.piexLoaderInstance_;
};