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