summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorkenobi <kenobi@chromium.org>2015-03-10 10:02:51 -0700
committerCommit bot <commit-bot@chromium.org>2015-03-10 17:03:30 +0000
commitf7dd25c4eb020d227f0fe1f655daefad08903ff7 (patch)
tree0f2b30d754c68bee02599a30f20acd8441d1f149 /ui
parentcd62df7d4d23db29bdf16f7eefe701d092209b6d (diff)
downloadchromium_src-f7dd25c4eb020d227f0fe1f655daefad08903ff7.zip
chromium_src-f7dd25c4eb020d227f0fe1f655daefad08903ff7.tar.gz
chromium_src-f7dd25c4eb020d227f0fe1f655daefad08903ff7.tar.bz2
Update the chrome platform analytics package to 1.6.0.
BUG=461946 Review URL: https://codereview.chromium.org/986393002 Cr-Commit-Position: refs/heads/master@{#319905}
Diffstat (limited to 'ui')
-rw-r--r--ui/file_manager/file_manager/background/js/background.js5
-rw-r--r--ui/file_manager/file_manager/common/js/metrics.js41
-rw-r--r--ui/file_manager/file_manager/common/js/metrics_unittest.js39
3 files changed, 63 insertions, 22 deletions
diff --git a/ui/file_manager/file_manager/background/js/background.js b/ui/file_manager/file_manager/background/js/background.js
index b415ad0..13531be 100644
--- a/ui/file_manager/file_manager/background/js/background.js
+++ b/ui/file_manager/file_manager/background/js/background.js
@@ -627,11 +627,6 @@ FileBrowserBackground.prototype.initContextMenu_ = function() {
});
};
-// Ensure that the user gets a new analytics ID each time Files.app starts.
-// NOTE: This must be called before FileBrowserBackground is instantiated.
-// TODO(kenobi): Revisit this once users have the ability to do this themselves.
-metrics.clearUserId();
-
/**
* Singleton instance of Background.
* NOTE: This must come after the call to metrics.clearUserId.
diff --git a/ui/file_manager/file_manager/common/js/metrics.js b/ui/file_manager/file_manager/common/js/metrics.js
index a96d827..fa84d7e5 100644
--- a/ui/file_manager/file_manager/common/js/metrics.js
+++ b/ui/file_manager/file_manager/common/js/metrics.js
@@ -28,6 +28,9 @@ metrics.convertName_ = function(name) {
return 'FileBrowser.' + name;
};
+/** @private {analytics.GoogleAnalytics} */
+metrics.analytics_ = null;
+
/** @private {analytics.Tracker} */
metrics.tracker_ = null;
@@ -47,39 +50,49 @@ metrics.getTracker = function() {
* @private
*/
metrics.createTracker_ = function() {
- var analyticsService = analytics.getService('Files app');
+ metrics.analytics_ = analytics.getService('Files app');
// Create a tracker, add a filter that only enables analytics when UMA is
// enabled.
- metrics.tracker_ = analyticsService.getTracker(metrics.TRACKING_ID);
+ metrics.tracker_ = metrics.analytics_.getTracker(metrics.TRACKING_ID);
metrics.tracker_.addFilter(metrics.umaEnabledFilter_);
};
/**
* Queries the chrome UMA enabled setting, and filters hits based on that.
* @param {!analytics.Tracker.Hit} hit
+ * @return {!goog.async.Deferred} A deferred indicating when the filter has
+ * completed running.
* @private
*/
metrics.umaEnabledFilter_ = function(hit) {
+ // TODO(kenobi): Change this to use Promises when analytics supports it.
+ var deferred = new goog.async.Deferred();
+
chrome.fileManagerPrivate.isUMAEnabled(
- /** @param {boolean} enabled */
function(enabled) {
+ if (!enabled) {
+ // If UMA was just toggled, reset the analytics ID.
+ if (metrics.enabled_) {
+ metrics.clearUserId_();
+ }
+ hit.cancel();
+ }
metrics.enabled_ = enabled;
+ deferred.callback(enabled);
});
- if (!metrics.enabled_) {
- hit.cancel();
- }
+
+ return deferred;
};
/**
* Clears the previously set analytics user id.
+ * @return {!Promise} Resolves when the analytics ID has been reset.
*/
-metrics.clearUserId = function() {
- chrome.storage.local.remove(
- 'google-analytics.analytics.user-id',
- function () {
- if (chrome.runtime.lastError) {
- throw new Error(chrome.runtime.lastError.message);
- }
- });
+metrics.clearUserId_ = function() {
+ return metrics.analytics_.getConfig().then(
+ /** @param {!analytics.Config} config */
+ function(config) {
+ config.resetUserId();
+ });
};
diff --git a/ui/file_manager/file_manager/common/js/metrics_unittest.js b/ui/file_manager/file_manager/common/js/metrics_unittest.js
index 36a9807..47a0b61 100644
--- a/ui/file_manager/file_manager/common/js/metrics_unittest.js
+++ b/ui/file_manager/file_manager/common/js/metrics_unittest.js
@@ -14,16 +14,16 @@ var tracker;
function setUp() {
setupFakeChromeAPIs();
+ // Set a fake tracking ID so the tests aren't actually sending analytics.
+ metrics.TRACKING_ID = 'UA-XXXXX-XX';
tracker = metrics.getTracker();
- // Make a filter that logs the last received hit. Cancel the hit so that
- // running tests doesn't actually send any analytics.
+ // Make a filter that logs the last received hit.
tracker.addFilter(
/** @param {!analytics.Tracker.Hit} hit */
function(hit) {
// Log the hit.
lastHit = hit;
- hit.cancel();
});
// Reset the last logged hit.
lastHit = null;
@@ -55,6 +55,39 @@ function testUMADisabled(callback) {
callback);
}
+// Verifies that toggling the UMA setting causes the user's analytics ID to be
+// reset.
+function testResetAnalyticsOnUMAToggle(callback) {
+ var id0 = null;
+ var id1 = null;
+
+ // Simulate UMA enabled, and send a hit.
+ chrome.fileManagerPrivate.umaEnabled = true;
+ reportPromise(
+ tracker.sendAppView('Test0')
+ .then(
+ function() {
+ // Log the analytics ID that got sent.
+ id0 = lastHit.getParameters().toObject()['clientId'];
+ // Simulate UMA disabled, send another hit.
+ chrome.fileManagerPrivate.umaEnabled = false;
+ return tracker.sendAppView('Test1');
+ })
+ .then(
+ function() {
+ // Re-enable analytics, send another hit.
+ chrome.fileManagerPrivate.umaEnabled = true;
+ return tracker.sendAppView('Test2');
+ })
+ .then(
+ function() {
+ // Check that a subsequent hit has a different analytics ID.
+ id1 = lastHit.getParameters().toObject()['clientId'];
+ assertTrue(id0 !== id1);
+ }),
+ callback);
+}
+
function setupFakeChromeAPIs() {
chrome = {
runtime: {