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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 * A map root.fullPath -> currentDirectory.fullPath. | 46 * A map root.fullPath -> currentDirectory.fullPath. |
47 * @private | 47 * @private |
48 * @type {Object.<string, string>} | 48 * @type {Object.<string, string>} |
49 */ | 49 */ |
50 this.currentDirByRoot_ = {}; | 50 this.currentDirByRoot_ = {}; |
51 | 51 |
52 // The map 'name' -> callback. Callbacks are function(entry) -> boolean. | 52 // The map 'name' -> callback. Callbacks are function(entry) -> boolean. |
53 this.filters_ = {}; | 53 this.filters_ = {}; |
54 this.setFilterHidden(true); | 54 this.setFilterHidden(true); |
55 | 55 |
56 // Readonly status. | 56 /** @type {Object.<string, boolean>} */ |
57 this.readonly_ = false; | 57 this.volumeReadOnlyStatus_ = {}; |
Vladislav Kaznacheev
2012/04/25 11:08:04
I am concerned that the default value is "false" (
SeRya
2012/04/25 11:50:53
This place is not about default values. volumeRead
| |
58 this.currentVolumeMetadata_ = {rootPath: '/'}; | |
59 this.offline_ = false; | |
60 } | 58 } |
61 | 59 |
62 /** | 60 /** |
63 * The name of the directory containing externally | 61 * The name of the directory containing externally |
64 * mounted removable storage volumes. | 62 * mounted removable storage volumes. |
65 */ | 63 */ |
66 DirectoryModel.REMOVABLE_DIRECTORY = 'removable'; | 64 DirectoryModel.REMOVABLE_DIRECTORY = 'removable'; |
67 | 65 |
68 /** | 66 /** |
69 * The name of the directory containing externally | 67 * The name of the directory containing externally |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 * @return {string} Root name. | 130 * @return {string} Root name. |
133 */ | 131 */ |
134 DirectoryModel.prototype.getRootName = function() { | 132 DirectoryModel.prototype.getRootName = function() { |
135 return DirectoryModel.getRootName(this.currentDirEntry_.fullPath); | 133 return DirectoryModel.getRootName(this.currentDirEntry_.fullPath); |
136 }; | 134 }; |
137 | 135 |
138 /** | 136 /** |
139 * @return {boolean} True if current directory is read only. | 137 * @return {boolean} True if current directory is read only. |
140 */ | 138 */ |
141 DirectoryModel.prototype.isReadOnly = function() { | 139 DirectoryModel.prototype.isReadOnly = function() { |
142 return this.readonly_; | 140 return this.isPathReadOnly(this.getCurrentRootPath()); |
143 }; | 141 }; |
144 | 142 |
145 /** | 143 /** |
146 * @return {boolean} If offline. | 144 * @param {strin} path Path to check. |
145 * @return {boolean} True if the |path| is read only. | |
147 */ | 146 */ |
148 DirectoryModel.prototype.isOffline = function() { | 147 DirectoryModel.prototype.isPathReadOnly = function(path) { |
149 return this.offline_; | 148 switch (DirectoryModel.getRootType(path)) { |
150 }; | 149 case DirectoryModel.RootType.REMOVABLE: |
151 | 150 return !!this.volumeReadOnlyStatus_[DirectoryModel.getRootPath(path)]; |
152 /** | 151 case DirectoryModel.RootType.ARCHIVE: |
153 * @param {boolean} value New online status. | 152 return true; |
154 */ | 153 case DirectoryModel.RootType.DOWNLOADS: |
155 DirectoryModel.prototype.setOffline = function(value) { | 154 return false; |
156 if (this.offline_ != value) { | 155 case DirectoryModel.RootType.GDATA: |
157 this.offline_ = !!value; | 156 return !navigator.onLine; |
158 this.updateReadonlyStatus_(); | 157 default: |
158 return true; | |
159 } | 159 } |
160 }; | 160 }; |
161 | 161 |
162 /** | 162 /** |
163 * @return {boolean} If current directory is system. | 163 * @return {boolean} If current directory is system. |
164 */ | 164 */ |
165 DirectoryModel.prototype.isSystemDirectory = function() { | 165 DirectoryModel.prototype.isSystemDirectory = function() { |
166 var path = this.currentDirEntry_.fullPath; | 166 var path = this.currentDirEntry_.fullPath; |
167 return path == '/' || | 167 return path == '/' || |
168 path == '/' + DirectoryModel.REMOVABLE_DIRECTORY || | 168 path == '/' + DirectoryModel.REMOVABLE_DIRECTORY || |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
701 DirectoryModel.prototype.changeDirectoryEntry_ = function(dirEntry, action, | 701 DirectoryModel.prototype.changeDirectoryEntry_ = function(dirEntry, action, |
702 initial) { | 702 initial) { |
703 var previous = this.currentDirEntry_; | 703 var previous = this.currentDirEntry_; |
704 this.currentDirEntry_ = dirEntry; | 704 this.currentDirEntry_ = dirEntry; |
705 function onRescanComplete() { | 705 function onRescanComplete() { |
706 action(); | 706 action(); |
707 // For tests that open the dialog to empty directories, everything | 707 // For tests that open the dialog to empty directories, everything |
708 // is loaded at this point. | 708 // is loaded at this point. |
709 chrome.test.sendMessage('directory-change-complete'); | 709 chrome.test.sendMessage('directory-change-complete'); |
710 } | 710 } |
711 this.updateReadonlyStatus_(); | |
712 this.updateVolumeMetadata_(); | |
713 this.updateRootsListSelection_(); | 711 this.updateRootsListSelection_(); |
714 this.scan_(onRescanComplete); | 712 this.scan_(onRescanComplete); |
715 this.currentDirByRoot_[this.getCurrentRootPath()] = dirEntry.fullPath; | 713 this.currentDirByRoot_[this.getCurrentRootPath()] = dirEntry.fullPath; |
716 | 714 |
717 var e = new cr.Event('directory-changed'); | 715 var e = new cr.Event('directory-changed'); |
718 e.previousDirEntry = previous; | 716 e.previousDirEntry = previous; |
719 e.newDirEntry = dirEntry; | 717 e.newDirEntry = dirEntry; |
720 e.initial = initial; | 718 e.initial = initial; |
721 this.dispatchEvent(e); | 719 this.dispatchEvent(e); |
722 }; | 720 }; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
908 * @param {function(Array.<Entry>)} callback Called when roots are resolved. | 906 * @param {function(Array.<Entry>)} callback Called when roots are resolved. |
909 * @param {boolean} resolveGData See comment for updateRoots. | 907 * @param {boolean} resolveGData See comment for updateRoots. |
910 */ | 908 */ |
911 DirectoryModel.prototype.resolveRoots_ = function(callback, resolveGData) { | 909 DirectoryModel.prototype.resolveRoots_ = function(callback, resolveGData) { |
912 var groups = { | 910 var groups = { |
913 downloads: null, | 911 downloads: null, |
914 archives: null, | 912 archives: null, |
915 removables: null, | 913 removables: null, |
916 gdata: null | 914 gdata: null |
917 }; | 915 }; |
916 var self = this; | |
918 | 917 |
919 metrics.startInterval('Load.Roots'); | 918 metrics.startInterval('Load.Roots'); |
920 function done() { | 919 function done() { |
921 for (var i in groups) | 920 for (var i in groups) |
922 if (!groups[i]) | 921 if (!groups[i]) |
923 return; | 922 return; |
924 | 923 |
924 self.updateVolumeReadOnlyStatus_(groups.removables); | |
925 callback(groups.downloads. | 925 callback(groups.downloads. |
926 concat(groups.gdata). | 926 concat(groups.gdata). |
927 concat(groups.archives). | 927 concat(groups.archives). |
928 concat(groups.removables)); | 928 concat(groups.removables)); |
929 metrics.recordInterval('Load.Roots'); | 929 metrics.recordInterval('Load.Roots'); |
930 } | 930 } |
931 | 931 |
932 function append(index, values, opt_error) { | 932 function append(index, values, opt_error) { |
933 groups[index] = values; | 933 groups[index] = values; |
934 done(); | 934 done(); |
935 } | 935 } |
936 | 936 |
937 function onDownloads(entry) { | 937 function onDownloads(entry) { |
938 groups.downloads = [entry]; | 938 groups.downloads = [entry]; |
939 done(); | 939 done(); |
940 } | 940 } |
941 | 941 |
942 function onDownloadsError(error) { | 942 function onDownloadsError(error) { |
943 groups.downloads = []; | 943 groups.downloads = []; |
944 done(); | 944 done(); |
945 } | 945 } |
946 | 946 |
947 var self = this; | |
948 | |
949 function onGData(entry) { | 947 function onGData(entry) { |
950 console.log('GData found:', entry); | 948 console.log('GData found:', entry); |
951 self.unmountedGDataEntry_ = null; | 949 self.unmountedGDataEntry_ = null; |
952 groups.gdata = [entry]; | 950 groups.gdata = [entry]; |
953 done(); | 951 done(); |
954 } | 952 } |
955 | 953 |
956 function onGDataError(error) { | 954 function onGDataError(error) { |
957 console.log('GData error: ', error); | 955 console.log('GData error: ', error); |
958 self.unmountedGDataEntry_ = { | 956 self.unmountedGDataEntry_ = { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1037 | 1035 |
1038 /** | 1036 /** |
1039 * @private | 1037 * @private |
1040 */ | 1038 */ |
1041 DirectoryModel.prototype.updateRootsListSelection_ = function() { | 1039 DirectoryModel.prototype.updateRootsListSelection_ = function() { |
1042 var rootPath = DirectoryModel.getRootPath(this.currentDirEntry_.fullPath); | 1040 var rootPath = DirectoryModel.getRootPath(this.currentDirEntry_.fullPath); |
1043 this.rootsListSelection_.selectedIndex = this.findRootsListItem_(rootPath); | 1041 this.rootsListSelection_.selectedIndex = this.findRootsListItem_(rootPath); |
1044 }; | 1042 }; |
1045 | 1043 |
1046 /** | 1044 /** |
1045 * @param {Array.<DirectoryEntry>} roots Removable volumes entries. | |
1047 * @private | 1046 * @private |
1048 */ | 1047 */ |
1049 DirectoryModel.prototype.updateReadonlyStatus_ = function() { | 1048 DirectoryModel.prototype.updateVolumeReadOnlyStatus_ = function(roots) { |
1050 switch (this.getRootType()) { | 1049 var status = this.volumeReadOnlyStatus_ = {}; |
1051 case DirectoryModel.RootType.REMOVABLE: | 1050 for (var i = 0; i < roots.length; i++) { |
1052 this.readonly_ = !!this.currentVolumeMetadata_.isReadOnly; | 1051 status[roots[i].fullPath] = false; |
Vladislav Kaznacheev
2012/04/25 11:08:04
How about setting 'true' originally?
SeRya
2012/04/25 11:50:53
I would vote for 'false' because:
1. It better wor
| |
1053 break; | 1052 chrome.fileBrowserPrivate.getVolumeMetadata(roots[i].toURL(), |
1054 case DirectoryModel.RootType.ARCHIVE: | 1053 function(systemMetadata, path) { |
1055 this.readonly_ = true; | 1054 status[path] = !!(systemMetadata && systemMetadata.isReadOnly); |
1056 break; | 1055 }.bind(null, roots[i].fullPath)); |
1057 case DirectoryModel.RootType.DOWNLOADS: | |
1058 this.readonly_ = false; | |
1059 break; | |
1060 case DirectoryModel.RootType.GDATA: | |
1061 this.readonly_ = this.offline_; | |
1062 break; | |
1063 default: | |
1064 this.readonly_ = true; | |
1065 break; | |
1066 } | 1056 } |
1067 }; | 1057 }; |
1068 | 1058 |
1069 /** | |
1070 * @private | |
1071 */ | |
1072 DirectoryModel.prototype.updateVolumeMetadata_ = function() { | |
1073 var rootPath = this.getCurrentRootPath(); | |
1074 if (this.currentVolumeMetadata_.rootPath != rootPath) { | |
1075 var metadata = this.currentVolumeMetadata_ = {rootPath: rootPath}; | |
1076 if (DirectoryModel.getRootType(rootPath) == | |
1077 DirectoryModel.RootType.REMOVABLE) { | |
1078 var self = this; | |
1079 this.root_.getDirectory(rootPath, {}, function(entry) { | |
1080 chrome.fileBrowserPrivate.getVolumeMetadata(entry.toURL(), | |
1081 function(systemMetadata) { | |
1082 if (systemMetadata) { | |
1083 metadata.isReadOnly = systemMetadata.isReadOnly; | |
1084 self.updateReadonlyStatus_(); | |
1085 } | |
1086 }); | |
1087 }); | |
1088 } | |
1089 } | |
1090 }; | |
1091 | |
1092 /** | 1059 /** |
1093 * Prepare the root for the unmount. | 1060 * Prepare the root for the unmount. |
1094 * | 1061 * |
1095 * @param {string} rootPath The path to the root. | 1062 * @param {string} rootPath The path to the root. |
1096 */ | 1063 */ |
1097 DirectoryModel.prototype.prepareUnmount = function(rootPath) { | 1064 DirectoryModel.prototype.prepareUnmount = function(rootPath) { |
1098 var index = this.findRootsListItem_(rootPath); | 1065 var index = this.findRootsListItem_(rootPath); |
1099 if (index == -1) { | 1066 if (index == -1) { |
1100 console.error('Unknown root entry', rootPath); | 1067 console.error('Unknown root entry', rootPath); |
1101 return; | 1068 return; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1270 /** | 1237 /** |
1271 * @private | 1238 * @private |
1272 */ | 1239 */ |
1273 DirectoryModel.Scanner.prototype.recordMetrics_ = function() { | 1240 DirectoryModel.Scanner.prototype.recordMetrics_ = function() { |
1274 metrics.recordInterval('DirectoryScan'); | 1241 metrics.recordInterval('DirectoryScan'); |
1275 if (this.dir_.fullPath == | 1242 if (this.dir_.fullPath == |
1276 '/' + DirectoryModel.DOWNLOADS_DIRECTORY) { | 1243 '/' + DirectoryModel.DOWNLOADS_DIRECTORY) { |
1277 metrics.recordMediumCount('DownloadsCount', this.list_.length); | 1244 metrics.recordMediumCount('DownloadsCount', this.list_.length); |
1278 } | 1245 } |
1279 }; | 1246 }; |
OLD | NEW |