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

Refactoring. Extract some blocks as private functions.

This is preparation for fixing Issue 834675, where we will be changing
execution paths for these procedures based on input file locations.

Test: manually tested by zipping files on My Drive
Bug: 834675
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Iac3637d46760066b18c36e799448af5d7f6cd705
Reviewed-on: https://chromium-review.googlesource.com/1027332
Commit-Queue: Tatsuhisa Yamaguchi <yamaguchi@chromium.org>
Reviewed-by: default avatarYuki Awano <yawano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553484}
parent 095ec973
...@@ -213,23 +213,28 @@ unpacker.Compressor.prototype.getArchiveFile_ = function() { ...@@ -213,23 +213,28 @@ unpacker.Compressor.prototype.getArchiveFile_ = function() {
this.onErrorInternal_(); this.onErrorInternal_();
}); });
}; };
new Promise(function(resolve, reject) {
navigator.webkitTemporaryStorage this.getTemporaryRootEntry_().then(saveZipFile).catch((domException) => {
.queryUsageAndQuota(function(used, granted) { console.error(domException);
resolve(granted); this.onErrorInternal_();
}, reject); });
}) };
/**
* Creates a Promise which gives the root entry of a temporary filesystem.
* @return {!Promise<!Entry>}
*/
unpacker.Compressor.prototype.getTemporaryRootEntry_ = function() {
return new Promise(function(resolve, reject) {
navigator.webkitTemporaryStorage
.queryUsageAndQuota(function(used, granted) {
resolve(granted);
}, reject);
})
.then( .then(
(quota) => (quota) =>
new Promise(webkitRequestFileSystem.bind(null, TEMPORARY, quota))) new Promise(webkitRequestFileSystem.bind(null, TEMPORARY, quota)))
.then((fs) => { .then((fs) => fs.root);
saveZipFile(fs.root);
this.fs = fs.root;
})
.catch((domException) => {
console.error(domException);
this.onErrorInternal_();
});
}; };
/** /**
...@@ -587,31 +592,43 @@ unpacker.Compressor.prototype.moveZipFileToActualDestination = function() { ...@@ -587,31 +592,43 @@ unpacker.Compressor.prototype.moveZipFileToActualDestination = function() {
this.onErrorInternal_(); this.onErrorInternal_();
}); });
}; };
this.getParentEntry_()
.then(moveZipFileToParentDir)
.catch(this.onErrorInternal_.bind(this));
};
// Get all accessible volumes with their metadata /**
chrome.fileManagerPrivate.getVolumeMetadataList((volumeMetadataList) => { * Creates a Promise which gives the parent entry of the files to be zipped.
// Here we call chrome.fileSystem.requestFileSystem on each volume's * @rerturn {!Promise<!Entry>}
// metadata entry to be able to sucessfully execute * @private
// resolveIsolatedEntries later. */
Promise.all(this.requestAccessPermissionForVolumes_(volumeMetadataList)) unpacker.Compressor.prototype.getParentEntry_ = function() {
.then((result) => { return new Promise((resolve, reject) => {
chrome.fileManagerPrivate.resolveIsolatedEntries( // Get all accessible volumes with their metadata
[this.items_[0].entry], (result) => { chrome.fileManagerPrivate.getVolumeMetadataList((volumeMetadataList) => {
if (result && result.length >= 1) { // Here we call chrome.fileSystem.requestFileSystem on each volume's
result[0].getParent(moveZipFileToParentDir); // metadata entry to be able to sucessfully execute
} else { // resolveIsolatedEntries later.
console.error('Failed to resolve isolated entries!'); Promise.all(this.requestAccessPermissionForVolumes_(volumeMetadataList))
if (chrome.runtime.lastError) .then((result) => {
console.error(chrome.runtime.lastError.message); chrome.fileManagerPrivate.resolveIsolatedEntries(
[this.items_[0].entry], (result) => {
this.onErrorInternal_(); if (result && result.length >= 1) {
} result[0].getParent(resolve);
}); } else {
}) console.error('Failed to resolve isolated entries!');
.catch((error) => { if (chrome.runtime.lastError)
console.error(error); console.error(chrome.runtime.lastError.message);
this.onErrorInternal_();
}); reject();
}
});
})
.catch((error) => {
console.error(error);
reject();
});
});
}); });
}; };
......
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