Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: ui/file_manager/file_manager/foreground/js/scan_controller.js

Issue 1222563005: Implement refreshing logic in Files app. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 /** 5 /**
6 * Handler for scan related events of DirectoryModel. 6 * Handler for scan related events of DirectoryModel.
7 * 7 *
8 * @param {!DirectoryModel} directoryModel 8 * @param {!DirectoryModel} directoryModel
9 * @param {!ListContainer} listContainer 9 * @param {!ListContainer} listContainer
10 * @param {!SpinnerController} spinnerController 10 * @param {!SpinnerController} spinnerController
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 if (this.scanCompletedTimer_) { 126 if (this.scanCompletedTimer_) {
127 clearTimeout(this.scanCompletedTimer_); 127 clearTimeout(this.scanCompletedTimer_);
128 this.scanCompletedTimer_ = 0; 128 this.scanCompletedTimer_ = 0;
129 } 129 }
130 130
131 if (this.scanUpdatedTimer_) { 131 if (this.scanUpdatedTimer_) {
132 clearTimeout(this.scanUpdatedTimer_); 132 clearTimeout(this.scanUpdatedTimer_);
133 this.scanUpdatedTimer_ = 0; 133 this.scanUpdatedTimer_ = 0;
134 } 134 }
135 135
136 this.spinnerController_.showLater(); 136 if (this.directoryModel_.isScanning())
137 this.spinnerController_.showLater();
137 }; 138 };
138 139
139 /** 140 /**
140 * @private 141 * @private
141 */ 142 */
142 ScanController.prototype.onScanCompleted_ = function() { 143 ScanController.prototype.onScanCompleted_ = function() {
143 if (!this.scanInProgress_) { 144 if (!this.scanInProgress_) {
144 console.error('Scan-completed event recieved. But scan is not started.'); 145 console.error('Scan-completed event recieved. But scan is not started.');
145 return; 146 return;
146 } 147 }
147 148
148 if (this.commandHandler_) 149 if (this.commandHandler_)
149 this.commandHandler_.updateAvailability(); 150 this.commandHandler_.updateAvailability();
150 this.spinnerController_.hide(); 151 this.hideSpinner_();
151 152
152 if (this.scanUpdatedTimer_) { 153 if (this.scanUpdatedTimer_) {
153 clearTimeout(this.scanUpdatedTimer_); 154 clearTimeout(this.scanUpdatedTimer_);
154 this.scanUpdatedTimer_ = 0; 155 this.scanUpdatedTimer_ = 0;
155 } 156 }
156 157
157 // To avoid flickering postpone updating the ui by a small amount of time. 158 // To avoid flickering postpone updating the ui by a small amount of time.
158 // There is a high chance, that metadata will be received within 50 ms. 159 // There is a high chance, that metadata will be received within 50 ms.
159 this.scanCompletedTimer_ = setTimeout(function() { 160 this.scanCompletedTimer_ = setTimeout(function() {
160 // Check if batch updates are already finished by onScanUpdated_(). 161 // Check if batch updates are already finished by onScanUpdated_().
(...skipping 18 matching lines...) Expand all
179 180
180 if (this.scanUpdatedTimer_ || this.scanCompletedTimer_) 181 if (this.scanUpdatedTimer_ || this.scanCompletedTimer_)
181 return; 182 return;
182 183
183 // Show contents incrementally by finishing batch updated, but only after 184 // Show contents incrementally by finishing batch updated, but only after
184 // 200ms elapsed, to avoid flickering when it is not necessary. 185 // 200ms elapsed, to avoid flickering when it is not necessary.
185 this.scanUpdatedTimer_ = setTimeout(function() { 186 this.scanUpdatedTimer_ = setTimeout(function() {
186 // We need to hide the spinner only once. 187 // We need to hide the spinner only once.
187 if (!this.scanUpdatedAtLeastOnceOrCompleted_) { 188 if (!this.scanUpdatedAtLeastOnceOrCompleted_) {
188 this.scanUpdatedAtLeastOnceOrCompleted_ = true; 189 this.scanUpdatedAtLeastOnceOrCompleted_ = true;
189 this.spinnerController_.hide(); 190 this.hideSpinner_();
190 } 191 }
191 192
192 // Update the UI. 193 // Update the UI.
193 if (this.scanInProgress_) { 194 if (this.scanInProgress_) {
194 this.listContainer_.endBatchUpdates(); 195 this.listContainer_.endBatchUpdates();
195 this.listContainer_.startBatchUpdates(); 196 this.listContainer_.startBatchUpdates();
196 } 197 }
197 this.scanUpdatedTimer_ = 0; 198 this.scanUpdatedTimer_ = 0;
198 }.bind(this), 200); 199 }.bind(this), 200);
199 }; 200 };
200 201
201 /** 202 /**
202 * @private 203 * @private
203 */ 204 */
204 ScanController.prototype.onScanCancelled_ = function() { 205 ScanController.prototype.onScanCancelled_ = function() {
205 if (!this.scanInProgress_) { 206 if (!this.scanInProgress_) {
206 console.error('Scan-cancelled event recieved. But scan is not started.'); 207 console.error('Scan-cancelled event recieved. But scan is not started.');
207 return; 208 return;
208 } 209 }
209 210
210 if (this.commandHandler_) 211 if (this.commandHandler_)
211 this.commandHandler_.updateAvailability(); 212 this.commandHandler_.updateAvailability();
212 this.spinnerController_.hide(); 213 this.hideSpinner_();
213 if (this.scanCompletedTimer_) { 214 if (this.scanCompletedTimer_) {
214 clearTimeout(this.scanCompletedTimer_); 215 clearTimeout(this.scanCompletedTimer_);
215 this.scanCompletedTimer_ = 0; 216 this.scanCompletedTimer_ = 0;
216 } 217 }
217 if (this.scanUpdatedTimer_) { 218 if (this.scanUpdatedTimer_) {
218 clearTimeout(this.scanUpdatedTimer_); 219 clearTimeout(this.scanUpdatedTimer_);
219 this.scanUpdatedTimer_ = 0; 220 this.scanUpdatedTimer_ = 0;
220 } 221 }
221 // Finish unfinished batch updates. 222 // Finish unfinished batch updates.
222 if (!this.scanUpdatedAtLeastOnceOrCompleted_) { 223 if (!this.scanUpdatedAtLeastOnceOrCompleted_) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 /** 256 /**
256 * When a spinner is shown, updates the UI to remove items in the previous 257 * When a spinner is shown, updates the UI to remove items in the previous
257 * directory. 258 * directory.
258 */ 259 */
259 ScanController.prototype.onSpinnerShown_ = function() { 260 ScanController.prototype.onSpinnerShown_ = function() {
260 if (this.scanInProgress_) { 261 if (this.scanInProgress_) {
261 this.listContainer_.endBatchUpdates(); 262 this.listContainer_.endBatchUpdates();
262 this.listContainer_.startBatchUpdates(); 263 this.listContainer_.startBatchUpdates();
263 } 264 }
264 }; 265 };
266
267 /**
268 * @private
269 */
270 ScanController.prototype.hideSpinner_ = function() {
hirono 2015/07/06 09:39:27 Is the method still needed? The hide method no lon
mtomasz 2015/07/07 03:42:11 It's used if there is no blinking spinner shown. T
hirono 2015/07/07 03:58:22 I just noticed the method originally came from Spi
mtomasz 2015/07/07 04:01:48 Ah, got it. Yes, I moved the scanning logic from s
271 if (this.directoryModel_.isScanning() &&
272 this.directoryModel_.getFileList().length == 0) {
273 return;
274 }
275 this.spinnerController_.hide();
276 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698