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

Unified Diff: chrome/browser/resources/file_manager/js/file_copy_manager.js

Issue 9652024: Only show progress bar after 500ms (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Address Rick's review. Created 8 years, 9 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
Index: chrome/browser/resources/file_manager/js/file_copy_manager.js
diff --git a/chrome/browser/resources/file_manager/js/file_copy_manager.js b/chrome/browser/resources/file_manager/js/file_copy_manager.js
index d29bb526a4b58fc60e4f0d31a50c3e7fb81379ba..8e05d1c8eac70b9d2e097020a99e6ba2eb9136d5 100644
--- a/chrome/browser/resources/file_manager/js/file_copy_manager.js
+++ b/chrome/browser/resources/file_manager/js/file_copy_manager.js
@@ -56,12 +56,15 @@ FileCopyManager.Task.prototype.setEntries = function(entries, callback) {
util.recurseAndResolveEntries(entries, onEntriesRecursed);
}
-FileCopyManager.Task.prototype.takeNextEntry = function() {
+FileCopyManager.Task.prototype.getNextEntry = function() {
+ // We should keep the file in pending list and remove it after complete.
+ // Otherwise, if we try to get status in the middle of copying. The returned
+ // status is wrong (miss count the pasting item in totalItems).
if (this.pendingDirectories.length)
- return this.pendingDirectories.shift();
+ return this.pendingDirectories[0];
if (this.pendingFiles.length)
- return this.pendingFiles.shift();
+ return this.pendingFiles[0];
return null;
};
@@ -69,9 +72,11 @@ FileCopyManager.Task.prototype.takeNextEntry = function() {
FileCopyManager.Task.prototype.markEntryComplete = function(entry, size) {
if (entry.isDirectory) {
this.completedDirectories.push(entry);
+ this.pendingDirectories.shift();
} else {
this.completedFiles.push(entry);
this.completedBytes += size;
+ this.pendingFiles.shift();
}
};
@@ -129,14 +134,13 @@ FileCopyManager.prototype.getStatus = function() {
rv.pendingFiles += task.pendingFiles.length;
rv.pendingDirectories += task.pendingDirectories.length;
rv.pendingBytes += task.pendingBytes;
- rv.pendingItems += rv.pendingFiles + rv.pendingDirectories;
rv.completedFiles += task.completedFiles.length;
rv.completedDirectories += task.completedDirectories.length;
rv.completedBytes += task.completedBytes;
- rv.completedItems += rv.completedFiles + rv.completedDirectories;
-
}
+ rv.pendingItems = rv.pendingFiles + rv.pendingDirectories;
+ rv.completedItems = rv.completedFiles + rv.completedDirectories;
rv.totalFiles = rv.pendingFiles + rv.completedFiles;
rv.totalDirectories = rv.pendingDirectories + rv.completedDirectories;
@@ -146,6 +150,28 @@ FileCopyManager.prototype.getStatus = function() {
return rv;
};
+FileCopyManager.prototype.getProgress = function() {
Rick Byers 2012/03/12 14:20:08 Since this is a public function you should have a
bshe 2012/03/12 16:41:19 Done.
+ var status = this.getStatus();
+ var result = {
Rick Byers 2012/03/12 14:20:08 No need to create a variable and initializing to 0
bshe 2012/03/12 16:41:19 Done.
+ percentage: 0,
+ pendingItems: 0
+ };
+
+ // TODO(bshe): Need to figure out a way to get completed bytes in real
+ // time. We currently use completedItems and totalItems to estimate the
+ // progress. There are completeBytes and totalBytes ready to use.
+ // However, the completedBytes is not in real time. It only updates
+ // itself after each item finished. So if there is a large item to
+ // copy, the progress bar will stop moving until it finishes and jump
+ // a large portion of the bar.
+ // There is case that when user copy a large file, we want to show an
+ // 100% animated progress bar. So we use completedItems + 1 here.
+ result.percentage = (status.completedItems + 1) / status.totalItems;
+
+ result.pendingItems = status.pendingItems;
+ return result;
+};
+
/**
* Completely clear out the copy queue, either because we encountered an error
* or completed successfully.
@@ -271,6 +297,12 @@ FileCopyManager.prototype.queueCopy = function(sourceDirEntry,
if (self.copyTasks_.length == 1) {
// This moved us from 0 to 1 active tasks, let the servicing begin!
self.serviceAllTasks_();
+ } else {
+ // Force to update the progress of butter bar when there are new tasks
+ // coming while servicing current task.
+ var event = new cr.Event('copy-progress');
+ event.reason = 'PROGRESS';
+ self.dispatchEvent(event);
}
});
@@ -293,7 +325,7 @@ FileCopyManager.prototype.serviceAllTasks_ = function() {
}
function onTaskSuccess(task) {
- if (task == null) {
+ if (!self.copyTasks_.length) {
// All tasks have been serviced, clean up and exit.
var event = new cr.Event('copy-progress');
event.reason = 'SUCCESS';
@@ -302,11 +334,23 @@ FileCopyManager.prototype.serviceAllTasks_ = function() {
return;
}
+ // We want to dispatch a PROGRESS event when there are more tasks to serve
+ // right after one task finished in the queue. We treat all tasks as one
+ // big task logically, so there is only one BEGIN/SUCCESS event pair for
+ // these continuous tasks.
+ var event = new cr.Event('copy-progress');
+ event.reason = 'PROGRESS';
+ self.dispatchEvent(event);
Rick Byers 2012/03/12 14:20:08 Probably worth encapsulating these 3 lines in a si
bshe 2012/03/12 16:41:19 Done.
+
self.serviceNextTask_(onTaskSuccess, onTaskError);
}
// If the queue size is 1 after pushing our task, it was empty before,
- // so we need to kick off queue processing.
+ // so we need to kick off queue processing and dispatch BEGIN event.
+
+ var event = new cr.Event('copy-progress');
+ event.reason = 'BEGIN';
+ this.dispatchEvent(event);
this.serviceNextTask_(onTaskSuccess, onTaskError);
};
@@ -318,11 +362,6 @@ FileCopyManager.prototype.serviceNextTask_ = function(
if (this.maybeCancel_())
return;
- if (!this.copyTasks_.length) {
- successCallback(null);
- return;
- }
-
var self = this;
var task = this.copyTasks_[0];
@@ -351,7 +390,9 @@ FileCopyManager.prototype.serviceNextTask_ = function(
}
function onEntryServiced(targetEntry, size) {
- if (!targetEntry) {
+ // We should not dispatch a PROGRESS event when there is no pending items
+ // in the task.
+ if (task.pendingDirectories.length + task.pendingFiles.length == 0) {
// All done with the entries in this task.
if (task.deleteAfterCopy) {
deleteOriginals()
@@ -372,9 +413,6 @@ FileCopyManager.prototype.serviceNextTask_ = function(
}, 10);
}
- var event = new cr.Event('copy-progress');
- event.reason = 'BEGIN';
- this.dispatchEvent(event);
this.serviceNextTaskEntry_(task, onEntryServiced, errorCallback);
}
@@ -387,7 +425,7 @@ FileCopyManager.prototype.serviceNextTaskEntry_ = function(
return;
var self = this;
- var sourceEntry = task.takeNextEntry();
+ var sourceEntry = task.getNextEntry();
if (!sourceEntry) {
// All entries in this task have been copied.
@@ -482,7 +520,7 @@ FileCopyManager.prototype.serviceNextTaskEntry_ = function(
onCopyComplete, onError);
},
util.flog('Error getting file: ' + targetRelativePath,
- onFilesystemError));
+ onFilesystemError));
Rick Byers 2012/03/12 14:20:08 Remove added extra space
bshe 2012/03/12 16:41:19 Done.
}
}

Powered by Google App Engine
This is Rietveld 408576698