Bug 1520361 - Add Telemetry to know how people add site to the exception list. r=smaug,cpearce,janerik
authorAlastor Wu <alwu@mozilla.com>
Tue, 22 Jan 2019 18:22:44 +0000
changeset 511972 89875cd4d9422dd0f7a169184ac2633a6669a196
parent 511971 36b36b5cdab6c75c1cfd7e0e7c4784c297c2efa2
child 511973 69a2799081521866febfe2bbcbfc27b3d60133bd
push id10566
push userarchaeopteryx@coole-files.de
push dateMon, 28 Jan 2019 12:41:12 +0000
treeherdermozilla-beta@69a3d7c8d04b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, cpearce, janerik
bugs1520361
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1520361 - Add Telemetry to know how people add site to the exception list. r=smaug,cpearce,janerik Add Telemetry to know the number of times user adds site to allow list, remove site from allow list, add site to block list and remove site from block list. Differential Revision: https://phabricator.services.mozilla.com/D16642
extensions/cookie/nsPermissionManager.cpp
toolkit/components/telemetry/Histograms.json
--- a/extensions/cookie/nsPermissionManager.cpp
+++ b/extensions/cookie/nsPermissionManager.cpp
@@ -727,16 +727,70 @@ static bool IsExpandedPrincipal(nsIPrinc
 
 // We only want to persist permissions which don't have session or policy
 // expiration.
 static bool IsPersistentExpire(uint32_t aExpire) {
   return aExpire != nsIPermissionManager::EXPIRE_SESSION &&
          aExpire != nsIPermissionManager::EXPIRE_POLICY;
 }
 
+static void UpdateAutoplayTelemetry(const nsCString& aType,
+                                    uint32_t aOldPermission,
+                                    uint32_t aNewPermission,
+                                    uint32_t aExpireType) {
+  if (!aType.EqualsLiteral("autoplay-media")) {
+    return;
+  }
+
+  if (aExpireType != nsIPermissionManager::EXPIRE_NEVER) {
+    return;
+  }
+
+  // Add permission
+  if (aOldPermission == nsIPermissionManager::UNKNOWN_ACTION) {
+    if (aNewPermission == nsIPermissionManager::ALLOW_ACTION) {
+      AccumulateCategorical(
+          mozilla::Telemetry::LABELS_AUTOPLAY_SITES_SETTING_CHANGE::AddAllow);
+    } else if (aNewPermission == nsIPermissionManager::DENY_ACTION) {
+      AccumulateCategorical(
+          mozilla::Telemetry::LABELS_AUTOPLAY_SITES_SETTING_CHANGE::AddBlock);
+    }
+    return;
+  }
+
+  // Remove permission
+  if (aNewPermission == nsIPermissionManager::UNKNOWN_ACTION) {
+    if (aOldPermission == nsIPermissionManager::ALLOW_ACTION) {
+      AccumulateCategorical(
+          mozilla::Telemetry::LABELS_AUTOPLAY_SITES_SETTING_CHANGE::
+              RemoveAllow);
+    } else if (aOldPermission == nsIPermissionManager::DENY_ACTION) {
+      AccumulateCategorical(
+          mozilla::Telemetry::LABELS_AUTOPLAY_SITES_SETTING_CHANGE::
+              RemoveBlock);
+    }
+    return;
+  }
+
+  // Change permission
+  if (aNewPermission == nsIPermissionManager::ALLOW_ACTION &&
+      aOldPermission == nsIPermissionManager::DENY_ACTION) {
+    AccumulateCategorical(
+        mozilla::Telemetry::LABELS_AUTOPLAY_SITES_SETTING_CHANGE::AddAllow);
+    AccumulateCategorical(
+        mozilla::Telemetry::LABELS_AUTOPLAY_SITES_SETTING_CHANGE::RemoveBlock);
+  } else if (aNewPermission == nsIPermissionManager::DENY_ACTION &&
+             aOldPermission == nsIPermissionManager::ALLOW_ACTION) {
+    AccumulateCategorical(
+        mozilla::Telemetry::LABELS_AUTOPLAY_SITES_SETTING_CHANGE::AddBlock);
+    AccumulateCategorical(
+        mozilla::Telemetry::LABELS_AUTOPLAY_SITES_SETTING_CHANGE::RemoveAllow);
+  }
+}
+
 }  // namespace
 
 ////////////////////////////////////////////////////////////////////////////////
 
 nsPermissionManager::PermissionKey*
 nsPermissionManager::PermissionKey::CreateFromPrincipal(
     nsIPrincipal* aPrincipal, nsresult& aResult) {
   nsAutoCString origin;
@@ -1812,16 +1866,20 @@ nsresult nsPermissionManager::AddInterna
 
   switch (op) {
     case eOperationNone: {
       // nothing to do
       return NS_OK;
     }
 
     case eOperationAdding: {
+      UpdateAutoplayTelemetry(aType,
+                              nsIPermissionManager::UNKNOWN_ACTION,
+                              aPermission,
+                              aExpireType);
       if (aDBOperation == eWriteToDB) {
         // we'll be writing to the database - generate a known unique id
         id = ++mLargestID;
       } else {
         // we're reading from the database - use the id already assigned
         id = aID;
       }
 
@@ -1855,16 +1913,20 @@ nsresult nsPermissionManager::AddInterna
 
       // If the type we want to remove is EXPIRE_POLICY, we need to reject
       // attempts to change the permission.
       if (entry->GetPermissions()[index].mExpireType == EXPIRE_POLICY) {
         NS_WARNING("Attempting to remove EXPIRE_POLICY permission");
         break;
       }
 
+      UpdateAutoplayTelemetry(aType,
+                              oldPermissionEntry.mPermission,
+                              nsIPermissionManager::UNKNOWN_ACTION,
+                              aExpireType);
       entry->GetPermissions().RemoveElementAt(index);
 
       // Record a count of the number of preload permissions present in the
       // content process.
       if (IsPreloadPermission(mTypeArray[typeIndex].get())) {
         sPreloadPermissionCount--;
       }
 
@@ -1894,16 +1956,21 @@ nsresult nsPermissionManager::AddInterna
 
       // If the existing type is EXPIRE_POLICY, we need to reject attempts to
       // change the permission.
       if (entry->GetPermissions()[index].mExpireType == EXPIRE_POLICY) {
         NS_WARNING("Attempting to modify EXPIRE_POLICY permission");
         break;
       }
 
+      UpdateAutoplayTelemetry(aType,
+                              entry->GetPermissions()[index].mPermission,
+                              aPermission,
+                              aExpireType);
+
       // If the new expireType is EXPIRE_SESSION, then we have to keep a
       // copy of the previous permission/expireType values. This cached value
       // will be used when restoring the permissions of an app.
       if (entry->GetPermissions()[index].mExpireType !=
               nsIPermissionManager::EXPIRE_SESSION &&
           aExpireType == nsIPermissionManager::EXPIRE_SESSION) {
         entry->GetPermissions()[index].mNonSessionPermission =
             entry->GetPermissions()[index].mPermission;
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -14486,16 +14486,29 @@
     ],
     "expires_in_version": "70",
     "kind": "categorical",
     "labels": ["NeverBlocked", "AllowedAfterBlocked", "NeverAllowed"],
     "bug_numbers": [1512277],
     "description": "The number of times an AudioContext is allowed to start after being blocked, or the number of AudioContexts attempting to start which were never blocked or never allowed.",
     "releaseChannelCollection": "opt-out"
   },
+  "AUTOPLAY_SITES_SETTING_CHANGE": {
+    "record_in_processes": ["main", "content"],
+    "alert_emails": [
+      "alwu@mozilla.com",
+      "cpearce@mozilla.com"
+    ],
+    "expires_in_version": "71",
+    "kind": "categorical",
+    "labels": ["AddAllow", "RemoveAllow", "AddBlock", "RemoveBlock"],
+    "bug_numbers": [1520361],
+    "description": "The number of times the user adds a site to the allow list, removes a site from the allow list, adds a site to the block list and removes a site from the block list.",
+    "releaseChannelCollection": "opt-out"
+  },
   "QM_REPOSITORIES_INITIALIZATION_TIME": {
     "record_in_processes": ["main"],
     "expires_in_version": "68",
     "bug_numbers": [1481716],
     "kind": "exponential",
     "high": 30000,
     "n_buckets": 30,
     "releaseChannelCollection": "opt-out",