Commit e7116472 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Reland "ES6 styles to onVolumeInfoListUpdated_ and setupCurrentDirectory_"

This reverts commit 1eeaf562.

Reason for revert: The culprit CL is this one here: crrev.com/c/1282517 which is already reverted: crrev.com/c/1287729.


Original change's description:
> Revert "ES6 styles to onVolumeInfoListUpdated_ and setupCurrentDirectory_"
> 
> This reverts commit 0ad9fe79.
> 
> Reason for revert: speculative revert, will revert the revert if not a root cause.
> 
> Bunch of Video/file-manager related tests started to fail:
> OpenVideoFiles/FilesAppBrowserTest.Test/videoOpenDrive_DriveFs
> OpenVideoFiles/FilesAppBrowserTest.Test/videoOpenDownloads
> VideoPlayerBrowserTest.OpenSingleVideoOnDrive
> VideoPlayerBrowserTest.OpenSingleVideoOnDownloads
> VideoPlayerBrowserTest.ClickControlButtons
> OpenVideoFiles/FilesAppBrowserTest.Test/videoOpenDownloads_GuestMode
> VideoPlayerBrowserTestInGuestMode.OpenSingleVideoOnDownloads
> VideoPlayerBrowserTest.CheckInitialElements
> OpenVideoFiles/FilesAppBrowserTest.Test/videoOpenDrive
> 
> Failures:
> https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/Linux%20ChromiumOS%20MSan%20Tests/9115
> https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/Linux%20ChromiumOS%20MSan%20Tests/9116
> 
> Original change's description:
> > ES6 styles to onVolumeInfoListUpdated_ and setupCurrentDirectory_
> > 
> > Appliy ES6 features to the DirectoryModel.onVolumeInfoListUpdated_ and
> > FileManager.setupCurrentDirectory_.
> > 
> > ES6 styles:
> > - Change var to const or let.
> > - Change anonymous functions+bind(this) to arrow functions.
> > 
> > Remove a TODO that linked to a closed bug.
> > 
> > Move comment to be before queue.run() to match the style of the
> > previous lines.
> > 
> > Apply the formatting from git cl format, which is slightly uglier, but
> > at least automatic. :-)
> > 
> > Test: No change in behaviour.
> > Change-Id: I5564263d44f8639d97fc86d7add5a59e8938be6d
> > Reviewed-on: https://chromium-review.googlesource.com/c/1286239
> > Reviewed-by: Joel Hockey <joelhockey@chromium.org>
> > Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#600312}
> 
> TBR=joelhockey@chromium.org,lucmult@chromium.org
> 
> Change-Id: I5f4aa388d2b88c5914c705c71b0fcc70904a42fe
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/c/1288169
> Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
> Commit-Queue: Kinuko Yasuda <kinuko@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#600640}

TBR=kinuko@chromium.org,joelhockey@chromium.org,lucmult@chromium.org

Change-Id: I7ce79f80a47367a2e5547e1bb3d5b227c40e77dd
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/1288091Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600646}
parent d7a963df
......@@ -1199,17 +1199,17 @@ DirectoryModel.prototype.onVolumeInfoListUpdated_ = function(event) {
// When the volume where we are is unmounted, fallback to the default volume's
// root. If current directory path is empty, stop the fallback
// since the current directory is initializing now.
var entry = this.getCurrentDirEntry();
const entry = this.getCurrentDirEntry();
if (entry && !this.volumeManager_.getVolumeInfo(entry)) {
this.volumeManager_.getDefaultDisplayRoot(function(displayRoot) {
this.volumeManager_.getDefaultDisplayRoot((displayRoot) => {
if (displayRoot)
this.changeDirectoryEntry(displayRoot);
}.bind(this));
});
}
// If a new file backed provided volume is mounted,
// then redirect to it in the focused window.
// If crostini is mounted, redirect even if window is not focussed.
// If crostini is mounted, redirect even if window is not focused.
// Note, that this is a temporary solution for https://crbug.com/427776.
if (event.added.length !== 1)
return;
......@@ -1217,11 +1217,11 @@ DirectoryModel.prototype.onVolumeInfoListUpdated_ = function(event) {
event.added[0].volumeType === VolumeManagerCommon.VolumeType.PROVIDED &&
event.added[0].source === VolumeManagerCommon.Source.FILE) ||
event.added[0].volumeType === VolumeManagerCommon.VolumeType.CROSTINI) {
event.added[0].resolveDisplayRoot().then(function(displayRoot) {
event.added[0].resolveDisplayRoot().then((displayRoot) => {
// Resolving a display root on FSP volumes is instant, despite the
// asynchronous call.
this.changeDirectoryEntry(event.added[0].displayRoot);
}.bind(this));
});
}
};
......
......@@ -1255,30 +1255,29 @@ FileManager.prototype = /** @struct */ {
* @private
*/
FileManager.prototype.setupCurrentDirectory_ = function() {
var tracker = this.directoryModel_.createDirectoryChangeTracker();
var queue = new AsyncUtil.Queue();
const tracker = this.directoryModel_.createDirectoryChangeTracker();
const queue = new AsyncUtil.Queue();
// Wait until the volume manager is initialized.
queue.run(function(callback) {
queue.run((callback) => {
tracker.start();
this.volumeManager_.ensureInitialized(callback);
}.bind(this));
});
var nextCurrentDirEntry;
var selectionEntry;
let nextCurrentDirEntry;
let selectionEntry;
// Resolve the selectionURL to selectionEntry or to currentDirectoryEntry
// in case of being a display root or a default directory to open files.
queue.run(function(callback) {
queue.run((callback) => {
if (!this.launchParams_.selectionURL) {
callback();
return;
}
window.webkitResolveLocalFileSystemURL(
this.launchParams_.selectionURL,
function(inEntry) {
var locationInfo = this.volumeManager_.getLocationInfo(inEntry);
this.launchParams_.selectionURL, (inEntry) => {
const locationInfo = this.volumeManager_.getLocationInfo(inEntry);
// If location information is not available, then the volume is
// no longer (or never) available.
if (!locationInfo) {
......@@ -1304,53 +1303,50 @@ FileManager.prototype = /** @struct */ {
selectionEntry = inEntry;
callback();
}.bind(this), callback);
}.bind(this));
}, callback);
});
// Resolve the currentDirectoryURL to currentDirectoryEntry (if not done
// by the previous step).
queue.run(function(callback) {
queue.run((callback) => {
if (nextCurrentDirEntry || !this.launchParams_.currentDirectoryURL) {
callback();
return;
}
window.webkitResolveLocalFileSystemURL(
this.launchParams_.currentDirectoryURL,
function(inEntry) {
var locationInfo = this.volumeManager_.getLocationInfo(inEntry);
this.launchParams_.currentDirectoryURL, (inEntry) => {
const locationInfo = this.volumeManager_.getLocationInfo(inEntry);
if (!locationInfo) {
callback();
return;
}
nextCurrentDirEntry = inEntry;
callback();
}.bind(this), callback);
// TODO(mtomasz): Implement reopening on special search, when fake
// entries are converted to directory providers. crbug.com/433161.
}.bind(this));
}, callback);
});
// If the directory to be changed to is not available, then first fallback
// to the parent of the selection entry.
queue.run(function(callback) {
queue.run((callback) => {
if (nextCurrentDirEntry || !selectionEntry) {
callback();
return;
}
selectionEntry.getParent(function(inEntry) {
selectionEntry.getParent((inEntry) => {
nextCurrentDirEntry = inEntry;
callback();
}.bind(this));
}.bind(this));
});
});
// Check if the next current directory is not a virtual directory which is
// not available in UI. This may happen to shared on Drive.
queue.run(function(callback) {
queue.run((callback) => {
if (!nextCurrentDirEntry) {
callback();
return;
}
var locationInfo = this.volumeManager_.getLocationInfo(
nextCurrentDirEntry);
const locationInfo =
this.volumeManager_.getLocationInfo(nextCurrentDirEntry);
// If we can't check, assume that the directory is illegal.
if (!locationInfo) {
nextCurrentDirEntry = null;
......@@ -1359,19 +1355,21 @@ FileManager.prototype = /** @struct */ {
}
// Having root directory of DRIVE_OTHER here should be only for shared
// with me files. Fallback to Drive root in such case.
if (locationInfo.isRootEntry && locationInfo.rootType ===
VolumeManagerCommon.RootType.DRIVE_OTHER) {
var volumeInfo = this.volumeManager_.getVolumeInfo(nextCurrentDirEntry);
if (locationInfo.isRootEntry &&
locationInfo.rootType === VolumeManagerCommon.RootType.DRIVE_OTHER) {
const volumeInfo =
this.volumeManager_.getVolumeInfo(nextCurrentDirEntry);
if (!volumeInfo) {
nextCurrentDirEntry = null;
callback();
return;
}
volumeInfo.resolveDisplayRoot().then(
function(entry) {
volumeInfo.resolveDisplayRoot()
.then((entry) => {
nextCurrentDirEntry = entry;
callback();
}).catch(function(error) {
})
.catch((error) => {
console.error(error.stack || error);
nextCurrentDirEntry = null;
callback();
......@@ -1379,25 +1377,25 @@ FileManager.prototype = /** @struct */ {
} else {
callback();
}
}.bind(this));
});
// If the directory to be changed to is still not resolved, then fallback
// to the default display root.
queue.run(function(callback) {
queue.run((callback) => {
if (nextCurrentDirEntry) {
callback();
return;
}
this.volumeManager_.getDefaultDisplayRoot(function(displayRoot) {
this.volumeManager_.getDefaultDisplayRoot((displayRoot) => {
nextCurrentDirEntry = displayRoot;
callback();
}.bind(this));
}.bind(this));
});
});
// If selection failed to be resolved (eg. didn't exist, in case of saving
// a file, or in case of a fallback of the current directory, then try to
// resolve again using the target name.
queue.run(function(callback) {
queue.run((callback) => {
if (selectionEntry ||
!nextCurrentDirEntry ||
!this.launchParams_.targetName) {
......@@ -1406,28 +1404,28 @@ FileManager.prototype = /** @struct */ {
}
// Try to resolve as a file first. If it fails, then as a directory.
nextCurrentDirEntry.getFile(
this.launchParams_.targetName,
{},
function(targetEntry) {
this.launchParams_.targetName, {},
(targetEntry) => {
selectionEntry = targetEntry;
callback();
}, function() {
},
() => {
// Failed to resolve as a file
nextCurrentDirEntry.getDirectory(
this.launchParams_.targetName,
{},
function(targetEntry) {
this.launchParams_.targetName, {},
(targetEntry) => {
selectionEntry = targetEntry;
callback();
}, function() {
},
() => {
// Failed to resolve as either file or directory.
callback();
});
}.bind(this));
}.bind(this));
});
});
queue.run((callback) => {
// If there is no target select MyFiles by default.
queue.run((callback) => {
if (!nextCurrentDirEntry)
nextCurrentDirEntry = this.directoryTree.dataModel.myFilesModel_.entry;
......@@ -1435,7 +1433,7 @@ FileManager.prototype = /** @struct */ {
});
// Finalize.
queue.run(function(callback) {
queue.run((callback) => {
// Check directory change.
tracker.stop();
if (tracker.hasChanged) {
......@@ -1448,7 +1446,7 @@ FileManager.prototype = /** @struct */ {
selectionEntry,
this.launchParams_.targetName);
callback();
}.bind(this));
});
};
/**
......
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