Bug 1289906 - part 2: add more generic telemetry for undo reasons, r?bsmedberg,markh draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Sat, 20 Aug 2016 14:15:12 +0100
changeset 403906 1b9357ec4e78fc7b1b6ec6e81144e13b9abfe870
parent 403905 81f166d1a62dd4886b6203a05f1ab79f7eafb79a
child 529028 c5367e145d62bf570d1cabe3273c4ffd44536b0b
push id27041
push usergijskruitbosch@gmail.com
push dateMon, 22 Aug 2016 11:53:01 +0000
reviewersbsmedberg, markh
bugs1289906
milestone51.0a1
Bug 1289906 - part 2: add more generic telemetry for undo reasons, r?bsmedberg,markh 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
@@ -51,35 +51,35 @@ const AutoMigrate = {
   },
 
   maybeInitUndoObserver() {
     if (!this.canUndo()) {
       return;
     }
     // Now register places and password observers:
     this.onItemAdded = this.onItemMoved = this.onItemChanged =
-      this.removeUndoOption;
+      this.removeUndoOption.bind(this, this.UNDO_REMOVED_REASON_BOOKMARK_CHANGE);
     PlacesUtils.addLazyBookmarkObserver(this, true);
     Services.obs.addObserver(this, kPasswordManagerTopic, true);
     // And sync ones:
     for (let topic of kSyncTopics) {
       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 (kSyncTopics.has(topic)) {
-      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
@@ -233,34 +233,36 @@ 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.
     try {
       for (let topic of kSyncTopics) {
         Services.obs.removeObserver(this, kSyncTopics);
       }
     } catch (ex) {}
     try {
       Services.obs.removeObserver(this, kPasswordManagerTopic);
     } catch (ex) {}
     try {
       PlacesUtils.removeLazyBookmarkObserver(this);
     } catch (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) {
@@ -268,16 +270,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;
@@ -294,17 +299,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 = MigrationUtils.getLocalizedString("automigration.undo.message",
                                                   [browserName]);
@@ -312,17 +317,17 @@ const AutoMigrate = {
       message = MigrationUtils.getLocalizedString("automigration.undo.unknownBrowserMessage");
     }
 
     let buttons = [
       {
         label: MigrationUtils.getLocalizedString("automigration.undo.keep.label"),
         accessKey: MigrationUtils.getLocalizedString("automigration.undo.keep.accesskey"),
         callback: () => {
-          this.removeUndoOption();
+          this.removeUndoOption(this.UNDO_REMOVED_REASON_OFFER_REJECTED);
         },
       },
       {
         label: MigrationUtils.getLocalizedString("automigration.undo.dontkeep.label"),
         accessKey: MigrationUtils.getLocalizedString("automigration.undo.dontkeep.accesskey"),
         callback: () => {
           this.undo();
         },
@@ -349,14 +354,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
@@ -4652,16 +4652,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,