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

Unified Diff: ui/file_manager/file_manager/foreground/js/metadata_update_controller.js

Issue 921683003: Files.app: Update metadata by using new metadata cache event. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/file_manager/file_manager/foreground/js/file_manager.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/file_manager/file_manager/foreground/js/metadata_update_controller.js
diff --git a/ui/file_manager/file_manager/foreground/js/metadata_update_controller.js b/ui/file_manager/file_manager/foreground/js/metadata_update_controller.js
index b9df4851fa4ec0ecab1a07e485a80e5eb1c46d1a..67a32e2ff9673b21c7844a9763d743a85dd861e0 100644
--- a/ui/file_manager/file_manager/foreground/js/metadata_update_controller.js
+++ b/ui/file_manager/file_manager/foreground/js/metadata_update_controller.js
@@ -6,52 +6,38 @@
* Controller for list contents update.
* @param {!ListContainer} listContainer
* @param {!DirectoryModel} directoryModel
- * @param {!VolumeManagerWrapper} volumeManager
- * @param {!MetadataCache} metadataCache
- * @param {!FileWatcher} fileWatcher
- * @param {!FileOperationManager} fileOperationManager
+ * @param {!MetadataProviderCache} metadataProviderCache
+ * @param {!FileSystemMetadata} fileSystemMetadata
* @constructor
+ * @struct
*/
function MetadataUpdateController(listContainer,
directoryModel,
- volumeManager,
- metadataCache,
- fileWatcher,
- fileOperationManager) {
+ metadataProviderCache,
+ fileSystemMetadata) {
/**
- * @type {!DirectoryModel}
+ * @private {!DirectoryModel}
* @const
- * @private
*/
this.directoryModel_ = directoryModel;
/**
- * @type {!VolumeManagerWrapper}
+ * @private {!FileSystemMetadata}
* @const
- * @private
*/
- this.volumeManager_ = volumeManager;
+ this.fileSystemMetadata_ = fileSystemMetadata;
/**
- * @type {!MetadataCache}
+ * @private {!ListContainer}
* @const
- * @private
- */
- this.metadataCache_ = metadataCache;
-
- /**
- * @type {!ListContainer}
- * @const
- * @private
*/
this.listContainer_ = listContainer;
chrome.fileManagerPrivate.onPreferencesChanged.addListener(
this.onPreferencesChanged_.bind(this));
this.onPreferencesChanged_();
-
- fileWatcher.addEventListener(
- 'watcher-metadata-changed', this.onWatcherMetadataChanged_.bind(this));
+ metadataProviderCache.addEventListener(
+ 'update', this.onCachedMetadataUpdate_.bind(this));
// Update metadata to change 'Today' and 'Yesterday' dates.
var today = new Date();
@@ -79,30 +65,17 @@ MetadataUpdateController.prototype.refreshCurrentDirectoryMetadata =
var directoryEntry = this.directoryModel_.getCurrentDirEntry();
if (!directoryEntry)
return;
- // We don't pass callback here. When new metadata arrives, we have an
- // observer registered to update the UI.
// TODO(dgozman): refresh content metadata only when modificationTime
// changed.
var isFakeEntry = util.isFakeEntry(directoryEntry);
- var getEntries = (isFakeEntry ? [] : [directoryEntry]).concat(entries);
- if (!isFakeEntry)
- this.metadataCache_.clearRecursively(directoryEntry, '*');
- this.metadataCache_.get(getEntries, 'filesystem|external', null);
+ var changedEntries = (isFakeEntry ? [] : [directoryEntry]).concat(entries);
+ this.fileSystemMetadata_.notifyEntriesChanged(changedEntries);
- var visibleItems = this.listContainer_.currentList.items;
- var visibleEntries = [];
- for (var i = 0; i < visibleItems.length; i++) {
- var index = this.listContainer_.currentList.getIndexOfListItem(
- visibleItems[i]);
- var entry = this.directoryModel_.getFileList().item(index);
- // The following check is a workaround for the bug in list: sometimes item
- // does not have listIndex, and therefore is not found in the list.
- if (entry)
- visibleEntries.push(entry);
- }
- // Refreshes the metadata.
- this.metadataCache_.getLatest(visibleEntries, 'thumbnail', null);
+ // We don't pass callback here. When new metadata arrives, we have an
+ // observer registered to update the UI.
+ this.fileSystemMetadata_.get(
+ changedEntries, this.directoryModel_.getPrefetchPropertyNames());
};
/**
@@ -110,24 +83,24 @@ MetadataUpdateController.prototype.refreshCurrentDirectoryMetadata =
* @param {Event} event Change event.
* @private
*/
-MetadataUpdateController.prototype.onWatcherMetadataChanged_ = function(event) {
+MetadataUpdateController.prototype.onCachedMetadataUpdate_ = function(event) {
+ // TODO(hirono): Specify property name instead of metadata type.
this.listContainer_.currentView.updateListItemsMetadata(
- event.metadataType, event.entries);
+ 'filesystem', event.entries);
+ this.listContainer_.currentView.updateListItemsMetadata(
+ 'external', event.entries);
yawano 2015/02/17 03:26:46 onWatcherMetadataChanged_ can be called with metad
hirono 2015/02/17 07:28:25 The thumbnail change for list views is handled by
yawano 2015/02/17 07:42:08 Acknowledged.
};
/**
* @private
*/
MetadataUpdateController.prototype.dailyUpdateModificationTime_ = function() {
- var entries = this.directoryModel_.getFileList().slice();
- this.metadataCache_.get(
- entries,
- 'filesystem',
- function() {
- this.listContainer_.currentView.updateListItemsMetadata(
- 'filesystem', entries);
- }.bind(this));
-
+ var entries = /** @type {!Array<!Entry>} */(
+ this.directoryModel_.getFileList().slice());
+ this.fileSystemMetadata_.get(entries, ['modificationTime']).then(function() {
yawano 2015/02/17 03:26:46 We don't need to get modificationTime again to upd
hirono 2015/02/17 07:28:25 I'd like to avoid using getCache if we can. The re
yawano 2015/02/17 07:42:08 If we don't have the assumption (we don't require)
+ this.listContainer_.currentView.updateListItemsMetadata(
+ 'filesystem', entries);
+ }.bind(this));
setTimeout(this.dailyUpdateModificationTime_.bind(this),
MetadataUpdateController.MILLISECONDS_IN_DAY_);
};
@@ -142,47 +115,3 @@ MetadataUpdateController.prototype.onPreferencesChanged_ = function() {
this.refreshCurrentDirectoryMetadata();
}.bind(this));
};
-
-/**
- * Handler of file manager operations. Called when an entry has been
- * changed.
- * This updates directory model to reflect operation result immediately (not
- * waiting for directory update event). Also, preloads thumbnails for the
- * images of new entries.
- * See also fileOperationUtil.EventRouter.
- *
- * @param {Event} event An event for the entry change.
- * @private
- */
-MetadataUpdateController.prototype.onEntriesChanged_ = function(event) {
- var kind = event.kind;
- var entries = event.entries;
- if (kind !== util.EntryChangedKind.CREATED)
- return;
-
- var preloadThumbnail = function(entry) {
- var locationInfo = this.volumeManager_.getLocationInfo(entry);
- if (!locationInfo)
- return;
- this.metadataCache_.getOne(entry, 'thumbnail|external',
- function(metadata) {
- var thumbnailLoader = new ThumbnailLoader(
- entry,
- ThumbnailLoader.LoaderType.CANVAS,
- metadata,
- undefined, // Media type.
- [
- ThumbnailLoader.LoadTarget.EXTERNAL_METADATA,
- ThumbnailLoader.LoadTarget.FILE_ENTRY
- ],
- 10); // Very low priority.
- thumbnailLoader.loadDetachedImage(function(success) {});
- });
- }.bind(this);
-
- for (var i = 0; i < entries.length; i++) {
- // Preload a thumbnail if the new copied entry an image.
- if (FileType.isImage(entries[i]))
- preloadThumbnail(entries[i]);
- }
-};
« no previous file with comments | « ui/file_manager/file_manager/foreground/js/file_manager.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698