Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Unified Diff: ui/file_manager/file_manager/foreground/js/task_controller.js

Issue 2833413003: Reuse FileTasks when entries are not changed. (Closed)
Patch Set: Use getter for FileTasks.entries. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/file_manager/file_manager/foreground/js/file_tasks.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/file_manager/file_manager/foreground/js/task_controller.js
diff --git a/ui/file_manager/file_manager/foreground/js/task_controller.js b/ui/file_manager/file_manager/foreground/js/task_controller.js
index a703d14c00d7f9c8d5a5109887dd38fb1940e018..8126570201a14582b44a6b63f40207c61487fe51 100644
--- a/ui/file_manager/file_manager/foreground/js/task_controller.js
+++ b/ui/file_manager/file_manager/foreground/js/task_controller.js
@@ -262,7 +262,6 @@ TaskController.prototype.getMimeType_ = function(entry) {
* @private
*/
TaskController.prototype.onSelectionChanged_ = function() {
- this.tasks_ = null;
var selection = this.selectionHandler_.selection;
// Caller of update context menu task items.
// FileSelectionHandler.EventType.CHANGE
@@ -286,15 +285,36 @@ TaskController.prototype.updateTasks_ = function() {
var selection = this.selectionHandler_.selection;
if (this.dialogType_ === DialogType.FULL_PAGE &&
(selection.directoryCount > 0 || selection.fileCount > 0)) {
- this.getFileTasks()
- .then(function(tasks) {
- tasks.display(this.ui_.taskMenuButton);
- this.updateContextMenuTaskItems_(tasks.getTaskItems());
- }.bind(this))
- .catch(function(error) {
- if (error)
- console.error(error.stack || error);
- });
+ var previousFileTasksInvalidatePromise = new Promise(function(resolve) {
+ if (this.tasks_) {
+ this.getFileTasks()
+ .then(function(tasks) {
+ if (!util.isSameEntries(tasks.entries, selection.entries)) {
+ this.tasks_ = null;
+ }
+ resolve();
+ }.bind(this))
+ .catch(function(error) {
+ if (error)
+ console.log(error.stack || error);
+ this.tasks_ = null;
+ resolve();
+ }.bind(this));
+ } else {
+ resolve();
+ }
+ }.bind(this));
+ previousFileTasksInvalidatePromise.then(function() {
+ this.getFileTasks()
+ .then(function(tasks) {
+ tasks.display(this.ui_.taskMenuButton);
+ this.updateContextMenuTaskItems_(tasks.getTaskItems());
+ }.bind(this))
+ .catch(function(error) {
+ if (error)
+ console.error(error.stack || error);
+ });
+ }.bind(this));
} else {
this.ui_.taskMenuButton.hidden = true;
}
@@ -309,19 +329,21 @@ TaskController.prototype.getFileTasks = function() {
return this.tasks_;
var selection = this.selectionHandler_.selection;
- return selection.computeAdditional(this.metadataModel_).then(
- function() {
- if (this.selectionHandler_.selection !== selection)
- return Promise.reject();
- return FileTasks.create(
- this.volumeManager_, this.metadataModel_, this.directoryModel_,
- this.ui_, selection.entries, assert(selection.mimeTypes)).
- then(function(tasks) {
- if (this.selectionHandler_.selection !== selection)
- return Promise.reject();
- return tasks;
- }.bind(this));
- }.bind(this));
+ return this.tasks_ =
+ selection.computeAdditional(this.metadataModel_).then(function() {
+ if (this.selectionHandler_.selection !== selection)
+ return Promise.reject();
+ return FileTasks
+ .create(
+ this.volumeManager_, this.metadataModel_,
+ this.directoryModel_, this.ui_, selection.entries,
+ assert(selection.mimeTypes))
+ .then(function(tasks) {
+ if (this.selectionHandler_.selection !== selection)
+ return Promise.reject();
+ return tasks;
+ }.bind(this));
+ }.bind(this));
};
/**
« no previous file with comments | « ui/file_manager/file_manager/foreground/js/file_tasks.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698