diff options
Diffstat (limited to 'ui')
3 files changed, 61 insertions, 8 deletions
diff --git a/ui/file_manager/file_manager/foreground/js/file_manager.js b/ui/file_manager/file_manager/foreground/js/file_manager.js index 36a0d3d..2ccc3b9 100644 --- a/ui/file_manager/file_manager/foreground/js/file_manager.js +++ b/ui/file_manager/file_manager/foreground/js/file_manager.js @@ -867,7 +867,7 @@ FileManager.prototype = /** @struct */ { this.initDirectoryTree_(); this.ui_.listContainer.listThumbnailLoader = new ListThumbnailLoader( - assert(this.directoryModel_.getFileList()), + this.directoryModel_, assert(this.thumbnailModel_), this.volumeManager_); this.ui_.listContainer.dataModel = this.directoryModel_.getFileList(); diff --git a/ui/file_manager/file_manager/foreground/js/list_thumbnail_loader.js b/ui/file_manager/file_manager/foreground/js/list_thumbnail_loader.js index 3184679..c09c769 100644 --- a/ui/file_manager/file_manager/foreground/js/list_thumbnail_loader.js +++ b/ui/file_manager/file_manager/foreground/js/list_thumbnail_loader.js @@ -10,7 +10,7 @@ * is responsible to return dataUrls of thumbnails and fetch them with proper * priority. * - * @param {!FileListModel} dataModel A file list model. + * @param {!DirectoryModel} directoryModel A directory model. * @param {!ThumbnailModel} thumbnailModel Thumbnail metadata model. * @param {!VolumeManagerWrapper} volumeManager Volume manager. * @param {Function=} opt_thumbnailLoaderConstructor A constructor of thumbnail @@ -21,11 +21,12 @@ * @suppress {checkStructDictInheritance} */ function ListThumbnailLoader( - dataModel, thumbnailModel, volumeManager, opt_thumbnailLoaderConstructor) { + directoryModel, thumbnailModel, volumeManager, + opt_thumbnailLoaderConstructor) { /** - * @private {!FileListModel} + * @private {!DirectoryModel} */ - this.dataModel_ = dataModel; + this.directoryModel_ = directoryModel; /** * @private {!ThumbnailModel} @@ -76,6 +77,13 @@ function ListThumbnailLoader( */ this.currentVolumeType_ = null; + /** + * @private {!FileListModel} + */ + this.dataModel_ = assert(this.directoryModel_.getFileList()); + + this.directoryModel_.addEventListener( + 'scan-completed', this.onScanCompleted_.bind(this)); this.dataModel_.addEventListener('splice', this.onSplice_.bind(this)); this.dataModel_.addEventListener('sorted', this.onSorted_.bind(this)); this.dataModel_.addEventListener('change', this.onChange_.bind(this)); @@ -144,6 +152,19 @@ ListThumbnailLoader.prototype.getNumOfMaxActiveTasks_ = function() { }; /** + * An event handler for scan-completed event of directory model. When directory + * scan is running, we don't fetch thumbnail in order not to block IO for + * directory scan. i.e. modification events during directory scan is ignored. + * We need to check thumbnail loadings after directory scan is completed. + * + * @param {!Event} event Event + */ +ListThumbnailLoader.prototype.onScanCompleted_ = function(event) { + this.cursor_ = this.beginIndex_; + this.continue_(); +}; + +/** * An event handler for splice event of data model. When list is changed, start * to rescan items. * @@ -216,8 +237,9 @@ ListThumbnailLoader.prototype.getThumbnailFromCache = function(entry) { * Enqueues tasks if available. */ ListThumbnailLoader.prototype.continue_ = function() { - // If all items are scanned, do nothing. - if (!(this.cursor_ < this.dataModel_.length)) + // If directory scan is running or all items are scanned, do nothing. + if (this.directoryModel_.isScanning() || + !(this.cursor_ < this.dataModel_.length)) return; var entry = /** @type {Entry} */ (this.dataModel_.item(this.cursor_)); diff --git a/ui/file_manager/file_manager/foreground/js/list_thumbnail_loader_unittest.js b/ui/file_manager/file_manager/foreground/js/list_thumbnail_loader_unittest.js index 6e2ea08..80ff510 100644 --- a/ui/file_manager/file_manager/foreground/js/list_thumbnail_loader_unittest.js +++ b/ui/file_manager/file_manager/foreground/js/list_thumbnail_loader_unittest.js @@ -45,7 +45,9 @@ var listThumbnailLoader; var getCallbacks; var thumbnailLoadedEvents; var fileListModel; +var directoryModel; var currentVolumeType; +var isScanningForTest = false; var fileSystem = new MockFileSystem('volume-id'); var directory1 = new MockDirectoryEntry(fileSystem, '/TestDirectory'); var entry1 = new MockEntry(fileSystem, '/Test1.jpg'); @@ -75,8 +77,18 @@ function setUp() { fileListModel = new FileListModel(thumbnailModel); + directoryModel = { + __proto__: cr.EventTarget.prototype, + getFileList: function() { + return fileListModel; + }, + isScanning: function() { + return isScanningForTest; + } + }; + listThumbnailLoader = new ListThumbnailLoader( - fileListModel, + directoryModel, thumbnailModel, // Mocking volume manager { @@ -337,3 +349,22 @@ function testMTPVolume() { // Only one request should be enqueued on MTP volume. assertEquals(1, Object.keys(getCallbacks).length); } + +/** + * Test case that directory scan is running. + */ +function testDirectoryScanIsRunning() { + // Items are added during directory scan. + isScanningForTest = true; + + listThumbnailLoader.setHighPriorityRange(0,2); + fileListModel.push(directory1, entry1, entry2); + assertEquals(0, Object.keys(getCallbacks).length); + + // Scan completed after adding the last item. + fileListModel.push(entry3); + isScanningForTest = false; + directoryModel.dispatchEvent(new Event('scan-completed')); + + assertEquals(2, Object.keys(getCallbacks).length); +} |