Commit 0ad9fe79 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

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