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 bbc64371624a23f8d4e6e87aa237f1dbfe4de9ba..7fc0c4e5d725794ace3e5cd94f7a08ec45cb9803 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 |
@@ -38,10 +38,11 @@ importer.ImportRunner.prototype.importFromScanResult; |
* |
* @param {!ProgressCenter} progressCenter |
* @param {!importer.HistoryLoader} historyLoader |
- * @param {!importer.DuplicateFinder} duplicateFinder |
+ * @param {!importer.DuplicateFinder.Factory} duplicateFinderFactory |
+ * @param {!analytics.Tracker} tracker |
*/ |
importer.MediaImportHandler = |
- function(progressCenter, historyLoader, duplicateFinder) { |
+ function(progressCenter, historyLoader, duplicateFinderFactory, tracker) { |
/** @private {!ProgressCenter} */ |
this.progressCenter_ = progressCenter; |
@@ -51,8 +52,11 @@ importer.MediaImportHandler = |
/** @private {!importer.TaskQueue} */ |
this.queue_ = new importer.TaskQueue(); |
- /** @private {!importer.DuplicateFinder} */ |
- this.duplicateFinder_ = duplicateFinder; |
+ /** @private {!importer.DuplicateFinder.Factory} */ |
+ this.duplicateFinderFactory_ = duplicateFinderFactory; |
+ |
+ /** @private {!analytics.Tracker} */ |
+ this.tracker_ = tracker; |
/** @private {number} */ |
this.nextTaskId_ = 0; |
@@ -69,8 +73,9 @@ importer.MediaImportHandler.prototype.importFromScanResult = |
this.historyLoader_, |
scanResult, |
destinationDirectory, |
- this.duplicateFinder_, |
- destination); |
+ this.duplicateFinderFactory_.create(), |
+ destination, |
+ this.tracker_); |
task.addObserver(this.onTaskProgress_.bind(this, task)); |
@@ -154,6 +159,7 @@ importer.MediaImportHandler.prototype.onTaskProgress_ = |
* @param {!importer.DuplicateFinder} duplicateFinder A duplicate-finder linked |
* to the import destination, that will be used to deduplicate imports. |
* @param {!importer.Destination} destination The logical destination. |
+ * @param {!analytics.Tracker} tracker |
*/ |
importer.MediaImportHandler.ImportTask = function( |
taskId, |
@@ -161,7 +167,8 @@ importer.MediaImportHandler.ImportTask = function( |
scanResult, |
destinationFactory, |
duplicateFinder, |
- destination) { |
+ destination, |
+ tracker) { |
importer.TaskQueue.BaseTask.call(this, taskId); |
/** @private {string} */ |
@@ -182,6 +189,9 @@ importer.MediaImportHandler.ImportTask = function( |
/** @private {!importer.HistoryLoader} */ |
this.historyLoader_ = historyLoader; |
+ /** @private {!analytics.Tracker} */ |
+ this.tracker_ = tracker; |
+ |
/** @private {Promise<!DirectoryEntry>} */ |
this.destinationPromise_ = null; |
@@ -199,6 +209,9 @@ importer.MediaImportHandler.ImportTask = function( |
/** @private {boolean} Indicates whether this task was canceled. */ |
this.canceled_ = false; |
+ |
+ /** @private {number} Number of files deduped by content dedupe. */ |
+ this.dedupeCount_ = 0; |
}; |
/** @struct */ |
@@ -254,6 +267,7 @@ importer.MediaImportHandler.ImportTask.prototype.run = function() { |
*/ |
importer.MediaImportHandler.ImportTask.prototype.requestCancel = function() { |
this.canceled_ = true; |
+ this.tracker_.send(metrics.Events.IMPORT_CANCELLED); |
if (this.cancelCallback_) { |
// Reset the callback before calling it, as the callback might do anything |
// (including calling #requestCancel again). |
@@ -265,9 +279,19 @@ importer.MediaImportHandler.ImportTask.prototype.requestCancel = function() { |
/** @private */ |
importer.MediaImportHandler.ImportTask.prototype.initialize_ = function() { |
- this.remainingFilesCount_ = this.scanResult_.getFileEntries().length; |
- this.totalBytes_ = this.scanResult_.getTotalBytes(); |
+ var stats = this.scanResult_.getStatistics(); |
+ |
+ this.remainingFilesCount_ = stats.newFileCount; |
+ this.totalBytes_ = stats.sizeBytes; |
this.notify(importer.TaskQueue.UpdateType.PROGRESS); |
+ |
+ this.tracker_.send(metrics.Events.IMPORT_STARTED); |
+ this.tracker_.send(metrics.Events.IMPORT_FILE_COUNT |
Steve McKay
2015/02/17 23:47:50
Report file and byte count only when finished.
Ben Kwa
2015/02/18 22:23:01
File counts - done. Byte counts - as discussed of
|
+ .value(this.remainingFilesCount_)); |
+ this.tracker_.send(metrics.Events.IMPORT_BYTE_COUNT |
+ .value(this.totalBytes_)); |
+ this.tracker_.send(metrics.Events.HISTORY_DEDUPE_COUNT |
+ .value(stats.duplicateFileCount)); |
}; |
/** |
@@ -318,6 +342,7 @@ importer.MediaImportHandler.ImportTask.prototype.importOne_ = |
if (isDuplicate) { |
// If the given file is a duplicate, don't import it again. Just |
// update the progress indicator. |
+ this.dedupeCount_++; |
this.markAsImported_(entry); |
this.processedBytes_ += entry.size; |
this.notify(importer.TaskQueue.UpdateType.PROGRESS); |
@@ -451,6 +476,21 @@ importer.MediaImportHandler.ImportTask.prototype.markAsImported_ = |
/** @private */ |
importer.MediaImportHandler.ImportTask.prototype.onSuccess_ = function() { |
this.notify(importer.TaskQueue.UpdateType.SUCCESS); |
+ this.tracker_.send(metrics.Events.IMPORT_ENDED); |
+ this.tracker_.send(metrics.Events.CONTENT_DEDUPE_COUNT |
+ .value(this.dedupeCount_)); |
+ |
+ // Send aggregate deduplication timings, to avoid flooding analytics with one |
+ // timing per file. |
+ var deduplicatorStats = this.deduplicator_.getStatistics(); |
+ this.tracker_.sendTiming( |
+ metrics.Categories.IMPORT, |
+ metrics.timing.Variables.COMPUTE_HASH, |
+ deduplicatorStats.computeHashTime); |
+ this.tracker_.sendTiming( |
+ metrics.Categories.IMPORT, |
+ metrics.timing.Variables.SEARCH_BY_HASH, |
+ deduplicatorStats.searchHashTime); |
}; |
/** |
@@ -459,6 +499,9 @@ importer.MediaImportHandler.ImportTask.prototype.onSuccess_ = function() { |
*/ |
importer.MediaImportHandler.ImportTask.prototype.onError_ = function(error) { |
this.notify(importer.TaskQueue.UpdateType.ERROR); |
+ // TODO(kenobi): Impedence mismatch: this gets called per-file, which is |
+ // different from onSuccess, which reports overall import success. |
+ this.tracker_.send(metrics.Events.IMPORT_ERROR); |
}; |
/** |