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 const SIMULTANEOUS_RESCAN_INTERVAL = 1000; | 7 const SIMULTANEOUS_RESCAN_INTERVAL = 1000; |
8 | 8 |
9 /** | 9 /** |
10 * Data model of the file manager. | 10 * Data model of the file manager. |
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 function onCacheDone() { | 747 function onCacheDone() { |
748 waitCount--; | 748 waitCount--; |
749 // If all caching functions finished synchronously or entries.length = 0 | 749 // If all caching functions finished synchronously or entries.length = 0 |
750 // call the callback synchronously. | 750 // call the callback synchronously. |
751 if (waitCount == 0) | 751 if (waitCount == 0) |
752 setTimeout(callback, 0); | 752 setTimeout(callback, 0); |
753 } | 753 } |
754 }, | 754 }, |
755 | 755 |
756 /** | 756 /** |
757 * Get root entries asynchronously. Invokes callback | 757 * Get root entries asynchronously. |
758 * when have finished. | 758 * @param {function(Array.<Entry>} callback Called when roots are resolved. |
| 759 * @param {boolean} resolveGData See comment for updateRoots. |
759 */ | 760 */ |
760 resolveRoots_: function(callback) { | 761 resolveRoots_: function(callback, resolveGData) { |
761 var groups = { | 762 var groups = { |
762 downloads: null, | 763 downloads: null, |
763 archives: null, | 764 archives: null, |
764 removables: null, | 765 removables: null, |
765 gdata: null | 766 gdata: null |
766 }; | 767 }; |
767 | 768 |
768 metrics.startInterval('Load.Roots'); | 769 metrics.startInterval('Load.Roots'); |
769 function done() { | 770 function done() { |
770 for (var i in groups) | 771 for (var i in groups) |
(...skipping 29 matching lines...) Expand all Loading... |
800 console.log(entry); | 801 console.log(entry); |
801 self.unmountedGDataEntry_ = null; | 802 self.unmountedGDataEntry_ = null; |
802 groups.gdata = [entry]; | 803 groups.gdata = [entry]; |
803 done(); | 804 done(); |
804 } | 805 } |
805 | 806 |
806 function onGDataError(error) { | 807 function onGDataError(error) { |
807 console.log('onGDataError'); | 808 console.log('onGDataError'); |
808 console.log(error); | 809 console.log(error); |
809 self.unmountedGDataEntry_ = { | 810 self.unmountedGDataEntry_ = { |
| 811 unmounted: true, // Clients use this field to distinguish a fake root. |
| 812 toURL: function() { return '' }, |
810 fullPath: '/' + DirectoryModel.GDATA_DIRECTORY | 813 fullPath: '/' + DirectoryModel.GDATA_DIRECTORY |
811 }; | 814 }; |
812 groups.gdata = [self.unmountedGDataEntry_]; | 815 groups.gdata = [self.unmountedGDataEntry_]; |
813 done(); | 816 done(); |
814 } | 817 } |
815 | 818 |
816 var root = this.root_; | 819 var root = this.root_; |
817 root.getDirectory(DirectoryModel.DOWNLOADS_DIRECTORY, { create: false }, | 820 root.getDirectory(DirectoryModel.DOWNLOADS_DIRECTORY, { create: false }, |
818 onDownloads, onDownloadsError); | 821 onDownloads, onDownloadsError); |
819 util.readDirectory(root, DirectoryModel.ARCHIVE_DIRECTORY, | 822 util.readDirectory(root, DirectoryModel.ARCHIVE_DIRECTORY, |
820 append.bind(this, 'archives')); | 823 append.bind(this, 'archives')); |
821 util.readDirectory(root, DirectoryModel.REMOVABLE_DIRECTORY, | 824 util.readDirectory(root, DirectoryModel.REMOVABLE_DIRECTORY, |
822 append.bind(this, 'removables')); | 825 append.bind(this, 'removables')); |
823 if (this.showGData_) { | 826 if (this.showGData_) { |
824 root.getDirectory(DirectoryModel.GDATA_DIRECTORY, { create: false }, | 827 if (resolveGData) { |
825 onGData, onGDataError); | 828 root.getDirectory(DirectoryModel.GDATA_DIRECTORY, { create: false }, |
| 829 onGData, onGDataError); |
| 830 } else { |
| 831 onGDataError('lazy mount'); |
| 832 } |
826 } else { | 833 } else { |
827 groups.gdata = []; | 834 groups.gdata = []; |
828 } | 835 } |
829 }, | 836 }, |
830 | 837 |
831 updateRoots: function(opt_callback) { | 838 /** |
| 839 * @param {function} opt_callback Called when all roots are resolved. |
| 840 * @param {boolean} opt_resolveGData If true GData should be resolved for real, |
| 841 * If false a stub entry should be created. |
| 842 */ |
| 843 updateRoots: function(opt_callback, opt_resolveGData) { |
832 console.log('directoryModel_.updateRoots'); | 844 console.log('directoryModel_.updateRoots'); |
833 var self = this; | 845 var self = this; |
834 this.resolveRoots_(function(rootEntries) { | 846 this.resolveRoots_(function(rootEntries) { |
835 console.log('rootsList_ = '); | 847 console.log('rootsList_ = '); |
836 console.log(self.rootsList_); | 848 console.log(self.rootsList_); |
837 var dm = self.rootsList_; | 849 var dm = self.rootsList_; |
838 var args = [0, dm.length].concat(rootEntries); | 850 var args = [0, dm.length].concat(rootEntries); |
839 dm.splice.apply(dm, args); | 851 dm.splice.apply(dm, args); |
840 | 852 |
841 self.updateRootsListSelection_(); | 853 self.updateRootsListSelection_(); |
842 | 854 |
843 if (opt_callback) | 855 if (opt_callback) |
844 opt_callback(); | 856 opt_callback(); |
845 }); | 857 }, opt_resolveGData); |
846 }, | 858 }, |
847 | 859 |
848 onRootsSelectionChanged_: function(event) { | 860 onRootsSelectionChanged_: function(event) { |
849 var root = this.rootsList.item(this.rootsListSelection.selectedIndex); | 861 var root = this.rootsList.item(this.rootsListSelection.selectedIndex); |
850 var current = this.currentEntry.fullPath; | 862 var current = this.currentEntry.fullPath; |
851 if (root && this.rootPath != root.fullPath) | 863 if (root && this.rootPath != root.fullPath) |
852 this.changeDirectory(root.fullPath); | 864 this.changeDirectory(root.fullPath); |
853 }, | 865 }, |
854 | 866 |
855 updateRootsListSelection_: function() { | 867 updateRootsListSelection_: function() { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 | 1002 |
991 recordMetrics_: function() { | 1003 recordMetrics_: function() { |
992 metrics.recordInterval('DirectoryScan'); | 1004 metrics.recordInterval('DirectoryScan'); |
993 if (this.dir_.fullPath == | 1005 if (this.dir_.fullPath == |
994 '/' + DirectoryModel.DOWNLOADS_DIRECTORY) { | 1006 '/' + DirectoryModel.DOWNLOADS_DIRECTORY) { |
995 metrics.recordMediumCount("DownloadsCount", this.list_.length); | 1007 metrics.recordMediumCount("DownloadsCount", this.list_.length); |
996 } | 1008 } |
997 } | 1009 } |
998 }; | 1010 }; |
999 | 1011 |
OLD | NEW |