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

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

Issue 918713003: Files.app: Add analytics code to instrument cloud import flows. (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
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..96cf0196ba891d0347d01e5f6ea55ff60b098657 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,9 +266,9 @@ importer.DefaultMediaScanner.prototype.onFileEntryFound_ =
* @this {importer.DefaultMediaScanner}
*/
function(duplicate) {
- if (!duplicate) {
- return this.onUniqueFileFound_(scan, entry);
- }
+ return duplicate ?
+ Promise.resolve() :
+ this.onUniqueFileFound_(scan, entry);
}.bind(this));
};
@@ -300,6 +300,11 @@ importer.DefaultMediaScanner.prototype.onUniqueFileFound_ =
}.bind(this));
};
+importer.DefaultMediaScanner.prototype.onDuplicateFileFound_ =
+ function(scan, entry) {
+ scan.addDuplicateEntry(entry);
+};
+
/**
* @param {!FileEntry} entry
* @return {!Promise.<boolean>} True if there is a history-entry-duplicate
@@ -366,6 +371,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 +420,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 +459,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 +474,24 @@ 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_++;
+};
+
+importer.DefaultScanResult.prototype.getStatistics = function() {
mtomasz 2015/02/12 01:51:03 nit: jsdoc missing?
Ben Kwa 2015/02/17 23:01:29 Done.
+ return {
+ scanDuration:
+ this.lastScanActivity_.getTime() - this.scanStarted_.getTime(),
+ newFileCount: this.fileEntries_.length,
+ duplicateFileCount: this.duplicateFileCount_,
+ sizeBytes: this.totalBytes_
+ };
+};
+
+/**
* Watcher for directories.
* @interface
*/

Powered by Google App Engine
This is Rietveld 408576698