Commit cf4d5ea2 authored by François Degros's avatar François Degros Committed by Commit Bot

[Files app] Linearized parts of VolumeManager with async / await.

Replaced some Promise continuations with async / await.

Change-Id: I054faccd3e4b60c562a72e981fae86fc06ec2e97
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1619502
Auto-Submit: François Degros <fdegros@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#661265}
parent 9b784f04
...@@ -74,51 +74,47 @@ class VolumeManagerImpl extends cr.EventTarget { ...@@ -74,51 +74,47 @@ class VolumeManagerImpl extends cr.EventTarget {
* @return {!Promise<!VolumeInfo>} * @return {!Promise<!VolumeInfo>}
* @private * @private
*/ */
addVolumeMetadata_(volumeMetadata) { async addVolumeMetadata_(volumeMetadata) {
return volumeManagerUtil.createVolumeInfo(volumeMetadata) const volumeInfo = await volumeManagerUtil.createVolumeInfo(volumeMetadata);
.then(
/** // We don't show Downloads and Drive on volume list if they have
* @param {!VolumeInfo} volumeInfo // mount error, since users can do nothing in this situation. We
* @return {!VolumeInfo} // show Removable and Provided volumes regardless of mount error
*/ // so that users can unmount or format the volume.
volumeInfo => { // TODO(fukino): Once the Files app gets ready, show erroneous
// We don't show Downloads and Drive on volume list if they have // Drive volume so that users can see auth warning banner on the
// mount error, since users can do nothing in this situation. We // volume. crbug.com/517772.
// show Removable and Provided volumes regardless of mount error let shouldShow = true;
// so that users can unmount or format the volume. switch (volumeInfo.volumeType) {
// TODO(fukino): Once the Files app gets ready, show erroneous case VolumeManagerCommon.VolumeType.DOWNLOADS:
// Drive volume so that users can see auth warning banner on the case VolumeManagerCommon.VolumeType.DRIVE:
// volume. crbug.com/517772. shouldShow = !!volumeInfo.fileSystem;
let shouldShow = true; break;
switch (volumeInfo.volumeType) { }
case VolumeManagerCommon.VolumeType.DOWNLOADS:
case VolumeManagerCommon.VolumeType.DRIVE: if (!shouldShow) {
shouldShow = !!volumeInfo.fileSystem; return volumeInfo;
break; }
}
if (!shouldShow) { if (this.volumeInfoList.findIndex(volumeInfo.volumeId) === -1) {
return volumeInfo; this.volumeInfoList.add(volumeInfo);
}
if (this.volumeInfoList.findIndex(volumeInfo.volumeId) === -1) { // Update the network connection status, because until the drive
this.volumeInfoList.add(volumeInfo); // is initialized, the status is set to not ready.
// TODO(mtomasz): The connection status should be migrated into
// Update the network connection status, because until the drive // chrome.fileManagerPrivate.VolumeMetadata.
// is initialized, the status is set to not ready. if (volumeMetadata.volumeType === VolumeManagerCommon.VolumeType.DRIVE) {
// TODO(mtomasz): The connection status should be migrated into this.onDriveConnectionStatusChanged_();
// chrome.fileManagerPrivate.VolumeMetadata. }
if (volumeMetadata.volumeType === } else if (
VolumeManagerCommon.VolumeType.DRIVE) { volumeMetadata.volumeType ===
this.onDriveConnectionStatusChanged_(); VolumeManagerCommon.VolumeType.REMOVABLE) {
} // Update for remounted USB external storage, because they were
} else if ( // remounted to switch read-only policy.
volumeMetadata.volumeType === this.volumeInfoList.add(volumeInfo);
VolumeManagerCommon.VolumeType.REMOVABLE) { }
// Update for remounted USB external storage, because they were
// remounted to switch read-only policy. return volumeInfo;
this.volumeInfoList.add(volumeInfo);
}
return volumeInfo;
});
} }
/** /**
...@@ -166,59 +162,59 @@ class VolumeManagerImpl extends cr.EventTarget { ...@@ -166,59 +162,59 @@ class VolumeManagerImpl extends cr.EventTarget {
* @private * @private
*/ */
onMountCompleted_(event) { onMountCompleted_(event) {
this.mountQueue_.run(callback => { this.mountQueue_.run(async (callback) => {
switch (event.eventType) { try {
case 'mount': switch (event.eventType) {
var requestKey = this.makeRequestKey_( case 'mount':
'mount', event.volumeMetadata.sourcePath || ''); var requestKey = this.makeRequestKey_(
'mount', event.volumeMetadata.sourcePath || '');
if (event.status === 'success' ||
event.status === if (event.status === 'success' ||
VolumeManagerCommon.VolumeError.UNKNOWN_FILESYSTEM || event.status ===
event.status === VolumeManagerCommon.VolumeError.UNKNOWN_FILESYSTEM ||
VolumeManagerCommon.VolumeError.UNSUPPORTED_FILESYSTEM) { event.status ===
this.addVolumeMetadata_(event.volumeMetadata).then(volumeInfo => { VolumeManagerCommon.VolumeError.UNSUPPORTED_FILESYSTEM) {
const volumeInfo =
await this.addVolumeMetadata_(event.volumeMetadata);
this.finishRequest_(requestKey, event.status, volumeInfo); this.finishRequest_(requestKey, event.status, volumeInfo);
callback(); } else if (
}); event.status ===
} else if ( VolumeManagerCommon.VolumeError.ALREADY_MOUNTED) {
event.status === const navigationEvent =
VolumeManagerCommon.VolumeError.ALREADY_MOUNTED) { new Event(VolumeManagerCommon.VOLUME_ALREADY_MOUNTED);
const navigationEvent = navigationEvent.volumeId = event.volumeMetadata.volumeId;
new Event(VolumeManagerCommon.VOLUME_ALREADY_MOUNTED); this.dispatchEvent(navigationEvent);
navigationEvent.volumeId = event.volumeMetadata.volumeId; this.finishRequest_(requestKey, event.status);
this.dispatchEvent(navigationEvent); } else {
this.finishRequest_(requestKey, event.status); console.warn('Failed to mount a volume: ' + event.status);
callback(); this.finishRequest_(requestKey, event.status);
} else { }
console.warn('Failed to mount a volume: ' + event.status); break;
this.finishRequest_(requestKey, event.status);
callback(); case 'unmount':
} const volumeId = event.volumeMetadata.volumeId;
break; const status = event.status;
var requestKey = this.makeRequestKey_('unmount', volumeId);
case 'unmount': const requested = requestKey in this.requests_;
const volumeId = event.volumeMetadata.volumeId; const volumeInfoIndex = this.volumeInfoList.findIndex(volumeId);
const status = event.status; const volumeInfo = volumeInfoIndex !== -1 ?
var requestKey = this.makeRequestKey_('unmount', volumeId); this.volumeInfoList.item(volumeInfoIndex) :
const requested = requestKey in this.requests_; null;
const volumeInfoIndex = this.volumeInfoList.findIndex(volumeId); if (event.status === 'success' && !requested && volumeInfo) {
const volumeInfo = volumeInfoIndex !== -1 ? console.warn('Unmounted volume without a request: ' + volumeId);
this.volumeInfoList.item(volumeInfoIndex) : this.dispatchEvent(new CustomEvent(
null; 'externally-unmounted', {detail: volumeInfo}));
if (event.status === 'success' && !requested && volumeInfo) { }
console.warn('Unmounted volume without a request: ' + volumeId);
this.dispatchEvent( this.finishRequest_(requestKey, status);
new CustomEvent('externally-unmounted', {detail: volumeInfo})); if (event.status === 'success') {
} this.volumeInfoList.remove(event.volumeMetadata.volumeId);
}
this.finishRequest_(requestKey, status); console.warn('unmounted volume: ' + volumeId);
if (event.status === 'success') { break;
this.volumeInfoList.remove(event.volumeMetadata.volumeId); }
} } finally {
console.warn('unmounted volume: ' + volumeId); callback();
callback();
break;
} }
}); });
} }
......
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