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

Unified Diff: ui/file_manager/file_manager/background/js/media_import_handler.js

Issue 1032513002: Files.app: Tag cloud imported media files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback. Created 5 years, 9 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 | « no previous file | ui/file_manager/file_manager/background/js/media_import_handler_unittest.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/file_manager/file_manager/background/js/media_import_handler.js
diff --git a/ui/file_manager/file_manager/background/js/media_import_handler.js b/ui/file_manager/file_manager/background/js/media_import_handler.js
index a796cf5034723b492522690d61d4437b372a999c..9c54e23cc3857fabb16bf358aea5b917d3498271 100644
--- a/ui/file_manager/file_manager/background/js/media_import_handler.js
+++ b/ui/file_manager/file_manager/background/js/media_import_handler.js
@@ -59,6 +59,15 @@ importer.MediaImportHandler = function(progressCenter, historyLoader, tracker) {
this.nextTaskId_ = 0;
};
+// The name of the Drive property used to tag imported files. Used to look up
+// the property later.
+importer.MediaImportHandler.IMPORTS_TAG_KEY = 'cloud-import';
+
+// The value of the Drive property used to tag imported files. Cloud import
+// only imports 'media' right now - change this to an enum if other types of
+// files start being imported.
+importer.MediaImportHandler.IMPORTS_TAG_VALUE = 'media';
+
/** @override */
importer.MediaImportHandler.prototype.importFromScanResult =
function(scanResult, destination, directoryPromise) {
@@ -72,6 +81,7 @@ importer.MediaImportHandler.prototype.importFromScanResult =
this.tracker_);
task.addObserver(this.onTaskProgress_.bind(this, task));
+ task.addObserver(this.onFileImported_.bind(this, task));
this.queue_.queueTask(task);
@@ -137,6 +147,37 @@ importer.MediaImportHandler.prototype.onTaskProgress_ =
};
/**
+ * Tags newly-imported files with a Drive property.
+ * @param {!importer.TaskQueue.Task} task
+ * @param {string} updateType
+ * @param {Object=} updateInfo
+ */
+importer.MediaImportHandler.prototype.onFileImported_ =
+ function(task, updateType, updateInfo) {
+ if (updateType !==
+ importer.MediaImportHandler.ImportTask.UpdateType.ENTRY_CHANGED) {
+ return;
+ }
+ // Update info must exist for ENTRY_CHANGED notifications.
+ console.assert(updateInfo && updateInfo.destination);
+ /** @type {!importer.MediaImportHandler.ImportTask.EntryChangedInfo} */
+ var info = updateInfo;
+
+ // Tag the import with a private drive property.
+ chrome.fileManagerPrivate.setEntryTag(
+ info.destination.toURL(),
+ 'private', // Scoped to just this app.
+ importer.MediaImportHandler.IMPORTS_TAG_KEY,
+ importer.MediaImportHandler.IMPORTS_TAG_VALUE,
+ function() {
+ if (chrome.runtime.lastError) {
+ console.error('Unable to tag imported media: ' +
+ chrome.runtime.lastError.message);
+ }
+ });
+};
+
+/**
* Note that this isn't an actual FileOperationManager.Task. It currently uses
* the FileOperationManager (and thus *spawns* an associated
* FileOperationManager.CopyTask) but this is a temporary state of affairs.
« no previous file with comments | « no previous file | ui/file_manager/file_manager/background/js/media_import_handler_unittest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698