Commit ed1db248 authored by mpearson's avatar mpearson Committed by Commit bot

Revert of Refoctoring FileSelection and FileSelectionHandler. (patchset #9...

Revert of Refoctoring FileSelection and FileSelectionHandler. (patchset #9 id:150001 of https://codereview.chromium.org/736663002/)

Reason for revert:
Causing failures on
https://build.chromium.org/p/chromium.chromiumos/builders/Linux%20ChromiumOS%20Tests%20%28dbg%29%281%29
SelectFileAndOpen
SelectFileAndSave

NOTRY=true
TBR=hirono

[detailed omitted; should've been sent by e-mail]

Review URL: https://codereview.chromium.org/749603002

Cr-Commit-Position: refs/heads/master@{#305121}
parent ddb15328
......@@ -279,7 +279,7 @@ IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest,
// waiting for chrome.test.sendMessage('selection-change-complete').
ASSERT_NO_FATAL_FAILURE(OpenDialog(ui::SelectFileDialog::SELECT_OPEN_FILE,
test_file, owning_window,
"dialog-ready"));
"selection-change-complete"));
// Click open button.
CloseDialog(DIALOG_BTN_OK, owning_window);
......@@ -305,7 +305,7 @@ IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest,
// chrome.test.sendMessage().
ASSERT_NO_FATAL_FAILURE(OpenDialog(ui::SelectFileDialog::SELECT_SAVEAS_FILE,
test_file, owning_window,
"dialog-ready"));
"directory-change-complete"));
// Click save button.
CloseDialog(DIALOG_BTN_OK, owning_window);
......
......@@ -116,8 +116,7 @@ function DialogActionController(
dialogFooter.filenameInput.addEventListener(
'input', this.updateOkButton_.bind(this));
fileSelectionHandler.addEventListener(
FileSelectionHandler.EventType.CHANGE_THROTTLED,
this.onFileSelectionChanged_.bind(this));
'change', this.onFileSelectionChanged_.bind(this));
dialogFooter.initFileTypeFilter(
this.fileTypes_, launchParam.includeAllFiles);
......@@ -412,13 +411,7 @@ DialogActionController.prototype.onFileSelectionChanged_ = function() {
this.dialogFooter_.filenameInput.value = selection.entries[0].name;
}
selection.completeInit().then(function() {
if (this.fileSelectionHandler_.selection !== selection)
return;
this.updateOkButton_();
if (!this.dialogFooter_.okButton.disable)
util.testSendMessage('dialog-ready');
}.bind(this));
this.updateOkButton_();
};
/**
......@@ -449,19 +442,27 @@ DialogActionController.prototype.updateOkButton_ = function() {
return;
}
var isDriveOffline =
this.volumeManager_.getDriveConnectionState().type ===
VolumeManagerCommon.DriveConnectionType.OFFLINE;
var filesAvailable =
!this.directoryModel_.isOnDrive() ||
!isDriveOffline ||
selection.allDriveFilesPresent;
if (this.dialogType_ === DialogType.SELECT_OPEN_FILE) {
this.dialogFooter_.okButton.disabled =
!filesAvailable ||
selection.directoryCount !== 0 ||
selection.fileCount !== 1 ||
!this.fileSelectionHandler_.isAvailable();
selection.fileCount !== 1;
return;
}
if (this.dialogType_ === DialogType.SELECT_OPEN_MULTI_FILE) {
this.dialogFooter_.okButton.disabled =
!filesAvailable ||
selection.directoryCount !== 0 ||
selection.fileCount === 0 ||
!this.fileSelectionHandler_.isAvailable();
selection.fileCount === 0;
return;
}
......
......@@ -384,12 +384,6 @@ FileManager.prototype = /** @struct */ {
get historyLoader() {
return this.historyLoader_;
},
/**
* @return {MetadataCache}
*/
get metadataCache() {
return this.metadataCache_;
},
/**
* @return {FileManagerUI}
*/
......@@ -1811,7 +1805,7 @@ var BOTTOM_MARGIN_FOR_PREVIEW_PANEL_PX = 52;
var entry = selection.entries[0];
if (entry.isDirectory) {
this.onDirectoryAction_(/** @type {!DirectoryEntry} */(entry));
this.onDirectoryAction_(entry);
} else {
this.dispatchSelectionAction_();
}
......@@ -2196,8 +2190,7 @@ var BOTTOM_MARGIN_FOR_PREVIEW_PANEL_PX = 52;
// directory.
if (!item.hasAttribute('renaming')) {
event.preventDefault();
this.onDirectoryAction_(
/** @type {DirectoryEntry} */(selection.entries[0]));
this.onDirectoryAction_(selection.entries[0]);
}
} else if (this.dispatchSelectionAction_()) {
event.preventDefault();
......
......@@ -106,6 +106,23 @@ CommandUtil.canExecuteAlways = function(event) {
event.canExecute = true;
};
/**
* Returns a single selected/passed entry or null.
* @param {!Event} event Command event.
* @param {!FileManager} fileManager FileManager to use.
* @return {FileEntry} The entry or null.
*/
CommandUtil.getSingleEntry = function(event, fileManager) {
if (event.target.entry) {
return event.target.entry;
}
var selection = fileManager.getSelection();
if (selection.totalCount == 1) {
return selection.entries[0];
}
return null;
};
/**
* Obtains target entries that can be pinned from the selection.
* If directories are included in the selection, it just returns an empty
......@@ -219,7 +236,7 @@ CommandUtil.getOnlyOneSelectedDirectory = function(selection) {
return null;
if (!selection.entries[0].isDirectory)
return null;
return /** @type {!DirectoryEntry} */(selection.entries[0]);
return selection.entries[0];
};
/**
......
......@@ -5,99 +5,26 @@
/**
* The current selection object.
*
* @param {!FileManager} fileManager FileManager instance.
* @param {!Array.<number>} indexes Selected indexes.
* @param {FileManager} fileManager FileManager instance.
* @param {Array.<number>} indexes Selected indexes.
* @constructor
* @struct
*/
function FileSelection(fileManager, indexes) {
/**
* @type {!FileManager}
* @private
* @const
*/
this.fileManager_ = fileManager;
/**
* @type {number}
* @private
*/
this.computeBytesSequence_ = 0;
/**
* @type {!Array.<number>}
* @const
*/
this.indexes = indexes;
/**
* @type {!Array.<!Entry>}
* @const
*/
this.entries = [];
/**
* @type {number}
*/
this.totalCount = 0;
/**
* @type {number}
*/
this.fileCount = 0;
/**
* @type {number}
*/
this.directoryCount = 0;
/**
* @type {number}
*/
this.bytes = 0;
/**
* @type {boolean}
*/
this.showBytes = false;
/**
* @type {boolean}
*/
this.allDriveFilesPresent = false;
/**
* @type {?string}
*/
this.allDriveFilesPresent = false,
this.iconType = null;
/**
* @type {boolean}
*/
this.bytesKnown = false;
/**
* @type {boolean}
* @private
*/
this.mustBeHidden_ = false;
/**
* @type {Array.<string>}
*/
this.mimeTypes = null;
/**
* @type {!FileTasks}
*/
this.tasks = new FileTasks(this.fileManager_);
/**
* @type {Promise}
* @private
*/
this.asyncInitPromise_ = null;
// Synchronously compute what we can.
for (var i = 0; i < this.indexes.length; i++) {
var entry = /** @type {!Entry} */
......@@ -122,36 +49,39 @@ function FileSelection(fileManager, indexes) {
}
this.totalCount++;
}
this.tasks = new FileTasks(this.fileManager_);
Object.seal(this);
}
/**
* Computes data required to get file tasks and requests the tasks.
* @return {!Promise}
*
* @param {function()} callback The callback.
*/
FileSelection.prototype.completeInit = function() {
if (!this.asyncInitPromise_) {
if (!this.fileManager_.isOnDrive()) {
this.asyncInitPromise_ = Promise.resolve();
this.tasks.init(this.entries);
this.allDriveFilesPresent = true;
} else {
this.asyncInitPromise_ = new Promise(function(fulfill) {
this.fileManager_.metadataCache.get(this.entries, 'external', fulfill);
}.bind(this)).then(function(props) {
FileSelection.prototype.createTasks = function(callback) {
if (!this.fileManager_.isOnDrive()) {
this.tasks.init(this.entries);
callback();
return;
}
this.fileManager_.metadataCache_.get(
this.entries, 'external', function(props) {
var present = props.filter(function(p) {
return p && p.availableOffline;
});
this.allDriveFilesPresent = present.length == props.length;
// Collect all of the mime types and push that info into the
// selection.
// Collect all of the mime types and push that info into the selection.
this.mimeTypes = props.map(function(value) {
return (value && value.contentMimeType) || '';
});
this.tasks.init(this.entries, this.mimeTypes);
callback();
}.bind(this));
}
}
return this.asyncInitPromise_;
};
/**
......@@ -220,7 +150,7 @@ FileSelection.prototype.cancelComputing_ = function() {
/**
* This object encapsulates everything related to current selection.
*
* @param {!FileManager} fileManager File manager instance.
* @param {FileManager} fileManager File manager instance.
* @extends {cr.EventTarget}
* @constructor
* @struct
......@@ -248,23 +178,6 @@ function FileSelectionHandler(fileManager) {
this.lastFileSelectionTime_ = new Date();
}
/**
* @enum {string}
*/
FileSelectionHandler.EventType = {
/**
* Dispatched every time when selection is changed.
*/
CHANGE: 'change',
/**
* Dispatched 200ms later after the selecton is changed.
* If multiple changes are happened during the term, only one CHANGE_THROTTLED
* event is dispatched.
*/
CHANGE_THROTTLED: 'changethrottled'
};
/**
* Create the temporary disabled action item.
* @return {Object} Created disabled item.
......@@ -354,27 +267,25 @@ FileSelectionHandler.prototype.onFileSelectionChanged = function() {
this.selectionUpdateTimer_ = setTimeout(function() {
this.selectionUpdateTimer_ = null;
if (this.selection == selection)
this.updateFileSelectionAsync_(selection);
this.updateFileSelectionAsync(selection);
}.bind(this), updateDelay);
cr.dispatchSimpleEvent(this, FileSelectionHandler.EventType.CHANGE);
cr.dispatchSimpleEvent(this, 'change');
};
/**
* Calculates async selection stats and updates secondary UI elements.
*
* @param {FileSelection} selection The selection object.
* @private
*/
FileSelectionHandler.prototype.updateFileSelectionAsync_ = function(selection) {
if (this.selection !== selection)
return;
FileSelectionHandler.prototype.updateFileSelectionAsync = function(selection) {
if (this.selection != selection) return;
// Update the file tasks.
if (this.fileManager_.dialogType === DialogType.FULL_PAGE &&
selection.directoryCount === 0 && selection.fileCount > 0) {
selection.completeInit().then(function() {
if (this.selection !== selection)
selection.createTasks(function() {
if (this.selection != selection)
return;
selection.tasks.display(this.taskMenuButton_);
selection.tasks.updateMenuItem();
......@@ -397,17 +308,7 @@ FileSelectionHandler.prototype.updateFileSelectionAsync_ = function(selection) {
if (this.fileManager_.commandHandler)
this.fileManager_.commandHandler.updateAvailability();
cr.dispatchSimpleEvent(this, FileSelectionHandler.EventType.CHANGE_THROTTLED);
};
/**
* Returns whether all the selected files are available currently or not.
* Should be called after the selection initialized.
* @return {boolean}
*/
FileSelectionHandler.prototype.isAvailable = function() {
return !this.fileManager_.isOnDrive() ||
this.fileManager_.volumeManager.getDriveConnectionState().type !==
VolumeManagerCommon.DriveConnectionType.OFFLINE ||
this.selection.allDriveFilesPresent;
// Inform tests it's OK to click buttons now.
if (selection.totalCount > 0)
util.testSendMessage('selection-change-complete');
};
......@@ -211,7 +211,7 @@ ShareDialog.prototype.hideWithResult = function(result, opt_onHide) {
/**
* Shows the dialog.
* @param {!Entry} entry Entry to share.
* @param {FileEntry} entry Entry to share.
* @param {function(ShareDialog.Result)} callback Callback to be called when the
* showing task is completed. The argument is whether to succeed or not.
* Note that cancel is regarded as success.
......
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