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

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

Issue 2945793002: Discard getDirectorySize request until the last one finishes. (Closed)
Patch Set: Fix compile error. Created 3 years, 6 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 | « no previous file | 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/metadata_box_controller.js
diff --git a/ui/file_manager/file_manager/foreground/js/metadata_box_controller.js b/ui/file_manager/file_manager/foreground/js/metadata_box_controller.js
index 841bce3b0424be18662868db1fa246fa53fb3b08..1ad02c31161ba023d041a02e519ae98b78941d9f 100644
--- a/ui/file_manager/file_manager/foreground/js/metadata_box_controller.js
+++ b/ui/file_manager/file_manager/foreground/js/metadata_box_controller.js
@@ -49,6 +49,18 @@ function MetadataBoxController(
* @private
*/
this.previousEntry_ = null;
+
+ /**
+ * @type {boolean}
+ * @private
+ */
+ this.isDirectorySizeLoading_ = false;
+
+ /**
+ * @type {?function(!DirectoryEntry)}
+ * @private
+ */
+ this.onDirectorySizeLoaded_ = null;
}
/**
@@ -187,6 +199,9 @@ MetadataBoxController.prototype.onGeneralMetadataLoaded_ = function(
/**
* Set a current directory's size in metadata box.
+ * If previous getDirectorySize is still running, next getDirectorySize is not
+ * called at the time. After the previous callback is finished, getDirectorySize
+ * that corresponds to the last setDirectorySize_ is called.
*
* @param {!DirectoryEntry} entry
* @param {boolean} isSameEntry
@@ -199,20 +214,34 @@ MetadataBoxController.prototype.setDirectorySize_ = function(
if (!entry.isDirectory)
return;
+ if (this.isDirectorySizeLoading_) {
+ if (!isSameEntry)
+ this.metadataBox_.isSizeLoading = true;
+
+ // Only retain the last setDirectorySize_ request.
+ this.onDirectorySizeLoaded_ = function(lastEntry) {
+ this.setDirectorySize_(entry, util.isSameEntry(entry, lastEntry));
+ }.bind(this);
+ return;
+ }
+
// false if the entry is same. true if the entry is changed.
this.metadataBox_.isSizeLoading = !isSameEntry;
- chrome.fileManagerPrivate.getDirectorySize(entry,
- function(size) {
- if(this.quickViewModel_.getSelectedEntry() != entry) {
- return;
- }
- if(chrome.runtime.lastError) {
- this.metadataBox_.isSizeLoading = false;
- return;
- }
-
- this.metadataBox_.isSizeLoading = false;
- this.metadataBox_.size =
- this.fileMetadataFormatter_.formatSize(size, true);
- }.bind(this));
+ this.isDirectorySizeLoading_ = true;
+ chrome.fileManagerPrivate.getDirectorySize(entry, function(size) {
+ this.isDirectorySizeLoading_ = false;
+ if (this.onDirectorySizeLoaded_)
+ setTimeout(this.onDirectorySizeLoaded_.bind(null, entry));
+
+ if (this.quickViewModel_.getSelectedEntry() != entry)
+ return;
+
+ if (chrome.runtime.lastError) {
+ this.metadataBox_.isSizeLoading = false;
+ return;
+ }
+
+ this.metadataBox_.isSizeLoading = false;
+ this.metadataBox_.size = this.fileMetadataFormatter_.formatSize(size, true);
+ }.bind(this));
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698