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

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: 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_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..285003dd7aaf076ca52acb8b06acc56fa3fa2b37 100644
--- a/chrome/browser/resources/file_manager/js/file_manager.js
+++ b/chrome/browser/resources/file_manager/js/file_manager.js
@@ -1254,48 +1254,42 @@ FileManager.prototype = {
this.onGridOrTableMouseDown_.bind(this));
};
+ FileManager.prototype.initButter_ = function() {
+ var self = this;
+ var progress = this.copyManager_.getProgress();
+
+ var options = {progress: progress.percentage, actions:{}};
+ options.actions[str('CANCEL_LABEL')] = function cancelPaste() {
+ self.copyManager_.requestCancel();
+ };
+ this.showButter(strf('PASTE_ITEMS_REMAINING', progress.pendingItems),
+ options);
+ };
+
FileManager.prototype.onCopyProgress_ = function(event) {
- var status = this.copyManager_.getStatus();
-
- // 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.
- 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' && 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);
+ var progress = this.copyManager_.getProgress();
+
+ if (event.reason == 'BEGIN') {
+ if (this.currentButter_)
+ this.hideButter();
+
+ 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);
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.percentage};
+ this.updateButter(strf('PASTE_ITEMS_REMAINING', progress.pendingItems),
+ options);
+ }
return;
}
if (event.reason == 'SUCCESS') {
+ clearTimeout(this.butterTimeout_);
if (this.currentButter_)
this.hideButter();
@@ -1311,6 +1305,7 @@ FileManager.prototype = {
}
}
} else if (event.reason == 'ERROR') {
+ clearTimeout(this.butterTimeout_);
switch (event.error.reason) {
case 'TARGET_EXISTS':
var name = event.error.data.name;
@@ -3004,10 +2999,6 @@ FileManager.prototype = {
if (!event.clipboardData.getData('fs/isCut'))
return;
- // Pass an empty string so that the butter bar remains invisible until
- // the first progress update. This prevents the flicker on short operations.
- this.showButter('', {timeout: 0});
bshe 2012/03/12 00:13:34 Side note: It seems the flicker it caused by a cal
-
var clipboard = {
isCut: event.clipboardData.getData('fs/isCut'),
sourceDir: event.clipboardData.getData('fs/sourcedir'),

Powered by Google App Engine
This is Rietveld 408576698