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

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: 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 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 self = this;
1259 var progress = this.copyManager_.getProgress();
1260
1261 var options = {progress: progress.percentage, actions:{}};
1262 options.actions[str('CANCEL_LABEL')] = function cancelPaste() {
1263 self.copyManager_.requestCancel();
1264 };
1265 this.showButter(strf('PASTE_ITEMS_REMAINING', progress.pendingItems),
1266 options);
1267 };
1268
1257 FileManager.prototype.onCopyProgress_ = function(event) { 1269 FileManager.prototype.onCopyProgress_ = function(event) {
1258 var status = this.copyManager_.getStatus(); 1270 var progress = this.copyManager_.getProgress();
1259 1271
1260 // TODO(bshe): Need to figure out a way to get completed bytes in real 1272 if (event.reason == 'BEGIN') {
1261 // time. We currently use completedItems and totalItems to estimate the 1273 if (this.currentButter_)
1262 // progress. There are completeBytes and totalBytes ready to use. 1274 this.hideButter();
1263 // 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
1265 // copy, the progress bar will stop moving until it finishes and jump
1266 // a large portion of the bar.
1267 // 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.
1269 var progress = (status.completedItems + 1) / status.totalItems;
1270 1275
1271 // If the files we're copying is larger than 100MB or more than 25, 1276 clearTimeout(this.butterTimeout_);
1272 // update the user on the current status with a progress bar and give 1277 // If the copy process lasts more than 500 ms, we show a progress bar.
1273 // an option to cancel. The rule of thumb here is if the pasting 1278 this.butterTimeout_ = setTimeout(this.initButter_.bind(this), 500);
1274 // process is less than 500ms. We dont want to show progress bar.
1275 var shouldShow = status.totalItems > 0 &&
1276 status.completedItems < status.totalItems &&
1277 (status.totalBytes > 100000000 || status.totalItems > 25);
1278
1279 if (event.reason == 'BEGIN' && shouldShow) {
1280 var self = this;
1281 var options = {timeout:0, progress: progress, actions:{}};
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; 1279 return;
1291 } 1280 }
1292 if (event.reason == 'PROGRESS' && shouldShow) { 1281 if (event.reason == 'PROGRESS') {
1293 var options = {timeout:0, progress: progress}; 1282 // Perform this check inside Progress event handler, avoid to log error
1294 this.updateButter(strf('PASTE_ITEMS_REMAINING', status.pendingItems), 1283 // message 'Unknown event reason: PROGRESS' in console.
1295 options); 1284 if (this.currentButter_) {
1285 var options = {progress: progress.percentage};
1286 this.updateButter(strf('PASTE_ITEMS_REMAINING', progress.pendingItems),
1287 options);
1288 }
1296 return; 1289 return;
1297 } 1290 }
1298 if (event.reason == 'SUCCESS') { 1291 if (event.reason == 'SUCCESS') {
1292 clearTimeout(this.butterTimeout_);
1299 if (this.currentButter_) 1293 if (this.currentButter_)
1300 this.hideButter(); 1294 this.hideButter();
1301 1295
1302 this.updateCommands_(); 1296 this.updateCommands_();
1303 self = this; 1297 self = this;
1304 var callback; 1298 var callback;
1305 while (callback = self.pasteSuccessCallbacks_.shift()) { 1299 while (callback = self.pasteSuccessCallbacks_.shift()) {
1306 try { 1300 try {
1307 callback(); 1301 callback();
1308 } catch (ex) { 1302 } catch (ex) {
1309 console.error('Caught exception while inovking callback: ' + 1303 console.error('Caught exception while inovking callback: ' +
1310 callback, ex); 1304 callback, ex);
1311 } 1305 }
1312 } 1306 }
1313 } else if (event.reason == 'ERROR') { 1307 } else if (event.reason == 'ERROR') {
1308 clearTimeout(this.butterTimeout_);
1314 switch (event.error.reason) { 1309 switch (event.error.reason) {
1315 case 'TARGET_EXISTS': 1310 case 'TARGET_EXISTS':
1316 var name = event.error.data.name; 1311 var name = event.error.data.name;
1317 if (event.error.data.isDirectory) 1312 if (event.error.data.isDirectory)
1318 name += '/'; 1313 name += '/';
1319 this.showButterError(strf('PASTE_TARGET_EXISTS_ERROR', name)); 1314 this.showButterError(strf('PASTE_TARGET_EXISTS_ERROR', name));
1320 break; 1315 break;
1321 1316
1322 case 'FILESYSTEM_ERROR': 1317 case 'FILESYSTEM_ERROR':
1323 this.showButterError( 1318 this.showButterError(
(...skipping 1673 matching lines...) Expand 10 before | Expand all | Expand 10 after
2997 2992
2998 /** 2993 /**
2999 * Queue up a file copy operation based on the current system clipboard. 2994 * Queue up a file copy operation based on the current system clipboard.
3000 */ 2995 */
3001 FileManager.prototype.pasteFromClipboard_ = function(event) { 2996 FileManager.prototype.pasteFromClipboard_ = function(event) {
3002 event.preventDefault(); 2997 event.preventDefault();
3003 2998
3004 if (!event.clipboardData.getData('fs/isCut')) 2999 if (!event.clipboardData.getData('fs/isCut'))
3005 return; 3000 return;
3006 3001
3007 // Pass an empty string so that the butter bar remains invisible until
3008 // the first progress update. This prevents the flicker on short operations.
3009 this.showButter('', {timeout: 0});
bshe 2012/03/12 00:13:34 Side note: It seems the flicker it caused by a cal
3010
3011 var clipboard = { 3002 var clipboard = {
3012 isCut: event.clipboardData.getData('fs/isCut'), 3003 isCut: event.clipboardData.getData('fs/isCut'),
3013 sourceDir: event.clipboardData.getData('fs/sourcedir'), 3004 sourceDir: event.clipboardData.getData('fs/sourcedir'),
3014 directories: event.clipboardData.getData('fs/directories'), 3005 directories: event.clipboardData.getData('fs/directories'),
3015 files: event.clipboardData.getData('fs/files') 3006 files: event.clipboardData.getData('fs/files')
3016 }; 3007 };
3017 3008
3018 this.copyManager_.paste(clipboard, 3009 this.copyManager_.paste(clipboard,
3019 this.directoryModel_.currentEntry, 3010 this.directoryModel_.currentEntry,
3020 this.filesystem_.root); 3011 this.filesystem_.root);
(...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after
4157 }); 4148 });
4158 }, onError); 4149 }, onError);
4159 4150
4160 function onError(err) { 4151 function onError(err) {
4161 console.log('Error while checking free space: ' + err); 4152 console.log('Error while checking free space: ' + err);
4162 setTimeout(doCheck, 1000 * 60); 4153 setTimeout(doCheck, 1000 * 60);
4163 } 4154 }
4164 } 4155 }
4165 } 4156 }
4166 })(); 4157 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698