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 // If directory files changes too often, don't rescan directory more than once | 5 // If directory files changes too often, don't rescan directory more than once |
6 // per specified interval | 6 // per specified interval |
7 var SIMULTANEOUS_RESCAN_INTERVAL = 1000; | 7 var SIMULTANEOUS_RESCAN_INTERVAL = 1000; |
8 // Used for operations that require almost instant rescan. | 8 // Used for operations that require almost instant rescan. |
9 var SHORT_RESCAN_INTERVAL = 100; | 9 var SHORT_RESCAN_INTERVAL = 100; |
10 | 10 |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
487 }; | 487 }; |
488 | 488 |
489 /** | 489 /** |
490 * Delete the list of files and directories from filesystem and | 490 * Delete the list of files and directories from filesystem and |
491 * update the file list. | 491 * update the file list. |
492 * @param {Array.<Entry>} entries Entries to delete. | 492 * @param {Array.<Entry>} entries Entries to delete. |
493 * @param {function()=} opt_callback Called when finished. | 493 * @param {function()=} opt_callback Called when finished. |
494 */ | 494 */ |
495 DirectoryModel.prototype.deleteEntries = function(entries, opt_callback) { | 495 DirectoryModel.prototype.deleteEntries = function(entries, opt_callback) { |
496 var downcount = entries.length + 1; | 496 var downcount = entries.length + 1; |
497 var currentDirPath = this.getCurrentDirPath(); | |
497 | 498 |
498 var onComplete = opt_callback ? function() { | 499 var onComplete = opt_callback ? function() { |
499 if (--downcount == 0) | 500 if (--downcount == 0) |
500 opt_callback(); | 501 opt_callback(); |
501 } : function() {}; | 502 } : function() {}; |
502 | 503 |
503 var fileList = this.getFileList(); | 504 var fileList = this.getFileList(); |
504 for (var i = 0; i < entries.length; i++) { | 505 for (var i = 0; i < entries.length; i++) { |
505 var entry = entries[i]; | 506 var entry = entries[i]; |
506 | 507 |
507 var onSuccess = function(removedEntry) { | 508 var onSuccess = function(removedEntry) { |
508 var index = fileList.indexOf(removedEntry); | 509 if (currentDirPath == this.getCurrentDirPath()) { |
509 if (index >= 0) | 510 var index = fileList.indexOf(removedEntry); |
510 fileList.splice(index, 1); | 511 if (index >= 0) |
512 fileList.splice(index, 1); | |
513 } | |
511 onComplete(); | 514 onComplete(); |
Vladislav Kaznacheev
2012/08/02 12:45:39
Is it safe to call the callback if the directory h
SeRya
2012/08/02 12:56:20
Sure. And it's called. Only fileList update is omi
| |
512 }.bind(null, entry); | 515 }.bind(this, entry); |
513 | 516 |
514 util.removeFileOrDirectory( | 517 util.removeFileOrDirectory( |
515 entry, | 518 entry, |
516 onSuccess, | 519 onSuccess, |
517 util.flog('Error deleting ' + entry.fullPath, onComplete)); | 520 util.flog('Error deleting ' + entry.fullPath, onComplete)); |
518 } | 521 } |
519 onComplete(); | 522 onComplete(); |
520 }; | 523 }; |
521 | 524 |
522 /** | 525 /** |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
575 * Rename the entry in the filesystem and update the file list. | 578 * Rename the entry in the filesystem and update the file list. |
576 * @param {Entry} entry Entry to rename. | 579 * @param {Entry} entry Entry to rename. |
577 * @param {string} newName New name. | 580 * @param {string} newName New name. |
578 * @param {function} errorCallback Called on error. | 581 * @param {function} errorCallback Called on error. |
579 * @param {function} opt_successCallback Called on success. | 582 * @param {function} opt_successCallback Called on success. |
580 */ | 583 */ |
581 DirectoryModel.prototype.renameEntry = function(entry, newName, | 584 DirectoryModel.prototype.renameEntry = function(entry, newName, |
582 errorCallback, | 585 errorCallback, |
583 opt_successCallback) { | 586 opt_successCallback) { |
584 var self = this; | 587 var self = this; |
588 var currentDirPath = this.getCurrentDirPath(); | |
585 function onSuccess(newEntry) { | 589 function onSuccess(newEntry) { |
586 self.currentDirContents_.prefetchMetadata([newEntry], function() { | 590 self.currentDirContents_.prefetchMetadata([newEntry], function() { |
591 // Do not change anything or call the callback if current | |
592 // directory changed. | |
593 if (currentDirPath != self.getCurrentDirPath()) | |
594 return; | |
595 | |
587 var index = self.findIndexByName_(entry.name); | 596 var index = self.findIndexByName_(entry.name); |
588 if (index >= 0) | 597 if (index >= 0) |
589 self.getFileList().splice(index, 1, newEntry); | 598 self.getFileList().splice(index, 1, newEntry); |
590 self.selectEntry(newEntry.name); | 599 self.selectEntry(newEntry.name); |
591 // If the entry doesn't exist in the list it mean that it updated from | 600 // If the entry doesn't exist in the list it mean that it updated from |
592 // outside (probably by directory rescan). | 601 // outside (probably by directory rescan). |
593 if (opt_successCallback) | 602 if (opt_successCallback) |
594 opt_successCallback(); | 603 opt_successCallback(); |
595 }); | 604 }); |
596 } | 605 } |
(...skipping 27 matching lines...) Expand all Loading... | |
624 | 633 |
625 /** | 634 /** |
626 * Creates directory and updates the file list. | 635 * Creates directory and updates the file list. |
627 * | 636 * |
628 * @param {string} name Directory name. | 637 * @param {string} name Directory name. |
629 * @param {function} successCallback Callback on success. | 638 * @param {function} successCallback Callback on success. |
630 * @param {function} errorCallback Callback on failure. | 639 * @param {function} errorCallback Callback on failure. |
631 */ | 640 */ |
632 DirectoryModel.prototype.createDirectory = function(name, successCallback, | 641 DirectoryModel.prototype.createDirectory = function(name, successCallback, |
633 errorCallback) { | 642 errorCallback) { |
643 var currentDirPath = this.getCurrentDirPath(); | |
Vladislav Kaznacheev
2012/08/02 12:45:39
I see the pattern here. How about creating a wrapp
SeRya
2012/08/02 12:56:20
In my oppinion cost of this level of abstraction d
| |
644 | |
634 var onSuccess = function(newEntry) { | 645 var onSuccess = function(newEntry) { |
646 // Do not change anything or call the callback if current | |
647 // directory changed. | |
648 if (currentDirPath != this.getCurrentDirPath()) | |
649 return; | |
650 | |
635 var existing = this.getFileList().slice().filter( | 651 var existing = this.getFileList().slice().filter( |
636 function(e) {return e.name == name;}); | 652 function(e) {return e.name == name;}); |
637 | 653 |
638 if (existing.length) { | 654 if (existing.length) { |
639 this.selectEntry(name); | 655 this.selectEntry(name); |
640 successCallback(existing[0]); | 656 successCallback(existing[0]); |
641 } else { | 657 } else { |
642 this.fileListSelection_.beginChange(); | 658 this.fileListSelection_.beginChange(); |
643 this.getFileList().splice(0, 0, newEntry); | 659 this.getFileList().splice(0, 0, newEntry); |
644 this.selectEntry(name); | 660 this.selectEntry(name); |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1324 }.bind(this)); | 1340 }.bind(this)); |
1325 } | 1341 } |
1326 }; | 1342 }; |
1327 | 1343 |
1328 /** | 1344 /** |
1329 * @return {DirectoryEntry} Current watched directory entry. | 1345 * @return {DirectoryEntry} Current watched directory entry. |
1330 */ | 1346 */ |
1331 FileWatcher.prototype.getWatchedDirectoryEntry = function() { | 1347 FileWatcher.prototype.getWatchedDirectoryEntry = function() { |
1332 return this.watchedDirectoryEntry_; | 1348 return this.watchedDirectoryEntry_; |
1333 }; | 1349 }; |
OLD | NEW |