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

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

Issue 9949069: Fix cut/paste on the same volume. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review fixes. Created 8 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 function FileCopyManager(root) { 5 function FileCopyManager(root) {
6 this.copyTasks_ = []; 6 this.copyTasks_ = [];
7 this.cancelObservers_ = []; 7 this.cancelObservers_ = [];
8 this.cancelRequested_ = false; 8 this.cancelRequested_ = false;
9 this.root_ = root; 9 this.root_ = root;
10 } 10 }
(...skipping 16 matching lines...) Expand all
27 27
28 this.pendingDirectories = []; 28 this.pendingDirectories = [];
29 this.pendingFiles = []; 29 this.pendingFiles = [];
30 this.pendingBytes = 0; 30 this.pendingBytes = 0;
31 31
32 this.completedDirectories = []; 32 this.completedDirectories = [];
33 this.completedFiles = []; 33 this.completedFiles = [];
34 this.completedBytes = 0; 34 this.completedBytes = 0;
35 35
36 this.deleteAfterCopy = false; 36 this.deleteAfterCopy = false;
37 this.move = false;
37 this.sourceOnGData = false; 38 this.sourceOnGData = false;
38 this.targetOnGData = false; 39 this.targetOnGData = false;
39 40
40 // If directory already exists, we try to make a copy named 'dir (X)', 41 // If directory already exists, we try to make a copy named 'dir (X)',
41 // where X is a number. When we do this, all subsequent copies from 42 // where X is a number. When we do this, all subsequent copies from
42 // inside the subtree should be mapped to the new directory name. 43 // inside the subtree should be mapped to the new directory name.
43 // For example, if 'dir' was copied as 'dir (1)', then 'dir\file.txt' should 44 // For example, if 'dir' was copied as 'dir (1)', then 'dir\file.txt' should
44 // become 'dir (1)\file.txt'. 45 // become 'dir (1)\file.txt'.
45 this.renamedDirectories_ = []; 46 this.renamedDirectories_ = [];
46 } 47 }
47 48
48 FileCopyManager.Task.prototype.setEntries = function(entries, callback) { 49 FileCopyManager.Task.prototype.setEntries = function(entries, callback) {
49 var self = this; 50 var self = this;
50 51
51 function onEntriesRecursed(result) { 52 function onEntriesRecursed(result) {
52 self.pendingDirectories = result.dirEntries; 53 self.pendingDirectories = result.dirEntries;
53 self.pendingFiles = result.fileEntries; 54 self.pendingFiles = result.fileEntries;
54 self.pendingBytes = result.fileBytes; 55 self.pendingBytes = result.fileBytes;
55 callback(); 56 callback();
56 } 57 }
57 58
58 this.originalEntries = entries; 59 this.originalEntries = entries;
59 // When moving directories, FileEntry.moveTo() is used if both source 60 // When moving directories, FileEntry.moveTo() is used if both source
60 // and target are on GData. There is no need to recurse into directories. 61 // and target are on GData. There is no need to recurse into directories.
61 var recurse = !(this.deleteAfterCopy && 62 var recurse = !this.move;
62 this.sourceOnGData && this.targetOnGData);
63 util.recurseAndResolveEntries(entries, recurse, onEntriesRecursed); 63 util.recurseAndResolveEntries(entries, recurse, onEntriesRecursed);
64 } 64 }
65 65
66 FileCopyManager.Task.prototype.getNextEntry = function() { 66 FileCopyManager.Task.prototype.getNextEntry = function() {
67 // We should keep the file in pending list and remove it after complete. 67 // We should keep the file in pending list and remove it after complete.
68 // Otherwise, if we try to get status in the middle of copying. The returned 68 // Otherwise, if we try to get status in the middle of copying. The returned
69 // status is wrong (miss count the pasting item in totalItems). 69 // status is wrong (miss count the pasting item in totalItems).
70 if (this.pendingDirectories.length) { 70 if (this.pendingDirectories.length) {
71 this.pendingDirectories[0].inProgress = true; 71 this.pendingDirectories[0].inProgress = true;
72 return this.pendingDirectories[0]; 72 return this.pendingDirectories[0];
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 * Initiate a file copy. 331 * Initiate a file copy.
332 */ 332 */
333 FileCopyManager.prototype.queueCopy = function(sourceDirEntry, 333 FileCopyManager.prototype.queueCopy = function(sourceDirEntry,
334 targetDirEntry, 334 targetDirEntry,
335 entries, 335 entries,
336 deleteAfterCopy, 336 deleteAfterCopy,
337 sourceOnGData, 337 sourceOnGData,
338 targetOnGData) { 338 targetOnGData) {
339 var self = this; 339 var self = this;
340 var copyTask = new FileCopyManager.Task(sourceDirEntry, targetDirEntry); 340 var copyTask = new FileCopyManager.Task(sourceDirEntry, targetDirEntry);
341 copyTask.deleteAfterCopy = deleteAfterCopy; 341 if (deleteAfterCopy) {
342 if (DirectoryModel.getRootPath(sourceDirEntry.fullPath) ==
343 DirectoryModel.getRootPath(targetDirEntry.fullPath)) {
344 copyTask.move = true;
345 } else {
346 copyTask.deleteAfterCopy = true;
347 }
348 }
342 copyTask.sourceOnGData = sourceOnGData; 349 copyTask.sourceOnGData = sourceOnGData;
343 copyTask.targetOnGData = targetOnGData; 350 copyTask.targetOnGData = targetOnGData;
344 copyTask.setEntries(entries, function() { 351 copyTask.setEntries(entries, function() {
345 self.copyTasks_.push(copyTask); 352 self.copyTasks_.push(copyTask);
346 if (self.copyTasks_.length == 1) { 353 if (self.copyTasks_.length == 1) {
347 // This moved us from 0 to 1 active tasks, let the servicing begin! 354 // This moved us from 0 to 1 active tasks, let the servicing begin!
348 self.serviceAllTasks_(); 355 self.serviceAllTasks_();
349 } else { 356 } else {
350 // Force to update the progress of butter bar when there are new tasks 357 // Force to update the progress of butter bar when there are new tasks
351 // coming while servicing current task. 358 // coming while servicing current task.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 var entry = task.originalEntries[i]; 433 var entry = task.originalEntries[i];
427 util.removeFileOrDirectory( 434 util.removeFileOrDirectory(
428 entry, onEntryDeleted.bind(self, entry), onFilesystemError); 435 entry, onEntryDeleted.bind(self, entry), onFilesystemError);
429 } 436 }
430 } 437 }
431 438
432 function onEntryServiced(targetEntry, size) { 439 function onEntryServiced(targetEntry, size) {
433 // We should not dispatch a PROGRESS event when there is no pending items 440 // We should not dispatch a PROGRESS event when there is no pending items
434 // in the task. 441 // in the task.
435 if (task.pendingDirectories.length + task.pendingFiles.length == 0) { 442 if (task.pendingDirectories.length + task.pendingFiles.length == 0) {
436 // All done with the entries in this task. 443 if (task.deleteAfterCopy) {
437 // If files are moved within GData, FileEntry.moveTo() is used and
438 // there is no need to delete the original files.
439 var sourceAndTargetOnGData = task.sourceOnGData && task.targetOnGData;
440 if (task.deleteAfterCopy && !sourceAndTargetOnGData) {
441 deleteOriginals(); 444 deleteOriginals();
442 } else { 445 } else {
443 onTaskComplete(); 446 onTaskComplete();
444 } 447 }
445 return; 448 return;
446 } 449 }
447 450
448 self.sendProgressEvent_('PROGRESS'); 451 self.sendProgressEvent_('PROGRESS');
449 452
450 // We yield a few ms between copies to give the browser a chance to service 453 // We yield a few ms between copies to give the browser a chance to service
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 } 601 }
599 } 602 }
600 603
601 function onTargetNotResolved(err) { 604 function onTargetNotResolved(err) {
602 // We expect to be unable to resolve the target file, since we're going 605 // We expect to be unable to resolve the target file, since we're going
603 // to create it during the copy. However, if the resolve fails with 606 // to create it during the copy. However, if the resolve fails with
604 // anything other than NOT_FOUND, that's trouble. 607 // anything other than NOT_FOUND, that's trouble.
605 if (err.code != FileError.NOT_FOUND_ERR) 608 if (err.code != FileError.NOT_FOUND_ERR)
606 return onError('FILESYSTEM_ERROR', err); 609 return onError('FILESYSTEM_ERROR', err);
607 610
608 if (task.deleteAfterCopy && 611 if (task.move) {
609 DirectoryModel.getRootPath(sourceEntry.fullPath) ==
610 DirectoryModel.getRootPath(targetDirEntry.fullPath)) {
611 resolveDirAndBaseName( 612 resolveDirAndBaseName(
612 targetDirEntry, targetRelativePath, 613 targetDirEntry, targetRelativePath,
613 function(dirEntry, fileName) { 614 function(dirEntry, fileName) {
614 sourceEntry.moveTo(dirEntry, fileName, 615 sourceEntry.moveTo(dirEntry, fileName,
615 onFilesystemMoveComplete.bind(self, sourceEntry), 616 onFilesystemMoveComplete.bind(self, sourceEntry),
616 onFilesystemError); 617 onFilesystemError);
617 }, 618 },
618 onFilesystemError); 619 onFilesystemError);
619 // Since the file has been moved (not copied) the original file doesn't
620 // need to be deleted.
621 task.deleteAfterCopy = false;
622 return; 620 return;
623 } 621 }
624 622
625 if (task.sourceOnGData && task.targetOnGData && !task.deleteAfterCopy) { 623 if (task.sourceOnGData && task.targetOnGData) {
626 // TODO(benchan): GDataFileSystem has not implemented directory copy, 624 // TODO(benchan): GDataFileSystem has not implemented directory copy,
627 // and thus we only call FileEntry.copyTo() for files. Revisit this 625 // and thus we only call FileEntry.copyTo() for files. Revisit this
628 // code when GDataFileSystem supports directory copy. 626 // code when GDataFileSystem supports directory copy.
629 if (!sourceEntry.isDirectory) { 627 if (!sourceEntry.isDirectory) {
630 resolveDirAndBaseName( 628 resolveDirAndBaseName(
631 targetDirEntry, targetRelativePath, 629 targetDirEntry, targetRelativePath,
632 function(dirEntry, fileName) { 630 function(dirEntry, fileName) {
633 sourceEntry.copyTo(dirEntry, fileName, 631 sourceEntry.copyTo(dirEntry, fileName,
634 onFilesystemCopyComplete.bind(self, sourceEntry), 632 onFilesystemCopyComplete.bind(self, sourceEntry),
635 onFilesystemError); 633 onFilesystemError);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 successCallback(targetEntry, file.size) 717 successCallback(targetEntry, file.size)
720 }; 718 };
721 writer.write(file); 719 writer.write(file);
722 } 720 }
723 721
724 targetEntry.createWriter(onWriterCreated, errorCallback); 722 targetEntry.createWriter(onWriterCreated, errorCallback);
725 } 723 }
726 724
727 sourceEntry.file(onSourceFileFound, errorCallback); 725 sourceEntry.file(onSourceFileFound, errorCallback);
728 }; 726 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698