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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 if (chrome.extension) { | 7 if (chrome.extension) { |
8 var getContentWindows = function() { | 8 var getContentWindows = function() { |
9 return chrome.extension.getViews(); | 9 return chrome.extension.getViews(); |
10 }; | 10 }; |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 if (total == 0) | 515 if (total == 0) |
516 return; | 516 return; |
517 | 517 |
518 util.getDirectories(self.root_, {create: false}, directories, onEntryFound, | 518 util.getDirectories(self.root_, {create: false}, directories, onEntryFound, |
519 onPathError); | 519 onPathError); |
520 util.getFiles(self.root_, {create: false}, files, onEntryFound, | 520 util.getFiles(self.root_, {create: false}, files, onEntryFound, |
521 onPathError); | 521 onPathError); |
522 }; | 522 }; |
523 | 523 |
524 /** | 524 /** |
525 * Checks if source and target are on the same root. | 525 * Checks if the move operation is avaiable between the given two locations. |
526 * | 526 * |
527 * @param {DirectoryEntry} sourceEntry An entry from the source. | 527 * @param {DirectoryEntry} sourceEntry An entry from the source. |
528 * @param {DirectoryEntry} targetDirEntry Directory entry for the target. | 528 * @param {DirectoryEntry} targetDirEntry Directory entry for the target. |
529 * @param {boolean} targetOnDrive If target is on Drive. | 529 * @return {boolean} Whether we can move from the source to the target. |
530 * @return {boolean} Whether source and target dir are on the same root. | |
531 */ | 530 */ |
532 FileCopyManager.prototype.isOnSameRoot = function(sourceEntry, | 531 FileCopyManager.prototype.isMovable = function(sourceEntry, |
533 targetDirEntry, | 532 targetDirEntry) { |
534 targetOnDrive) { | 533 return (PathUtil.isDriveBasedPath(sourceEntry.fullPath) && |
535 return PathUtil.getRootPath(sourceEntry.fullPath) == | 534 PathUtil.isDriveBasedPath(targetDirEntry.fullPath)) || |
536 PathUtil.getRootPath(targetDirEntry.fullPath); | 535 (PathUtil.getRootPath(sourceEntry.fullPath) == |
| 536 PathUtil.getRootPath(targetDirEntry.fullPath)); |
537 }; | 537 }; |
538 | 538 |
539 /** | 539 /** |
540 * Initiate a file copy. | 540 * Initiate a file copy. |
541 * | 541 * |
542 * @param {DirectoryEntry} targetDirEntry Target directory. | 542 * @param {DirectoryEntry} targetDirEntry Target directory. |
543 * @param {Array.<Entry>} entries Entries to copy. | 543 * @param {Array.<Entry>} entries Entries to copy. |
544 * @param {boolean} deleteAfterCopy In case of move. | 544 * @param {boolean} deleteAfterCopy In case of move. |
545 * @param {boolean} sourceOnDrive Source directory on Drive. | 545 * @param {boolean} sourceOnDrive Source directory on Drive. |
546 * @param {boolean} targetOnDrive Target directory on Drive. | 546 * @param {boolean} targetOnDrive Target directory on Drive. |
547 * @return {FileCopyManager.Task} Copy task. | 547 * @return {FileCopyManager.Task} Copy task. |
548 * @private | 548 * @private |
549 */ | 549 */ |
550 FileCopyManager.prototype.queueCopy_ = function(targetDirEntry, | 550 FileCopyManager.prototype.queueCopy_ = function(targetDirEntry, |
551 entries, | 551 entries, |
552 deleteAfterCopy, | 552 deleteAfterCopy, |
553 sourceOnDrive, | 553 sourceOnDrive, |
554 targetOnDrive) { | 554 targetOnDrive) { |
555 var self = this; | 555 var self = this; |
556 // When copying files, null can be specified as source directory. | 556 // When copying files, null can be specified as source directory. |
557 var copyTask = new FileCopyManager.Task(targetDirEntry); | 557 var copyTask = new FileCopyManager.Task(targetDirEntry); |
558 if (deleteAfterCopy) { | 558 if (deleteAfterCopy) { |
559 // |sourecDirEntry| may be null, so let's check the root for the first of | 559 if (this.isMovable(entries[0], targetDirEntry)) { |
560 // the entries scheduled to be copied. | |
561 if (this.isOnSameRoot(entries[0], targetDirEntry)) { | |
562 copyTask.move = true; | 560 copyTask.move = true; |
563 } else { | 561 } else { |
564 copyTask.deleteAfterCopy = true; | 562 copyTask.deleteAfterCopy = true; |
565 } | 563 } |
566 } | 564 } |
567 copyTask.sourceOnDrive = sourceOnDrive; | 565 copyTask.sourceOnDrive = sourceOnDrive; |
568 copyTask.targetOnDrive = targetOnDrive; | 566 copyTask.targetOnDrive = targetOnDrive; |
569 copyTask.setEntries(entries, function() { | 567 copyTask.setEntries(entries, function() { |
570 self.copyTasks_.push(copyTask); | 568 self.copyTasks_.push(copyTask); |
571 self.maybeScheduleCloseBackgroundPage_(); | 569 self.maybeScheduleCloseBackgroundPage_(); |
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1279 // Assume self.cancelRequested_ == false. | 1277 // Assume self.cancelRequested_ == false. |
1280 // This moved us from 0 to 1 active tasks, let the servicing begin! | 1278 // This moved us from 0 to 1 active tasks, let the servicing begin! |
1281 self.serviceAllTasks_(); | 1279 self.serviceAllTasks_(); |
1282 } else { | 1280 } else { |
1283 // Force to update the progress of butter bar when there are new tasks | 1281 // Force to update the progress of butter bar when there are new tasks |
1284 // coming while servicing current task. | 1282 // coming while servicing current task. |
1285 self.sendProgressEvent_('PROGRESS'); | 1283 self.sendProgressEvent_('PROGRESS'); |
1286 } | 1284 } |
1287 }); | 1285 }); |
1288 }; | 1286 }; |
OLD | NEW |