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

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

Issue 805533003: Hook up import history to media scanner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add import history test double. Created 6 years 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
Index: ui/file_manager/file_manager/background/js/media_scanner.js
diff --git a/ui/file_manager/file_manager/background/js/media_scanner.js b/ui/file_manager/file_manager/background/js/media_scanner.js
index 9c7e40fd596d852a83a6e5ce0aee6ec3b7e5ae1c..653a0b40e4a163925c2775617d0407e19110e9c5 100644
--- a/ui/file_manager/file_manager/background/js/media_scanner.js
+++ b/ui/file_manager/file_manager/background/js/media_scanner.js
@@ -63,8 +63,13 @@ importer.ScanResult.prototype.whenFinished;
* @constructor
* @struct
* @implements {importer.MediaScanner}
+ *
+ * @param {!Promise.<!importer.ImportHistory>} historyProvider
*/
-importer.DefaultMediaScanner = function() {};
+importer.DefaultMediaScanner = function(historyProvider) {
+ /** @private {!Promise.<!importer.ImportHistory>} */
+ this.historyProvider_ = historyProvider;
+};
/** @override */
importer.DefaultMediaScanner.prototype.scan = function(entries) {
@@ -72,12 +77,24 @@ importer.DefaultMediaScanner.prototype.scan = function(entries) {
throw new Error('Cannot scan empty list of entries.');
}
- var scanResult = new importer.DefaultScanResult();
+ var scanResult = new importer.DefaultScanResult(this.historyProvider_);
var scanPromises = entries.map(this.scanEntry_.bind(this, scanResult));
+
Promise.all(scanPromises)
.then(scanResult.resolveScan.bind(scanResult))
.catch(scanResult.rejectScan.bind(scanResult));
+ scanResult.whenFinished()
+ .then(
+ function() {
+ metrics.recordTime(
+ 'CloudImport.DeviceScan.Duration',
+ scanResult.getScanDurationMs());
+ metrics.recordValue(
+ 'CloudImport.DeviceScan.TotalSize',
+ scanResult.getTotalBytes() / (1024 * 1024));
+ });
+
return scanResult;
};
@@ -92,7 +109,7 @@ importer.DefaultMediaScanner.prototype.scan = function(entries) {
importer.DefaultMediaScanner.prototype.scanEntry_ =
function(result, entry) {
return entry.isFile ?
- result.addFileEntry(/** @type {!FileEntry} */ (entry)) :
+ result.onFileEntryFound(/** @type {!FileEntry} */ (entry)) :
this.scanDirectory_(result, /** @type {!DirectoryEntry} */ (entry));
};
@@ -116,7 +133,7 @@ importer.DefaultMediaScanner.prototype.scanDirectory_ =
entry,
/** @param {!FileEntry} fileEntry */
function(fileEntry) {
- promises.push(result.addFileEntry(fileEntry));
+ promises.push(result.onFileEntryFound(fileEntry));
})
.then(
/** @this {importer.DefaultScanResult} */
@@ -136,8 +153,13 @@ importer.DefaultMediaScanner.prototype.scanDirectory_ =
* @constructor
* @struct
* @implements {importer.ScanResult}
+ *
+ * @param {!Promise.<!importer.ImportHistory>} historyProvider
*/
-importer.DefaultScanResult = function() {
+importer.DefaultScanResult = function(historyProvider) {
+ /** @private {!Promise.<!importer.ImportHistory>} */
+ this.historyProvider_ = historyProvider;
+
/**
* List of file entries found while scanning.
* @private {!Array.<!FileEntry>}
@@ -201,14 +223,37 @@ importer.DefaultScanResult.prototype.whenFinished = function() {
* @param {!FileEntry} entry
* @return {!Promise} Resolves once file entry has been processed
* and is represented in results.
- * @private
*/
-importer.DefaultScanResult.prototype.addFileEntry = function(entry) {
+importer.DefaultScanResult.prototype.onFileEntryFound = function(entry) {
this.lastScanActivity_ = new Date();
if (!FileType.isImageOrVideo(entry)) {
return Promise.resolve();
}
+
+ return this.historyProvider_
+ .then(
+ /** @this {importer.DefaultScanResult} */
+ function(history) {
+ history.wasImported(entry, importer.Destination.GOOGLE_DRIVE)
+ .then(
+ function(imported) {
+ return imported ?
+ Promise.resolve() :
+ this.addFileEntry_(entry);
+ }.bind(this));
+ }.bind(this));
+};
+
+/**
+ * Adds a file to results.
+ *
+ * @param {!FileEntry} entry
+ * @return {!Promise} Resolves once file entry has been processed
+ * and is represented in results.
+ * @private
+ */
+importer.DefaultScanResult.prototype.addFileEntry_ = function(entry) {
return new Promise(
function(resolve, reject) {
// TODO(smckay): Update to use MetadataCache.

Powered by Google App Engine
This is Rietveld 408576698