Bug 1289906 - Part 2: Add more generic telemetry for undo reasons. r=bsmedberg, r=markh, a=lizzard
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Sat, 20 Aug 2016 14:15:12 +0100
changeset 347867 ee6808c347afdf6a341bdc8992fe297764546daf
parent 347866 0fe247649cf4fccc9bb86ea1b3896ee451c2d32b
child 347868 e29cdbb036abf01b465dcbae14d6252feb115102
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg, markh, lizzard
bugs1289906
milestone50.0a2
Bug 1289906 - Part 2: Add more generic telemetry for undo reasons. r=bsmedberg, r=markh, a=lizzard MozReview-Commit-ID: 1wwLdY2iumV
browser/components/migration/AutoMigrate.jsm
toolkit/components/telemetry/Histograms.json
--- a/browser/components/migration/AutoMigrate.jsm
+++ b/browser/components/migration/AutoMigrate.jsm
@@ -62,33 +62,33 @@ const AutoMigrate = {
   },
 
   maybeInitUndoObserver() {
     if (!this.canUndo()) {
       return;
     }
     // Now register places, password and sync observers:
     this.onItemAdded = this.onItemMoved = this.onItemChanged =
-      this.removeUndoOption;
+      this.removeUndoOption.bind(this, this.UNDO_REMOVED_REASON_BOOKMARK_CHANGE);
     PlacesUtils.addLazyBookmarkObserver(this, true);
     for (let topic of [kSyncTopic, kPasswordManagerTopic]) {
       Services.obs.addObserver(this, topic, true);
     }
   },
 
   observe(subject, topic, data) {
     if (topic == kPasswordManagerTopic) {
       // As soon as any login gets added or modified, disable undo:
       // (Note that this ignores logins being removed as that doesn't
       //  impair the 'undo' functionality of the import.)
       if (kPasswordManagerTopicTypes.has(data)) {
-        this.removeUndoOption();
+        this.removeUndoOption(this.UNDO_REMOVED_REASON_PASSWORD_CHANGE);
       }
     } else if (topic == kSyncTopic) {
-      this.removeUndoOption();
+      this.removeUndoOption(this.UNDO_REMOVED_REASON_SYNC_SIGNIN);
     }
   },
 
   /**
    * Automatically pick a migrator and resources to migrate,
    * then migrate those and start up.
    *
    * @throws if automatically deciding on migrators/data
@@ -242,35 +242,37 @@ const AutoMigrate = {
     histogram.add(20);
 
     try {
       Services.logins.removeAllLogins();
     } catch (ex) {
       // ignore failure.
     }
     histogram.add(25);
-    this.removeUndoOption();
+    this.removeUndoOption(this.UNDO_REMOVED_REASON_UNDO_USED);
     histogram.add(30);
   }),
 
-  removeUndoOption() {
+  removeUndoOption(reason) {
     // Remove observers, and ensure that exceptions doing so don't break
     // removing the pref.
     for (let topic of [kSyncTopic, kPasswordManagerTopic]) {
       try {
         Services.obs.removeObserver(this, topic);
       } catch (ex) {
         Cu.reportError("Error removing observer for " + topic + ": " + ex);
       }
     }
     try {
       PlacesUtils.removeLazyBookmarkObserver(this);
     } catch (ex) {
       Cu.reportError("Error removing lazy bookmark observer: " + ex);
     }
+
+    let migrationBrowser = Preferences.get(kAutoMigrateBrowserPref, "unknown");
     Services.prefs.clearUserPref(kAutoMigrateStartedPref);
     Services.prefs.clearUserPref(kAutoMigrateFinishedPref);
     Services.prefs.clearUserPref(kAutoMigrateBrowserPref);
 
     let browserWindows = Services.wm.getEnumerator("navigator:browser");
     while (browserWindows.hasMoreElements()) {
       let win = browserWindows.getNext();
       if (!win.closed) {
@@ -278,16 +280,19 @@ const AutoMigrate = {
           let nb = win.gBrowser.getNotificationBox(browser);
           let notification = nb.getNotificationWithValue(kNotificationId);
           if (notification) {
             nb.removeNotification(notification);
           }
         }
       }
     }
+    let histogram =
+      Services.telemetry.getKeyedHistogramById("FX_STARTUP_MIGRATION_UNDO_REASON");
+    histogram.add(migrationBrowser, reason);
   },
 
   getBrowserUsedForMigration() {
     let browserId = Services.prefs.getCharPref(kAutoMigrateBrowserPref);
     if (browserId) {
       return MigrationUtils.getBrowserName(browserId);
     }
     return null;
@@ -311,17 +316,17 @@ const AutoMigrate = {
     if (!notificationBox || notificationBox.getNotificationWithValue("abouthome-automigration-undo")) {
       return;
     }
 
     // At this stage we're committed to show the prompt - unless we shouldn't,
     // in which case we remove the undo prefs (which will cause canUndo() to
     // return false from now on.):
     if (!this.shouldStillShowUndoPrompt()) {
-      this.removeUndoOption();
+      this.removeUndoOption(this.UNDO_REMOVED_REASON_OFFER_EXPIRED);
       return;
     }
 
     let browserName = this.getBrowserUsedForMigration();
     let message;
     if (browserName) {
       message = this.getLocalizedString("automigration.undo.message",
                                                   [browserName]);
@@ -329,17 +334,17 @@ const AutoMigrate = {
       message = this.getLocalizedString("automigration.undo.unknownBrowserMessage");
     }
 
     let buttons = [
       {
         label: this.getLocalizedString("automigration.undo.keep.label"),
         accessKey: this.getLocalizedString("automigration.undo.keep.accesskey"),
         callback: () => {
-          this.removeUndoOption();
+          this.removeUndoOption(this.UNDO_REMOVED_REASON_OFFER_REJECTED);
         },
       },
       {
         label: this.getLocalizedString("automigration.undo.dontkeep.label"),
         accessKey: this.getLocalizedString("automigration.undo.dontkeep.accesskey"),
         callback: () => {
           this.undo();
         },
@@ -366,14 +371,21 @@ const AutoMigrate = {
       Preferences.set(kAutoMigrateLastUndoPromptDateMsPref, today.valueOf().toString());
       if (remainingDays <= 0) {
         return false;
       }
     }
     return true;
   },
 
+  UNDO_REMOVED_REASON_UNDO_USED: 0,
+  UNDO_REMOVED_REASON_SYNC_SIGNIN: 1,
+  UNDO_REMOVED_REASON_PASSWORD_CHANGE: 2,
+  UNDO_REMOVED_REASON_BOOKMARK_CHANGE: 3,
+  UNDO_REMOVED_REASON_OFFER_EXPIRED: 4,
+  UNDO_REMOVED_REASON_OFFER_REJECTED: 5,
+
   QueryInterface: XPCOMUtils.generateQI(
     [Ci.nsIObserver, Ci.nsINavBookmarkObserver, Ci.nsISupportsWeakReference]
   ),
 };
 
 AutoMigrate.init();
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -4344,16 +4344,26 @@
     "bug_numbers": [1283565],
     "alert_emails": ["gijs@mozilla.com"],
     "expires_in_version": "53",
     "kind": "enumerated",
     "n_values": 31,
     "releaseChannelCollection": "opt-out",
     "description": "Where undo of the automatic migration was attempted, indicates to what degree we succeeded to undo. 0 means we started to undo, 5 means we bailed out from the undo because it was not possible to complete it (there was nothing to undo or the user was signed in to sync). All higher values indicate progression through the undo sequence, with 30 indicating we finished the undo without exceptions in the middle."
   },
+  "FX_STARTUP_MIGRATION_UNDO_REASON": {
+    "bug_numbers": [1289906],
+    "alert_emails": ["gijs@mozilla.com"],
+    "expires_in_version": "54",
+    "keyed": true,
+    "kind": "enumerated",
+    "n_values": 10,
+    "releaseChannelCollection": "opt-out",
+    "description": "Why the undo functionality of an automatic migration was disabled: 0 means we used undo, 1 means the user signed in to sync, 2 means the user created/modified a password, 3 means the user created/modified a bookmark (item or folder), 4 means we showed an undo option repeatedly and the user did not use it, 5 means we showed an undo option and the user actively elected to keep the data. The whole thing is keyed to the identifiers of different browsers (so 'chrome', 'ie', 'edge', 'safari', etc.)."
+  },
   "FX_STARTUP_MIGRATION_DATA_RECENCY": {
     "bug_numbers": [1276694],
     "alert_emails": ["gijs@mozilla.com"],
     "expires_in_version": "53",
     "keyed": true,
     "kind": "exponential",
     "n_buckets": 50,
     "high": 8760,