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

Side by Side Diff: chrome/browser/resources/file_manager/js/file_manager.js

Issue 9667040: Use FileEntry.copyTo() and FileEntry.moveTo() on GData file system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
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 7
8 /** 8 /**
9 * FileManager constructor. 9 * FileManager constructor.
10 * 10 *
(...skipping 1261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 var progress = (status.completedItems + 1) / status.totalItems; 1272 var progress = (status.completedItems + 1) / status.totalItems;
1273 1273
1274 // If the files we're copying is larger than 100MB or more than 25, 1274 // If the files we're copying is larger than 100MB or more than 25,
1275 // update the user on the current status with a progress bar and give 1275 // update the user on the current status with a progress bar and give
1276 // an option to cancel. The rule of thumb here is if the pasting 1276 // an option to cancel. The rule of thumb here is if the pasting
1277 // process is less than 500ms. We dont want to show progress bar. 1277 // process is less than 500ms. We dont want to show progress bar.
1278 var shouldShow = status.totalItems > 0 && 1278 var shouldShow = status.totalItems > 0 &&
1279 status.completedItems < status.totalItems && 1279 status.completedItems < status.totalItems &&
1280 (status.totalBytes > 100000000 || status.totalItems > 25); 1280 (status.totalBytes > 100000000 || status.totalItems > 25);
1281 1281
1282 if (event.reason == 'BEGIN' && shouldShow) { 1282 if (event.reason == 'BEGIN') {
Ben Chan 2012/03/12 03:03:53 This change is to prevent 'unknown event: BEGIN' f
dgozman 2012/03/12 09:46:03 Thank you for the fix.
1283 var self = this; 1283 if (shouldShow) {
1284 var options = {timeout:0, progress: progress, actions:{}}; 1284 var self = this;
1285 // We can't cancel the operation when pasting one file. 1285 var options = {timeout:0, progress: progress, actions:{}};
1286 if (status.totalItems > 1) { 1286 // We can't cancel the operation when pasting one file.
1287 options.actions[str('CANCEL_LABEL')] = function cancelPaste() { 1287 if (status.totalItems > 1) {
1288 self.copyManager_.requestCancel(); 1288 options.actions[str('CANCEL_LABEL')] = function cancelPaste() {
1289 }; 1289 self.copyManager_.requestCancel();
1290 };
1291 }
1292 this.showButter(strf('PASTE_ITEMS_REMAINING', status.pendingItems),
1293 options);
1290 } 1294 }
1291 this.showButter(strf('PASTE_ITEMS_REMAINING', status.pendingItems),
1292 options);
1293 return;
1294 } 1295 }
1295 if (event.reason == 'PROGRESS' && shouldShow) { 1296 else if (event.reason == 'PROGRESS') {
1296 var options = {timeout:0, progress: progress}; 1297 if (shouldShow) {
1297 this.updateButter(strf('PASTE_ITEMS_REMAINING', status.pendingItems), 1298 var options = {timeout:0, progress: progress};
1298 options); 1299 this.updateButter(strf('PASTE_ITEMS_REMAINING', status.pendingItems),
1299 return; 1300 options);
1301 }
1300 } 1302 }
1301 if (event.reason == 'SUCCESS') { 1303 else if (event.reason == 'SUCCESS') {
1302 if (this.currentButter_) 1304 if (this.currentButter_)
1303 this.hideButter(); 1305 this.hideButter();
1304 1306
1305 this.updateCommands_(); 1307 this.updateCommands_();
1306 self = this; 1308 self = this;
1307 var callback; 1309 var callback;
1308 while (callback = self.pasteSuccessCallbacks_.shift()) { 1310 while (callback = self.pasteSuccessCallbacks_.shift()) {
1309 try { 1311 try {
1310 callback(); 1312 callback();
1311 } catch (ex) { 1313 } catch (ex) {
1312 console.error('Caught exception while inovking callback: ' + 1314 console.error('Caught exception while inovking callback: ' +
1313 callback, ex); 1315 callback, ex);
1314 } 1316 }
1315 } 1317 }
1318 // TODO(benchan): Currently, there is no FileWatcher emulation for
1319 // GDataFileSystem, so we need to manually trigger the directory rescan
1320 // after paste operations complete. Remove this once we emulate file
1321 // watching functionalities in GDataFileSystem.
1322 if (this.isOnGData()) {
1323 this.directoryModel_.rescanLater();
1324 }
1316 } else if (event.reason == 'ERROR') { 1325 } else if (event.reason == 'ERROR') {
1317 switch (event.error.reason) { 1326 switch (event.error.reason) {
1318 case 'TARGET_EXISTS': 1327 case 'TARGET_EXISTS':
1319 var name = event.error.data.name; 1328 var name = event.error.data.name;
1320 if (event.error.data.isDirectory) 1329 if (event.error.data.isDirectory)
1321 name += '/'; 1330 name += '/';
1322 this.showButterError(strf('PASTE_TARGET_EXISTS_ERROR', name)); 1331 this.showButterError(strf('PASTE_TARGET_EXISTS_ERROR', name));
1323 break; 1332 break;
1324 1333
1325 case 'FILESYSTEM_ERROR': 1334 case 'FILESYSTEM_ERROR':
(...skipping 1605 matching lines...) Expand 10 before | Expand all | Expand 10 after
2931 entry = this.selection.entries[i]; 2940 entry = this.selection.entries[i];
2932 if (entry.isDirectory) 2941 if (entry.isDirectory)
2933 directories += entry.fullPath + '\n'; 2942 directories += entry.fullPath + '\n';
2934 else 2943 else
2935 files += entry.fullPath + '\n'; 2944 files += entry.fullPath + '\n';
2936 } 2945 }
2937 2946
2938 event.clipboardData.setData('fs/isCut', isCut.toString()); 2947 event.clipboardData.setData('fs/isCut', isCut.toString());
2939 event.clipboardData.setData('fs/sourceDir', 2948 event.clipboardData.setData('fs/sourceDir',
2940 this.directoryModel_.currentEntry.fullPath); 2949 this.directoryModel_.currentEntry.fullPath);
2950 event.clipboardData.setData('fs/sourceOnGData', this.isOnGData());
2941 event.clipboardData.setData('fs/directories', directories); 2951 event.clipboardData.setData('fs/directories', directories);
2942 event.clipboardData.setData('fs/files', files); 2952 event.clipboardData.setData('fs/files', files);
2943 } 2953 }
2944 2954
2945 FileManager.prototype.copySelectionToClipboard_ = function(event) { 2955 FileManager.prototype.copySelectionToClipboard_ = function(event) {
2946 if (!this.selection || this.selection.totalCount == 0) 2956 if (!this.selection || this.selection.totalCount == 0)
2947 return; 2957 return;
2948 2958
2949 this.cutOrCopyToClipboard_(event, false); 2959 this.cutOrCopyToClipboard_(event, false);
2950 2960
(...skipping 20 matching lines...) Expand all
2971 2981
2972 if (!event.clipboardData.getData('fs/isCut')) 2982 if (!event.clipboardData.getData('fs/isCut'))
2973 return; 2983 return;
2974 2984
2975 // Pass an empty string so that the butter bar remains invisible until 2985 // Pass an empty string so that the butter bar remains invisible until
2976 // the first progress update. This prevents the flicker on short operations. 2986 // the first progress update. This prevents the flicker on short operations.
2977 this.showButter('', {timeout: 0}); 2987 this.showButter('', {timeout: 0});
2978 2988
2979 var clipboard = { 2989 var clipboard = {
2980 isCut: event.clipboardData.getData('fs/isCut'), 2990 isCut: event.clipboardData.getData('fs/isCut'),
2981 sourceDir: event.clipboardData.getData('fs/sourcedir'), 2991 sourceDir: event.clipboardData.getData('fs/sourceDir'),
2992 sourceOnGData: event.clipboardData.getData('fs/sourceOnGData'),
2982 directories: event.clipboardData.getData('fs/directories'), 2993 directories: event.clipboardData.getData('fs/directories'),
2983 files: event.clipboardData.getData('fs/files') 2994 files: event.clipboardData.getData('fs/files')
2984 }; 2995 };
2985 2996
2997 // If both source and target are on GData, FileCopyManager uses
2998 // FileEntry.copyTo() / FileEntry.moveTo() to copy / move files.
2999 var sourceAndTargetOnGData = clipboard.sourceOnGData && this.isOnGData();
2986 this.copyManager_.paste(clipboard, 3000 this.copyManager_.paste(clipboard,
2987 this.directoryModel_.currentEntry, 3001 this.directoryModel_.currentEntry,
3002 sourceAndTargetOnGData,
2988 this.filesystem_.root); 3003 this.filesystem_.root);
2989 3004
2990 var clearClipboard = function (event) { 3005 var clearClipboard = function (event) {
2991 event.preventDefault(); 3006 event.preventDefault();
2992 event.clipboardData.setData('fs/clear', ''); 3007 event.clipboardData.setData('fs/clear', '');
2993 } 3008 }
2994 3009
2995 // On cut, we clear the clipboard after the file is pasted/moved so we don't 3010 // On cut, we clear the clipboard after the file is pasted/moved so we don't
2996 // try to move/delete the original file again. 3011 // try to move/delete the original file again.
2997 if (clipboard.isCut == 'true') { 3012 if (clipboard.isCut == 'true') {
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after
4131 }); 4146 });
4132 }, onError); 4147 }, onError);
4133 4148
4134 function onError(err) { 4149 function onError(err) {
4135 console.log('Error while checking free space: ' + err); 4150 console.log('Error while checking free space: ' + err);
4136 setTimeout(doCheck, 1000 * 60); 4151 setTimeout(doCheck, 1000 * 60);
4137 } 4152 }
4138 } 4153 }
4139 } 4154 }
4140 })(); 4155 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698