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 b311fc6a51750ee11f09e5d433a0faa588a11240..86dd1bcf31765e46db276e483b716dfa88385787 100644 |
--- a/ui/file_manager/file_manager/background/js/media_scanner.js |
+++ b/ui/file_manager/file_manager/background/js/media_scanner.js |
@@ -59,26 +59,26 @@ importer.ScanResult.prototype.isInvalidated; |
importer.ScanResult.prototype.getFileEntries; |
/** |
- * Returns the aggregate size, in bytes, of all FileEntries discovered |
- * during scanning. |
+ * Returns a promise that fires when scanning is complete. |
* |
- * @return {number} |
+ * @return {!Promise.<!importer.ScanResult>} |
*/ |
-importer.ScanResult.prototype.getTotalBytes; |
+importer.ScanResult.prototype.whenFinal; |
/** |
- * Returns the scan duration in milliseconds. |
- * |
- * @return {number} |
+ * @return {!importer.ScanResult.Statistics} |
*/ |
-importer.ScanResult.prototype.getScanDurationMs; |
+importer.ScanResult.prototype.getStatistics; |
/** |
- * Returns a promise that fires when scanning is complete. |
- * |
- * @return {!Promise.<!importer.ScanResult>} |
+ * @typedef {{ |
+ * scanDuration: number, |
+ * newFileCount: number, |
+ * duplicateFileCount: number, |
+ * sizeBytes: number |
+ * }} |
*/ |
-importer.ScanResult.prototype.whenFinal; |
+importer.ScanResult.Statistics; |
/** |
* Recursively scans through a list of given files and directories, and creates |
@@ -266,14 +266,14 @@ importer.DefaultMediaScanner.prototype.onFileEntryFound_ = |
* @this {importer.DefaultMediaScanner} |
*/ |
function(duplicate) { |
- if (!duplicate) { |
- return this.onUniqueFileFound_(scan, entry); |
- } |
+ return duplicate ? |
+ this.onDuplicateFileFound_(scan, entry) : |
+ this.onUniqueFileFound_(scan, entry); |
}.bind(this)); |
}; |
/** |
- * Finds all files beneath directory. |
+ * Adds a newly discovered file to the given scan result. |
* |
* @param {!importer.DefaultScanResult} scan |
* @param {!FileEntry} entry |
@@ -301,6 +301,21 @@ importer.DefaultMediaScanner.prototype.onUniqueFileFound_ = |
}; |
/** |
+ * Adds a duplicate file to the given scan result. This is to track the number |
+ * of duplicates that are being encountered. |
+ * |
+ * @param {!importer.DefaultScanResult} scan |
+ * @param {!FileEntry} entry |
+ * @return {!Promise} |
+ * @private |
+ */ |
+importer.DefaultMediaScanner.prototype.onDuplicateFileFound_ = |
+ function(scan, entry) { |
+ scan.addDuplicateEntry(entry); |
+ return Promise.resolve(); |
+}; |
+ |
+/** |
* @param {!FileEntry} entry |
* @return {!Promise.<boolean>} True if there is a history-entry-duplicate |
* for the file. |
@@ -366,6 +381,9 @@ importer.DefaultScanResult = function(hashGenerator) { |
/** @private {number} */ |
this.totalBytes_ = 0; |
+ /** @private {number} */ |
+ this.duplicateFileCount_ = 0; |
+ |
/** |
* The point in time when the scan was started. |
* @type {Date} |
@@ -412,16 +430,6 @@ importer.DefaultScanResult.prototype.getFileEntries = function() { |
}; |
/** @override */ |
-importer.DefaultScanResult.prototype.getTotalBytes = function() { |
- return this.totalBytes_; |
-}; |
- |
-/** @override */ |
-importer.DefaultScanResult.prototype.getScanDurationMs = function() { |
- return this.lastScanActivity_.getTime() - this.scanStarted_.getTime(); |
-}; |
- |
-/** @override */ |
importer.DefaultScanResult.prototype.whenFinal = function() { |
return this.resolver_.promise; |
}; |
@@ -461,11 +469,12 @@ importer.DefaultScanResult.prototype.addFileEntry = function(entry) { |
this.lastScanActivity_ = new Date(); |
if (hashcode in this.fileHashcodes_) { |
+ this.addDuplicateEntry(entry); |
return false; |
} |
entry.size = metadata.size; |
- this.totalBytes_ += metadata['size']; |
+ this.totalBytes_ += metadata.size; |
this.fileHashcodes_[hashcode] = entry; |
this.fileEntries_.push(entry); |
return true; |
@@ -475,6 +484,25 @@ importer.DefaultScanResult.prototype.addFileEntry = function(entry) { |
}; |
/** |
+ * Logs the fact that a duplicate file entry was discovered during the scan. |
+ * @param {!FileEntry} entry |
+ */ |
+importer.DefaultScanResult.prototype.addDuplicateEntry = function(entry) { |
+ this.duplicateFileCount_++; |
+}; |
+ |
+/** @override */ |
+importer.DefaultScanResult.prototype.getStatistics = function() { |
+ return { |
+ scanDuration: |
+ this.lastScanActivity_.getTime() - this.scanStarted_.getTime(), |
+ newFileCount: this.fileEntries_.length, |
+ duplicateFileCount: this.duplicateFileCount_, |
+ sizeBytes: this.totalBytes_ |
+ }; |
+}; |
+ |
+/** |
* Watcher for directories. |
* @interface |
*/ |