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() { | 5 function FileCopyManager() { |
6 this.copyTasks_ = []; | 6 this.copyTasks_ = []; |
7 this.cancelObservers_ = []; | 7 this.cancelObservers_ = []; |
8 this.cancelRequested_ = false; | 8 this.cancelRequested_ = false; |
9 } | 9 } |
10 | 10 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 self.pendingDirectories = result.dirEntries; | 49 self.pendingDirectories = result.dirEntries; |
50 self.pendingFiles = result.fileEntries; | 50 self.pendingFiles = result.fileEntries; |
51 self.pendingBytes = result.fileBytes; | 51 self.pendingBytes = result.fileBytes; |
52 callback(); | 52 callback(); |
53 } | 53 } |
54 | 54 |
55 this.originalEntries = entries; | 55 this.originalEntries = entries; |
56 util.recurseAndResolveEntries(entries, onEntriesRecursed); | 56 util.recurseAndResolveEntries(entries, onEntriesRecursed); |
57 } | 57 } |
58 | 58 |
59 FileCopyManager.Task.prototype.takeNextEntry = function() { | 59 FileCopyManager.Task.prototype.takeNextEntry = function() { |
Rick Byers
2012/03/09 21:45:45
This function name is misleading now (you're not '
bshe
2012/03/12 00:13:34
Done.
| |
60 // We should keep the file in pending list and remove it after complete. | |
61 // Otherwise, if we try to get status in the middle of copying. The returned | |
62 // status is wrong (miss count the pasting item in totalItems). | |
60 if (this.pendingDirectories.length) | 63 if (this.pendingDirectories.length) |
61 return this.pendingDirectories.shift(); | 64 return this.pendingDirectories[0]; |
62 | 65 |
63 if (this.pendingFiles.length) | 66 if (this.pendingFiles.length) |
64 return this.pendingFiles.shift(); | 67 return this.pendingFiles[0]; |
65 | 68 |
66 return null; | 69 return null; |
67 }; | 70 }; |
68 | 71 |
69 FileCopyManager.Task.prototype.markEntryComplete = function(entry, size) { | 72 FileCopyManager.Task.prototype.markEntryComplete = function(entry, size) { |
70 if (entry.isDirectory) { | 73 if (entry.isDirectory) { |
71 this.completedDirectories.push(entry); | 74 this.completedDirectories.push(entry); |
75 this.pendingDirectories.shift(); | |
Rick Byers
2012/03/09 21:45:45
You're implicitly assuming that 'entry' is still t
bshe
2012/03/12 00:13:34
It seems entry is targetEntry and shift function r
| |
72 } else { | 76 } else { |
73 this.completedFiles.push(entry); | 77 this.completedFiles.push(entry); |
74 this.completedBytes += size; | 78 this.completedBytes += size; |
79 this.pendingFiles.shift(); | |
75 } | 80 } |
76 }; | 81 }; |
77 | 82 |
78 FileCopyManager.Task.prototype.registerRename = function(fromName, toName) { | 83 FileCopyManager.Task.prototype.registerRename = function(fromName, toName) { |
79 this.renamedDirectories_.push({from: fromName + '/', to: toName + '/'}); | 84 this.renamedDirectories_.push({from: fromName + '/', to: toName + '/'}); |
80 }; | 85 }; |
81 | 86 |
82 FileCopyManager.Task.prototype.applyRenames = function(path) { | 87 FileCopyManager.Task.prototype.applyRenames = function(path) { |
83 // Directories are processed in pre-order, so we will store only the first | 88 // Directories are processed in pre-order, so we will store only the first |
84 // renaming point: | 89 // renaming point: |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 onTaskComplete(); | 349 onTaskComplete(); |
345 } | 350 } |
346 | 351 |
347 for (var i = 0; i < task.originalEntries.length; i++) { | 352 for (var i = 0; i < task.originalEntries.length; i++) { |
348 util.removeFileOrDirectory( | 353 util.removeFileOrDirectory( |
349 task.originalEntries[i], onEntryDeleted, onFilesystemError); | 354 task.originalEntries[i], onEntryDeleted, onFilesystemError); |
350 } | 355 } |
351 } | 356 } |
352 | 357 |
353 function onEntryServiced(targetEntry, size) { | 358 function onEntryServiced(targetEntry, size) { |
354 if (!targetEntry) { | 359 // We should not dispatch a PROGRESS event when there is no pending items |
360 // in the task. | |
361 if (task.pendingDirectories.length + task.pendingFiles.length == 0) { | |
355 // All done with the entries in this task. | 362 // All done with the entries in this task. |
356 if (task.deleteAfterCopy) { | 363 if (task.deleteAfterCopy) { |
357 deleteOriginals() | 364 deleteOriginals() |
358 } else { | 365 } else { |
359 onTaskComplete(); | 366 onTaskComplete(); |
360 } | 367 } |
361 return; | 368 return; |
362 } | 369 } |
363 | 370 |
364 var event = new cr.Event('copy-progress'); | 371 var event = new cr.Event('copy-progress'); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 successCallback(targetEntry, file.size) | 526 successCallback(targetEntry, file.size) |
520 }; | 527 }; |
521 writer.write(file); | 528 writer.write(file); |
522 } | 529 } |
523 | 530 |
524 targetEntry.createWriter(onWriterCreated, errorCallback); | 531 targetEntry.createWriter(onWriterCreated, errorCallback); |
525 } | 532 } |
526 | 533 |
527 sourceEntry.file(onSourceFileFound, errorCallback); | 534 sourceEntry.file(onSourceFileFound, errorCallback); |
528 }; | 535 }; |
OLD | NEW |