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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Setting the src of an img to an empty string can crash the browser, so we 5 // Setting the src of an img to an empty string can crash the browser, so we
6 // use an empty 1x1 gif instead. 6 // use an empty 1x1 gif instead.
7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' 7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,'
8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; 8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D';
9 9
10 /** 10 /**
(...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 'dblclick', this.onDetailDoubleClick_.bind(this)); 1247 'dblclick', this.onDetailDoubleClick_.bind(this));
1248 1248
1249 cr.ui.contextMenuHandler.addContextMenuProperty( 1249 cr.ui.contextMenuHandler.addContextMenuProperty(
1250 this.table_.querySelector('.list')); 1250 this.table_.querySelector('.list'));
1251 this.table_.querySelector('.list').contextMenu = this.fileContextMenu_; 1251 this.table_.querySelector('.list').contextMenu = this.fileContextMenu_;
1252 1252
1253 this.table_.addEventListener('mousedown', 1253 this.table_.addEventListener('mousedown',
1254 this.onGridOrTableMouseDown_.bind(this)); 1254 this.onGridOrTableMouseDown_.bind(this));
1255 }; 1255 };
1256 1256
1257 FileManager.prototype.initButter_ = function() {
1258 var status = this.copyManager_.getStatus();
1259 var self = this;
1260 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_
1261
1262 var options = {progress: progress, actions:{}};
1263 // We can't cancel the operation when pasting one file.
1264 if (status.totalItems > 1) {
1265 options.actions[str('CANCEL_LABEL')] = function cancelPaste() {
1266 self.copyManager_.requestCancel();
1267 };
1268 }
1269 this.showButter(strf('PASTE_ITEMS_REMAINING', status.pendingItems),
1270 options);
1271 this.shouldShowProgress_ = true;
1272 }
1273
1257 FileManager.prototype.onCopyProgress_ = function(event) { 1274 FileManager.prototype.onCopyProgress_ = function(event) {
1258 var status = this.copyManager_.getStatus(); 1275 var status = this.copyManager_.getStatus();
1259 1276
1260 // TODO(bshe): Need to figure out a way to get completed bytes in real 1277 // TODO(bshe): Need to figure out a way to get completed bytes in real
1261 // time. We currently use completedItems and totalItems to estimate the 1278 // time. We currently use completedItems and totalItems to estimate the
1262 // progress. There are completeBytes and totalBytes ready to use. 1279 // progress. There are completeBytes and totalBytes ready to use.
1263 // However, the completedBytes is not in real time. It only updates 1280 // However, the completedBytes is not in real time. It only updates
1264 // itself after each item finished. So if there is a large item to 1281 // itself after each item finished. So if there is a large item to
1265 // copy, the progress bar will stop moving until it finishes and jump 1282 // copy, the progress bar will stop moving until it finishes and jump
1266 // a large portion of the bar. 1283 // a large portion of the bar.
1267 // There is case that when user copy a large file, we want to show an 1284 // There is case that when user copy a large file, we want to show an
1268 // 100% animated progress bar. So we use completedItems + 1 here. 1285 // 100% animated progress bar. So we use completedItems + 1 here.
1269 var progress = (status.completedItems + 1) / status.totalItems; 1286 var progress = (status.completedItems + 1) / status.totalItems;
1270 1287
1271 // If the files we're copying is larger than 100MB or more than 25, 1288 if (event.reason == 'BEGIN') {
1272 // update the user on the current status with a progress bar and give 1289 // 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
1273 // an option to cancel. The rule of thumb here is if the pasting 1290 // there is a new copy task coming when the old one hasn't finished.
1274 // process is less than 500ms. We dont want to show progress bar. 1291 // Currently, just delete the old progress bar.
1275 var shouldShow = status.totalItems > 0 && 1292 if (this.currentButter_)
1276 status.completedItems < status.totalItems && 1293 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
1277 (status.totalBytes > 100000000 || status.totalItems > 25);
1278 1294
1279 if (event.reason == 'BEGIN' && shouldShow) { 1295 clearTimeout(this.butterTimeout);
1280 var self = this; 1296 // If the copy process lasts more than 500 ms, we show a progress bar.
1281 var options = {timeout:0, progress: progress, actions:{}}; 1297 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.
1282 // We can't cancel the operation when pasting one file.
1283 if (status.totalItems > 1) {
1284 options.actions[str('CANCEL_LABEL')] = function cancelPaste() {
1285 self.copyManager_.requestCancel();
1286 };
1287 }
1288 this.showButter(strf('PASTE_ITEMS_REMAINING', status.pendingItems),
1289 options);
1290 return; 1298 return;
1291 } 1299 }
1292 if (event.reason == 'PROGRESS' && shouldShow) { 1300 if (event.reason == 'PROGRESS') {
1293 var options = {timeout:0, progress: progress}; 1301 // Perform this check inside Progress event handler, avoid to log error
1294 this.updateButter(strf('PASTE_ITEMS_REMAINING', status.pendingItems), 1302 // message 'Unknown event reason: PROGRESS' in console.
1295 options); 1303 if (this.currentButter_) {
1304 var options = {progress: progress};
1305 this.updateButter(strf('PASTE_ITEMS_REMAINING', status.pendingItems),
1306 options);
1307 }
1296 return; 1308 return;
1297 } 1309 }
1298 if (event.reason == 'SUCCESS') { 1310 if (event.reason == 'SUCCESS') {
1311 clearTimeout(this.butterTimeout);
1299 if (this.currentButter_) 1312 if (this.currentButter_)
1300 this.hideButter(); 1313 this.hideButter();
1301 1314
1302 this.updateCommands_(); 1315 this.updateCommands_();
1303 self = this; 1316 self = this;
1304 var callback; 1317 var callback;
1305 while (callback = self.pasteSuccessCallbacks_.shift()) { 1318 while (callback = self.pasteSuccessCallbacks_.shift()) {
1306 try { 1319 try {
1307 callback(); 1320 callback();
1308 } catch (ex) { 1321 } catch (ex) {
(...skipping 2848 matching lines...) Expand 10 before | Expand all | Expand 10 after
4157 }); 4170 });
4158 }, onError); 4171 }, onError);
4159 4172
4160 function onError(err) { 4173 function onError(err) {
4161 console.log('Error while checking free space: ' + err); 4174 console.log('Error while checking free space: ' + err);
4162 setTimeout(doCheck, 1000 * 60); 4175 setTimeout(doCheck, 1000 * 60);
4163 } 4176 }
4164 } 4177 }
4165 } 4178 }
4166 })(); 4179 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698