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

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

Issue 9652024: Only show progress bar after 500ms (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: 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_manager.js
diff --git a/chrome/browser/resources/file_manager/js/file_manager.js b/chrome/browser/resources/file_manager/js/file_manager.js
index 3f51ddbaf5bd6d17f38b66baf056720256c91fa2..85d63a53f807c2634515c12198b301c63048172a 100644
--- a/chrome/browser/resources/file_manager/js/file_manager.js
+++ b/chrome/browser/resources/file_manager/js/file_manager.js
@@ -1254,6 +1254,23 @@ FileManager.prototype = {
this.onGridOrTableMouseDown_.bind(this));
};
+ FileManager.prototype.initButter_ = function() {
+ var status = this.copyManager_.getStatus();
+ var self = this;
+ var progress = (status.completedItems + 1) / status.totalItems;
Rick Byers 2012/03/09 21:45:45 Since this formula is non-trivial (i.e. the +1 req
bshe 2012/03/12 00:13:34 I moved the progress calculation into a file_copy_
+
+ var options = {progress: progress, actions:{}};
+ // We can't cancel the operation when pasting one file.
+ if (status.totalItems > 1) {
+ options.actions[str('CANCEL_LABEL')] = function cancelPaste() {
+ self.copyManager_.requestCancel();
+ };
+ }
+ this.showButter(strf('PASTE_ITEMS_REMAINING', status.pendingItems),
+ options);
+ this.shouldShowProgress_ = true;
+ }
+
FileManager.prototype.onCopyProgress_ = function(event) {
var status = this.copyManager_.getStatus();
@@ -1268,34 +1285,30 @@ FileManager.prototype = {
// 100% animated progress bar. So we use completedItems + 1 here.
var progress = (status.completedItems + 1) / status.totalItems;
- // If the files we're copying is larger than 100MB or more than 25,
- // update the user on the current status with a progress bar and give
- // an option to cancel. The rule of thumb here is if the pasting
- // process is less than 500ms. We dont want to show progress bar.
- var shouldShow = status.totalItems > 0 &&
- status.completedItems < status.totalItems &&
- (status.totalBytes > 100000000 || status.totalItems > 25);
+ if (event.reason == 'BEGIN') {
+ // TODO(bshe): Need to find a way to update the current progress bar if
Rick Byers 2012/03/09 21:45:45 At a quick glance it looks to me like this should
bshe 2012/03/12 00:13:34 Correct. I verified that for copy/paste task, the
+ // there is a new copy task coming when the old one hasn't finished.
+ // Currently, just delete the old progress bar.
+ if (this.currentButter_)
+ this.hideButter();
Rick Byers 2012/03/09 21:45:45 I think you should call initButter right away in t
bshe 2012/03/12 00:13:34 Now the progress bar auto updates itself when ther
- if (event.reason == 'BEGIN' && shouldShow) {
- var self = this;
- var options = {timeout:0, progress: progress, actions:{}};
- // We can't cancel the operation when pasting one file.
- if (status.totalItems > 1) {
- options.actions[str('CANCEL_LABEL')] = function cancelPaste() {
- self.copyManager_.requestCancel();
- };
- }
- this.showButter(strf('PASTE_ITEMS_REMAINING', status.pendingItems),
- options);
+ clearTimeout(this.butterTimeout);
+ // If the copy process lasts more than 500 ms, we show a progress bar.
+ this.butterTimeout = setTimeout(this.initButter_.bind(this), 500);
Rick Byers 2012/03/09 21:45:45 replace butterTimeout with butterTimeout_ ?
bshe 2012/03/12 00:13:34 Done.
return;
}
- if (event.reason == 'PROGRESS' && shouldShow) {
- var options = {timeout:0, progress: progress};
- this.updateButter(strf('PASTE_ITEMS_REMAINING', status.pendingItems),
- options);
+ if (event.reason == 'PROGRESS') {
+ // Perform this check inside Progress event handler, avoid to log error
+ // message 'Unknown event reason: PROGRESS' in console.
+ if (this.currentButter_) {
+ var options = {progress: progress};
+ this.updateButter(strf('PASTE_ITEMS_REMAINING', status.pendingItems),
+ options);
+ }
return;
}
if (event.reason == 'SUCCESS') {
+ clearTimeout(this.butterTimeout);
if (this.currentButter_)
this.hideButter();

Powered by Google App Engine
This is Rietveld 408576698