Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // All done with the entries in this task. |
| 437 // If files are moved within GData, FileEntry.moveTo() is used and | 444 // If files are moved within GData, FileEntry.moveTo() is used and |
| 438 // there is no need to delete the original files. | 445 // there is no need to delete the original files. |
| 439 var sourceAndTargetOnGData = task.sourceOnGData && task.targetOnGData; | 446 var sourceAndTargetOnGData = task.sourceOnGData && task.targetOnGData; |
|
Vladislav Kaznacheev
2012/04/16 06:55:45
Looks like this variable is not used anymore. The
SeRya
2012/04/16 07:05:29
Done.
| |
| 440 if (task.deleteAfterCopy && !sourceAndTargetOnGData) { | 447 if (task.deleteAfterCopy) { |
| 441 deleteOriginals(); | 448 deleteOriginals(); |
| 442 } else { | 449 } else { |
| 443 onTaskComplete(); | 450 onTaskComplete(); |
| 444 } | 451 } |
| 445 return; | 452 return; |
| 446 } | 453 } |
| 447 | 454 |
| 448 self.sendProgressEvent_('PROGRESS'); | 455 self.sendProgressEvent_('PROGRESS'); |
| 449 | 456 |
| 450 // We yield a few ms between copies to give the browser a chance to service | 457 // 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 Loading... | |
| 598 } | 605 } |
| 599 } | 606 } |
| 600 | 607 |
| 601 function onTargetNotResolved(err) { | 608 function onTargetNotResolved(err) { |
| 602 // We expect to be unable to resolve the target file, since we're going | 609 // 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 | 610 // to create it during the copy. However, if the resolve fails with |
| 604 // anything other than NOT_FOUND, that's trouble. | 611 // anything other than NOT_FOUND, that's trouble. |
| 605 if (err.code != FileError.NOT_FOUND_ERR) | 612 if (err.code != FileError.NOT_FOUND_ERR) |
| 606 return onError('FILESYSTEM_ERROR', err); | 613 return onError('FILESYSTEM_ERROR', err); |
| 607 | 614 |
| 608 if (task.deleteAfterCopy && | 615 if (task.move) { |
| 609 DirectoryModel.getRootPath(sourceEntry.fullPath) == | |
| 610 DirectoryModel.getRootPath(targetDirEntry.fullPath)) { | |
| 611 resolveDirAndBaseName( | 616 resolveDirAndBaseName( |
| 612 targetDirEntry, targetRelativePath, | 617 targetDirEntry, targetRelativePath, |
| 613 function(dirEntry, fileName) { | 618 function(dirEntry, fileName) { |
| 614 sourceEntry.moveTo(dirEntry, fileName, | 619 sourceEntry.moveTo(dirEntry, fileName, |
| 615 onFilesystemMoveComplete.bind(self, sourceEntry), | 620 onFilesystemMoveComplete.bind(self, sourceEntry), |
| 616 onFilesystemError); | 621 onFilesystemError); |
| 617 }, | 622 }, |
| 618 onFilesystemError); | 623 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; | 624 return; |
| 623 } | 625 } |
| 624 | 626 |
| 625 if (task.sourceOnGData && task.targetOnGData && !task.deleteAfterCopy) { | 627 if (task.sourceOnGData && task.targetOnGData) { |
| 626 // TODO(benchan): GDataFileSystem has not implemented directory copy, | 628 // TODO(benchan): GDataFileSystem has not implemented directory copy, |
| 627 // and thus we only call FileEntry.copyTo() for files. Revisit this | 629 // and thus we only call FileEntry.copyTo() for files. Revisit this |
| 628 // code when GDataFileSystem supports directory copy. | 630 // code when GDataFileSystem supports directory copy. |
| 629 if (!sourceEntry.isDirectory) { | 631 if (!sourceEntry.isDirectory) { |
| 630 resolveDirAndBaseName( | 632 resolveDirAndBaseName( |
| 631 targetDirEntry, targetRelativePath, | 633 targetDirEntry, targetRelativePath, |
| 632 function(dirEntry, fileName) { | 634 function(dirEntry, fileName) { |
| 633 sourceEntry.copyTo(dirEntry, fileName, | 635 sourceEntry.copyTo(dirEntry, fileName, |
| 634 onFilesystemCopyComplete.bind(self, sourceEntry), | 636 onFilesystemCopyComplete.bind(self, sourceEntry), |
| 635 onFilesystemError); | 637 onFilesystemError); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 719 successCallback(targetEntry, file.size) | 721 successCallback(targetEntry, file.size) |
| 720 }; | 722 }; |
| 721 writer.write(file); | 723 writer.write(file); |
| 722 } | 724 } |
| 723 | 725 |
| 724 targetEntry.createWriter(onWriterCreated, errorCallback); | 726 targetEntry.createWriter(onWriterCreated, errorCallback); |
| 725 } | 727 } |
| 726 | 728 |
| 727 sourceEntry.file(onSourceFileFound, errorCallback); | 729 sourceEntry.file(onSourceFileFound, errorCallback); |
| 728 }; | 730 }; |
| OLD | NEW |