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 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 * name search over current directory wil be performed. | 1125 * name search over current directory wil be performed. |
1126 * | 1126 * |
1127 * @param {string} query Query that will be searched for. | 1127 * @param {string} query Query that will be searched for. |
1128 * @param {function} onSearchRescan Function that will be called when the search | 1128 * @param {function} onSearchRescan Function that will be called when the search |
1129 * directory is rescanned (i.e. search results are displayed) | 1129 * directory is rescanned (i.e. search results are displayed) |
1130 * @param {function} onClearSearch Function to be called when search state gets | 1130 * @param {function} onClearSearch Function to be called when search state gets |
1131 * cleared. | 1131 * cleared. |
1132 * TODO(olege): Change callbacks to events. | 1132 * TODO(olege): Change callbacks to events. |
1133 */ | 1133 */ |
1134 DirectoryModel.prototype.search = function(query, | 1134 DirectoryModel.prototype.search = function(query, |
1135 onSearchRescan, | 1135 onSearchRescan, |
1136 onClearSearch) { | 1136 onClearSearch) { |
1137 query = query.trimLeft(); | 1137 query = query.trimLeft(); |
1138 | 1138 |
1139 var newDirContents; | 1139 var newDirContents; |
1140 if (!query) { | 1140 if (!query) { |
1141 if (this.isSearching()) { | 1141 if (this.isSearching()) { |
1142 newDirContents = new DirectoryContentsBasic( | 1142 newDirContents = new DirectoryContentsBasic( |
1143 this.currentFileListContext_, | 1143 this.currentFileListContext_, |
1144 this.currentDirContents_.getDirectoryEntry()); | 1144 this.currentDirContents_.getDirectoryEntry()); |
1145 this.clearAndScan_(newDirContents); | 1145 this.clearAndScan_(newDirContents); |
1146 this.clearSearch_(); | 1146 this.clearSearch_(); |
1147 } | 1147 } |
1148 return; | 1148 return; |
1149 } | 1149 } |
1150 | 1150 |
1151 // If we already have event listener for an old search, we have to remove it. | 1151 // If we already have event listener for an old search, we have to remove it. |
1152 if (this.onSearchRescan_) | 1152 if (this.onSearchCompleted_) |
1153 this.removeEventListener('rescan-completed', this.onSearchRescan_); | 1153 this.removeEventListener('scan-completed', this.onSearchCompleted_); |
1154 | 1154 |
1155 this.onSearchRescan_ = onSearchRescan; | 1155 this.onSearchCompleted_ = onSearchRescan; |
1156 this.onClearSearch_ = onClearSearch; | 1156 this.onClearSearch_ = onClearSearch; |
1157 | 1157 |
1158 this.addEventListener('rescan-completed', this.onSearchRescan_); | 1158 this.addEventListener('scan-completed', this.onSearchCompleted_); |
1159 | 1159 |
1160 // If we are offline, let's fallback to file name search inside dir. | 1160 // If we are offline, let's fallback to file name search inside dir. |
1161 if (this.getCurrentRootType() === RootType.GDATA && !this.isOffline()) { | 1161 if (this.getCurrentRootType() === RootType.GDATA && !this.isOffline()) { |
1162 newDirContents = new DirectoryContentsGDataSearch( | 1162 newDirContents = new DirectoryContentsGDataSearch( |
1163 this.currentFileListContext_, this.getCurrentDirEntry(), query); | 1163 this.currentFileListContext_, this.getCurrentDirEntry(), query); |
1164 } else { | 1164 } else { |
1165 newDirContents = new DirectoryContentsLocalSearch( | 1165 newDirContents = new DirectoryContentsLocalSearch( |
1166 this.currentFileListContext_, this.getCurrentDirEntry(), query); | 1166 this.currentFileListContext_, this.getCurrentDirEntry(), query); |
1167 } | 1167 } |
1168 this.clearAndScan_(newDirContents); | 1168 this.clearAndScan_(newDirContents); |
1169 }; | 1169 }; |
1170 | 1170 |
1171 | 1171 |
1172 /** | 1172 /** |
1173 * In case the search was active, remove listeners and send notifications on | 1173 * In case the search was active, remove listeners and send notifications on |
1174 * its canceling. | 1174 * its canceling. |
1175 * @private | 1175 * @private |
1176 */ | 1176 */ |
1177 DirectoryModel.prototype.clearSearch_ = function() { | 1177 DirectoryModel.prototype.clearSearch_ = function() { |
1178 if (!this.isSearching()) | 1178 if (!this.isSearching()) |
1179 return; | 1179 return; |
1180 | 1180 |
1181 if (this.onSearchRescan_) { | 1181 if (this.onSearchCompleted_) { |
1182 this.removeEventListener('rescan-completed', this.onSearchRescan_); | 1182 this.removeEventListener('scan-completed', this.onSearchCompleted_); |
1183 this.onSearchRescan_ = null; | 1183 this.onSearchCompleted_ = null; |
1184 } | 1184 } |
1185 | 1185 |
1186 if (this.onClearSearch_) { | 1186 if (this.onClearSearch_) { |
1187 this.onClearSearch_(); | 1187 this.onClearSearch_(); |
1188 this.onClearSearch_ = null; | 1188 this.onClearSearch_ = null; |
1189 } | 1189 } |
1190 }; | 1190 }; |
1191 | 1191 |
1192 /** | 1192 /** |
1193 * @param {string} name Filter identifier. | 1193 * @param {string} name Filter identifier. |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1323 }.bind(this)); | 1323 }.bind(this)); |
1324 } | 1324 } |
1325 }; | 1325 }; |
1326 | 1326 |
1327 /** | 1327 /** |
1328 * @return {DirectoryEntry} Current watched directory entry. | 1328 * @return {DirectoryEntry} Current watched directory entry. |
1329 */ | 1329 */ |
1330 FileWatcher.prototype.getWatchedDirectoryEntry = function() { | 1330 FileWatcher.prototype.getWatchedDirectoryEntry = function() { |
1331 return this.watchedDirectoryEntry_; | 1331 return this.watchedDirectoryEntry_; |
1332 }; | 1332 }; |
OLD | NEW |