Commit f22c91d3 authored by Tatsuhisa Yamaguchi's avatar Tatsuhisa Yamaguchi Committed by Commit Bot

Zip Archiver: Prevent duplicated loading when opening ZIP file in Drive.

Once loading of an archive has been started, it should not start loading
the same file again.
Existing logic returns "EXISTS" error via fileSystemProvider API when
an archive is already mounted.
However, it missed handling of a case where user requested opening the
same archive while its loading is ongoing.
It typically happens when an archive is on Drive and not yet cached.

As a transitive fix, this change reuses the "scanning..." message to
indiacte that user need to wait operation finish in such case.

Bug: 807254
Test: manually tested on Files app as noted in the bug.
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I90d5b8b2c157ea40b40ad106bbcb85b1bd022ea7
Reviewed-on: https://chromium-review.googlesource.com/895424
Commit-Queue: Tatsuhisa Yamaguchi <yamaguchi@chromium.org>
Reviewed-by: default avatarYuki Awano <yawano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533292}
parent a4568da1
......@@ -75,6 +75,12 @@ unpacker.app = {
*/
volumeLoadedPromises: {},
/**
* A map to indicate whether a volume's metadata load is finished.
* @type {!Object<!unpacker.types.FileSystemId, boolean>}
*/
volumeLoadFinished: {},
/**
* A Promise used to postpone all calls to fileSystemProvider API after
* the NaCl module loads.
......@@ -339,6 +345,7 @@ unpacker.app = {
delete unpacker.app.volumes[fileSystemId];
// Allow mount after clean.
delete unpacker.app.volumeLoadedPromises[fileSystemId];
delete unpacker.app.volumeLoadFinished[fileSystemId];
if (Object.keys(unpacker.app.volumes).length === 0 &&
unpacker.app.mountProcessCounter === 0) {
......@@ -706,7 +713,8 @@ unpacker.app = {
// Decrement the counter that indicates the number of
// ongoing mount process.
unpacker.app.mountProcessCounter--;
if (error.message === 'EXISTS') {
if (error.message === 'EXISTS' ||
error.message === 'ALREADY_LOADING') {
if (opt_onError)
opt_onError(fileSystemId);
return;
......@@ -739,10 +747,26 @@ unpacker.app = {
opt_onSuccess(fileSystemId);
};
// Prevent loading a zip file duplicatedly when the extension
// is currently loading the same file.
if (unpacker.app.volumeLoadedPromises[fileSystemId] &&
!unpacker.app.volumeLoadFinished[fileSystemId]) {
onError({message: 'ALREADY_LOADING'}, fileSystemId);
chrome.notifications.create(
fileSystemId, {
type: 'basic',
iconUrl: chrome.runtime.getManifest().icons[128],
title: entry.name,
message: stringData['ZIP_ARCHIVER_MOUNTING_MESSAGE'],
},
function() {});
return;
}
var loadPromise = unpacker.app.loadVolume_(
fileSystemId, entry, {}, null /* passphrase */);
loadPromise
.then(function() {
unpacker.app.volumeLoadFinished[fileSystemId] = true;
chrome.fileSystemProvider.mount(
{
fileSystemId: fileSystemId,
......@@ -764,6 +788,7 @@ unpacker.app = {
});
unpacker.app.volumeLoadedPromises[fileSystemId] = loadPromise;
unpacker.app.volumeLoadFinished[fileSystemId] = false;
}.bind(null, item.entry));
});
})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment