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 directory files changes too often, don't rescan directory more than once | 7 // If directory files changes too often, don't rescan directory more than once |
8 // per specified interval | 8 // per specified interval |
9 var SIMULTANEOUS_RESCAN_INTERVAL = 1000; | 9 var SIMULTANEOUS_RESCAN_INTERVAL = 1000; |
10 // Used for operations that require almost instant rescan. | 10 // Used for operations that require almost instant rescan. |
(...skipping 23 matching lines...) Expand all Loading... |
34 this.rescanTime_ = null; | 34 this.rescanTime_ = null; |
35 this.scanFailures_ = 0; | 35 this.scanFailures_ = 0; |
36 this.showSpecialSearchRoots_ = showSpecialSearchRoots; | 36 this.showSpecialSearchRoots_ = showSpecialSearchRoots; |
37 | 37 |
38 this.fileFilter_ = fileFilter; | 38 this.fileFilter_ = fileFilter; |
39 this.fileFilter_.addEventListener('changed', | 39 this.fileFilter_.addEventListener('changed', |
40 this.onFilterChanged_.bind(this)); | 40 this.onFilterChanged_.bind(this)); |
41 | 41 |
42 this.currentFileListContext_ = new FileListContext( | 42 this.currentFileListContext_ = new FileListContext( |
43 fileFilter, metadataCache); | 43 fileFilter, metadataCache); |
44 this.currentDirContents_ = new DirectoryContentsBasic( | 44 this.currentDirContents_ = |
45 this.currentFileListContext_, null); | 45 DirectoryContents.createForDirectory(this.currentFileListContext_, null); |
46 | 46 |
47 this.volumeManager_ = volumeManager; | 47 this.volumeManager_ = volumeManager; |
48 this.volumeManager_.volumeInfoList.addEventListener( | 48 this.volumeManager_.volumeInfoList.addEventListener( |
49 'splice', this.onVolumeInfoListUpdated_.bind(this)); | 49 'splice', this.onVolumeInfoListUpdated_.bind(this)); |
50 | 50 |
51 this.fileWatcher_ = fileWatcher; | 51 this.fileWatcher_ = fileWatcher; |
52 this.fileWatcher_.addEventListener( | 52 this.fileWatcher_.addEventListener( |
53 'watcher-directory-changed', | 53 'watcher-directory-changed', |
54 this.onWatcherDirectoryChanged_.bind(this)); | 54 this.onWatcherDirectoryChanged_.bind(this)); |
55 } | 55 } |
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 */ | 834 */ |
835 DirectoryModel.prototype.changeDirectoryEntrySilent_ = function(dirEntry, | 835 DirectoryModel.prototype.changeDirectoryEntrySilent_ = function(dirEntry, |
836 opt_callback) { | 836 opt_callback) { |
837 var onScanComplete = function() { | 837 var onScanComplete = function() { |
838 if (opt_callback) | 838 if (opt_callback) |
839 opt_callback(); | 839 opt_callback(); |
840 // For tests that open the dialog to empty directories, everything | 840 // For tests that open the dialog to empty directories, everything |
841 // is loaded at this point. | 841 // is loaded at this point. |
842 chrome.test.sendMessage('directory-change-complete'); | 842 chrome.test.sendMessage('directory-change-complete'); |
843 }; | 843 }; |
844 this.clearAndScan_(new DirectoryContentsBasic(this.currentFileListContext_, | 844 this.clearAndScan_( |
845 dirEntry), | 845 DirectoryContents.createForDirectory(this.currentFileListContext_, |
846 onScanComplete.bind(this)); | 846 dirEntry), |
| 847 onScanComplete.bind(this)); |
847 }; | 848 }; |
848 | 849 |
849 /** | 850 /** |
850 * Change the current directory to the directory represented by a | 851 * Change the current directory to the directory represented by a |
851 * DirectoryEntry. | 852 * DirectoryEntry. |
852 * | 853 * |
853 * Dispatches the 'directory-changed' event when the directory is successfully | 854 * Dispatches the 'directory-changed' event when the directory is successfully |
854 * changed. | 855 * changed. |
855 * | 856 * |
856 * @param {DirectoryEntry} dirEntry The absolute path to the new directory. | 857 * @param {DirectoryEntry} dirEntry The absolute path to the new directory. |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1132 this.clearSearch_(); | 1133 this.clearSearch_(); |
1133 | 1134 |
1134 var currentDirEntry = this.getCurrentDirEntry(); | 1135 var currentDirEntry = this.getCurrentDirEntry(); |
1135 if (!currentDirEntry) { | 1136 if (!currentDirEntry) { |
1136 // Not yet initialized. Do nothing. | 1137 // Not yet initialized. Do nothing. |
1137 return; | 1138 return; |
1138 } | 1139 } |
1139 | 1140 |
1140 if (!query) { | 1141 if (!query) { |
1141 if (this.isSearching()) { | 1142 if (this.isSearching()) { |
1142 var newDirContents = new DirectoryContentsBasic( | 1143 var newDirContents = DirectoryContents.createForDirectory( |
1143 this.currentFileListContext_, | 1144 this.currentFileListContext_, |
1144 this.currentDirContents_.getLastNonSearchDirectoryEntry()); | 1145 this.currentDirContents_.getLastNonSearchDirectoryEntry()); |
1145 this.clearAndScan_(newDirContents); | 1146 this.clearAndScan_(newDirContents); |
1146 } | 1147 } |
1147 return; | 1148 return; |
1148 } | 1149 } |
1149 | 1150 |
1150 this.onSearchCompleted_ = onSearchRescan; | 1151 this.onSearchCompleted_ = onSearchRescan; |
1151 this.onClearSearch_ = onClearSearch; | 1152 this.onClearSearch_ = onClearSearch; |
1152 | 1153 |
1153 this.addEventListener('scan-completed', this.onSearchCompleted_); | 1154 this.addEventListener('scan-completed', this.onSearchCompleted_); |
1154 | 1155 |
1155 // If we are offline, let's fallback to file name search inside dir. | 1156 // If we are offline, let's fallback to file name search inside dir. |
1156 // A search initiated from directories in Drive or special search results | 1157 // A search initiated from directories in Drive or special search results |
1157 // should trigger Drive search. | 1158 // should trigger Drive search. |
1158 var newDirContents; | 1159 var newDirContents; |
1159 if (!this.isDriveOffline() && | 1160 if (!this.isDriveOffline() && |
1160 PathUtil.isDriveBasedPath(currentDirEntry.fullPath)) { | 1161 PathUtil.isDriveBasedPath(currentDirEntry.fullPath)) { |
1161 // Drive search is performed over the whole drive, so pass drive root as | 1162 // Drive search is performed over the whole drive, so pass drive root as |
1162 // |directoryEntry|. | 1163 // |directoryEntry|. |
1163 newDirContents = new DirectoryContentsDriveSearch( | 1164 newDirContents = DirectoryContents.createForDriveSearch( |
1164 this.currentFileListContext_, | 1165 this.currentFileListContext_, |
1165 currentDirEntry, | 1166 currentDirEntry, |
1166 this.currentDirContents_.getLastNonSearchDirectoryEntry(), | 1167 this.currentDirContents_.getLastNonSearchDirectoryEntry(), |
1167 query); | 1168 query); |
1168 } else { | 1169 } else { |
1169 newDirContents = new DirectoryContentsLocalSearch( | 1170 newDirContents = DirectoryContents.createForLocalSearch( |
1170 this.currentFileListContext_, currentDirEntry, query); | 1171 this.currentFileListContext_, currentDirEntry, query); |
1171 } | 1172 } |
1172 this.clearAndScan_(newDirContents); | 1173 this.clearAndScan_(newDirContents); |
1173 }; | 1174 }; |
1174 | 1175 |
1175 /** | 1176 /** |
1176 * Performs special search and displays results. e.g. Drive files available | 1177 * Performs special search and displays results. e.g. Drive files available |
1177 * offline, shared-with-me files, recently modified files. | 1178 * offline, shared-with-me files, recently modified files. |
1178 * @param {string} path Path string representing special search. See fake | 1179 * @param {string} path Path string representing special search. See fake |
1179 * entries in PathUtil.RootDirectory. | 1180 * entries in PathUtil.RootDirectory. |
(...skipping 29 matching lines...) Expand all Loading... |
1209 dirEntry = DirectoryModel.fakeDriveRecentEntry_; | 1210 dirEntry = DirectoryModel.fakeDriveRecentEntry_; |
1210 searchOption = | 1211 searchOption = |
1211 DriveMetadataSearchContentScanner.SearchType.SEARCH_RECENT_FILES; | 1212 DriveMetadataSearchContentScanner.SearchType.SEARCH_RECENT_FILES; |
1212 | 1213 |
1213 } else { | 1214 } else { |
1214 // Unknown path. | 1215 // Unknown path. |
1215 this.changeDirectory(PathUtil.DEFAULT_DIRECTORY); | 1216 this.changeDirectory(PathUtil.DEFAULT_DIRECTORY); |
1216 return; | 1217 return; |
1217 } | 1218 } |
1218 | 1219 |
1219 var newDirContents = new DirectoryContentsDriveSearchMetadata( | 1220 var newDirContents = DirectoryContents.createForDriveMetadataSearch( |
1220 this.currentFileListContext_, | 1221 this.currentFileListContext_, |
1221 driveRoot, | 1222 dirEntry, driveRoot, query, searchOption); |
1222 dirEntry, | |
1223 query, | |
1224 searchOption); | |
1225 var previous = this.currentDirContents_.getDirectoryEntry(); | 1223 var previous = this.currentDirContents_.getDirectoryEntry(); |
1226 this.clearAndScan_(newDirContents); | 1224 this.clearAndScan_(newDirContents); |
1227 | 1225 |
1228 var e = new cr.Event('directory-changed'); | 1226 var e = new cr.Event('directory-changed'); |
1229 e.previousDirEntry = previous; | 1227 e.previousDirEntry = previous; |
1230 e.newDirEntry = dirEntry; | 1228 e.newDirEntry = dirEntry; |
1231 this.dispatchEvent(e); | 1229 this.dispatchEvent(e); |
1232 }.bind(this); | 1230 }.bind(this); |
1233 | 1231 |
1234 this.resolveDirectory(DirectoryModel.fakeDriveEntry_.fullPath, | 1232 this.resolveDirectory(DirectoryModel.fakeDriveEntry_.fullPath, |
(...skipping 13 matching lines...) Expand all Loading... |
1248 if (this.onSearchCompleted_) { | 1246 if (this.onSearchCompleted_) { |
1249 this.removeEventListener('scan-completed', this.onSearchCompleted_); | 1247 this.removeEventListener('scan-completed', this.onSearchCompleted_); |
1250 this.onSearchCompleted_ = null; | 1248 this.onSearchCompleted_ = null; |
1251 } | 1249 } |
1252 | 1250 |
1253 if (this.onClearSearch_) { | 1251 if (this.onClearSearch_) { |
1254 this.onClearSearch_(); | 1252 this.onClearSearch_(); |
1255 this.onClearSearch_ = null; | 1253 this.onClearSearch_ = null; |
1256 } | 1254 } |
1257 }; | 1255 }; |
OLD | NEW |