Commit 57c88499 authored by kenobi's avatar kenobi Committed by Commit bot

Files.app: Tag cloud imported media files.

Tags media files that were uploaded via cloud import with a custom Drive property.

BUG=469774

Review URL: https://codereview.chromium.org/1032513002

Cr-Commit-Position: refs/heads/master@{#321853}
parent 9f2fdc07
......@@ -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);
......@@ -136,6 +146,37 @@ importer.MediaImportHandler.prototype.onTaskProgress_ =
this.progressCenter_.updateItem(item);
};
/**
* 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
......
......@@ -51,6 +51,9 @@ function setUp() {
releaseKeepAwake: function() {
chrome.power.requestKeepAwakeStatus = false;
}
},
fileManagerPrivate: {
setEntryTag: function() {}
}
};
......@@ -314,6 +317,52 @@ function testUpdatesHistoryAfterImport(callback) {
scanResult.finalize();
}
function testTagsEntriesAfterImport(callback) {
var entries = setupFileSystem([
'/DCIM/photos0/IMG00001.jpg',
'/DCIM/photos1/IMG00003.jpg'
]);
var scanResult = new TestScanResult(entries);
var importTask = mediaImporter.importFromScanResult(
scanResult,
importer.Destination.GOOGLE_DRIVE,
destinationFactory);
var whenImportDone = new Promise(
function(resolve, reject) {
importTask.addObserver(
/**
* @param {!importer.TaskQueue.UpdateType} updateType
* @param {!importer.TaskQueue.Task} task
*/
function(updateType, task) {
switch (updateType) {
case importer.TaskQueue.UpdateType.COMPLETE:
resolve();
break;
case importer.TaskQueue.UpdateType.ERROR:
reject(new Error(importer.TaskQueue.UpdateType.ERROR));
break;
}
});
});
var taggedUrls = [];
// Replace chrome.fileManagerPrivate.setEntryTag with a listener.
chrome.fileManagerPrivate.setEntryTag = function(url) {
taggedUrls.push(url);
};
reportPromise(
whenImportDone.then(
function() {
assertEquals(entries.length, taggedUrls.length);
}),
callback);
scanResult.finalize();
}
// Tests that cancelling an import works properly.
function testImportCancellation(callback) {
var media = setupFileSystem([
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment