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

Unified Diff: ui/file_manager/file_manager/foreground/js/directory_model.js

Issue 1022423005: Move view change analytics tracking into DirectoryModel where implementation details can be hidden. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add FSP extension whitelist so we can report names to analytics rather than extension ids for provi… Created 5 years, 9 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/foreground/js/directory_model.js
diff --git a/ui/file_manager/file_manager/foreground/js/directory_model.js b/ui/file_manager/file_manager/foreground/js/directory_model.js
index c7c8213865b2c1a2474393dbee011110cfb10940..21f08ab61baa4a5d8738631651c17678bacefc6e 100644
--- a/ui/file_manager/file_manager/foreground/js/directory_model.js
+++ b/ui/file_manager/file_manager/foreground/js/directory_model.js
@@ -11,6 +11,9 @@ var SHORT_RESCAN_INTERVAL = 100;
/**
* Data model of the file manager.
*
+ * @constructor
+ * @extends {cr.EventTarget}
+ *
* @param {boolean} singleSelection True if only one file could be selected
* at the time.
* @param {FileFilter} fileFilter Instance of FileFilter.
@@ -18,12 +21,15 @@ var SHORT_RESCAN_INTERVAL = 100;
* service.
* @param {VolumeManagerWrapper} volumeManager The volume manager.
* @param {!FileOperationManager} fileOperationManager File operation manager.
- * @constructor
- * @extends {cr.EventTarget}
+ * @param {!analytics.Tracker} tracker
*/
-function DirectoryModel(singleSelection, fileFilter,
- metadataModel,
- volumeManager, fileOperationManager) {
+function DirectoryModel(
+ singleSelection,
+ fileFilter,
+ metadataModel,
+ volumeManager,
+ fileOperationManager,
+ tracker) {
this.fileListSelection_ = singleSelection ?
new FileListSingleSelectionModel() : new FileListSelectionModel();
@@ -65,6 +71,9 @@ function DirectoryModel(singleSelection, fileFilter,
fileOperationManager,
'entries-changed',
this.onEntriesChanged_.bind(this));
+
+ /** @private {!analytics.Tracker} */
+ this.tracker_ = tracker;
}
/**
@@ -921,17 +930,23 @@ DirectoryModel.prototype.changeDirectoryEntry = function(
var previousDirEntry =
this.currentDirContents_.getDirectoryEntry();
- this.clearAndScan_(
- newDirectoryContents,
- function(result) {
- // Calls the callback of the method when successful.
- if (result && opt_callback)
- opt_callback();
-
- // Notify that the current task of this.directoryChangeQueue_
- // is completed.
- setTimeout(queueTaskCallback, 0);
- });
+
+ var promises = [];
+
+ promises.push(
+ new Promise(
+ /** @this {DirectoryModel} */
+ function(resolve) {
+ this.clearAndScan_(
+ newDirectoryContents,
+ function(result) {
+ // Calls the callback of the method when successful.
+ if (result && opt_callback)
+ opt_callback();
+
+ resolve(undefined);
+ });
+ }.bind(this)));
// For tests that open the dialog to empty directories, everything
// is loaded at this point.
@@ -945,12 +960,68 @@ DirectoryModel.prototype.changeDirectoryEntry = function(
event.previousDirEntry = previousDirEntry;
event.newDirEntry = dirEntry;
event.volumeChanged = previousVolumeInfo !== currentVolumeInfo;
+
+ if (event.volumeChanged) {
+ promises.push(this.onVolumeChanged_(currentVolumeInfo));
+ }
+
this.dispatchEvent(event);
+ Promise.all(promises).then(queueTaskCallback);
}.bind(this));
}.bind(this, this.changeDirectorySequence_));
};
/**
+ * Handles volume changed by sending an analytics appView event.
+ *
+ * @param {!VolumeInfo} volumeInfo The new volume info.
+ * @return {!Promise} resolves once handling is done.
+ * @private
+ */
+DirectoryModel.prototype.onVolumeChanged_ = function(volumeInfo) {
+ // NOTE: That dynamic values, like volume name MUST NOT
+ // be sent to GA as that value can contain PII.
+ // VolumeType is an enum.
+ // ...
+ // But we can do stuff like figure out if this is a media device or vanilla
+ // removable device.
+ return Promise.resolve(undefined)
+ .then(
+ function() {
+ switch (volumeInfo.volumeType) {
+ case VolumeManagerCommon.VolumeType.REMOVABLE:
+ return importer.hasMediaDirectory(volumeInfo.fileSystem.root)
+ .then(
+ /**
+ * @param {boolean} hasMedia
+ * @return {string}
+ */
+ function(hasMedia) {
+ return hasMedia ?
+ volumeInfo.volumeType + ':with-media-dir' :
+ volumeInfo.volumeType;
+ });
+ case VolumeManagerCommon.VolumeType.PROVIDED:
+ var extensionId = volumeInfo.extensionId;
+ var extensionName =
+ metrics.getFileSystemProviderName(extensionId, 'unknown');
+ // Make note of an unrecognized extension id. When we see
+ // high counts for a particular id, we should add it to the
+ // whitelist in metrics_events.js.
+ if (extensionId && extensionName == 'unknown') {
+ this.tracker_.sendEvent(
+ metrics.Internals.UNRECOGNIZED_FILE_SYSTEM_PROVIDER
+ .label(extensionId));
+ }
+ return volumeInfo.volumeType + ':' + extensionName;
+ default:
+ return volumeInfo.volumeType;
+ }
+ })
+ .then(this.tracker_.sendAppView.bind(this.tracker_));
+};
+
+/**
* Activates the given directory.
* This method:
* - Changes the current directory, if the given directory is the current
« no previous file with comments | « ui/file_manager/file_manager/common/js/metrics_events.js ('k') | ui/file_manager/file_manager/foreground/js/file_manager.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698