Bug 1591803 - Part 1: Remove the dead code in NotificationTelemetryService; r=johannh
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 29 Oct 2019 01:56:23 +0000
changeset 499553 8305d3ae226dac150ae3f1cb531466413ca56901
parent 499552 47376d3ff1a9c23946d1c4fcb9d21608fd8535a3
child 499554 a6be0a8773dbc71ef1f33d67befbec9c4727803b
push id36743
push usershindli@mozilla.com
push dateTue, 29 Oct 2019 09:38:03 +0000
treeherdermozilla-central@9b2ebbf56577 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1591803
milestone72.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 1591803 - Part 1: Remove the dead code in NotificationTelemetryService; r=johannh Differential Revision: https://phabricator.services.mozilla.com/D50752
dom/notification/Notification.cpp
dom/notification/Notification.h
layout/build/components.conf
toolkit/components/alerts/nsXULAlerts.cpp
toolkit/components/telemetry/Histograms.json
toolkit/components/telemetry/histogram-allowlists.json
--- a/dom/notification/Notification.cpp
+++ b/dom/notification/Notification.cpp
@@ -588,135 +588,16 @@ nsresult NotificationPermissionRequest::
     RefPtr<NotificationPermissionCallback> callback(mCallback);
     callback->Call(mPermission, error);
     rv = error.StealNSResult();
   }
   mPromise->MaybeResolve(mPermission);
   return rv;
 }
 
-NS_IMPL_ISUPPORTS(NotificationTelemetryService, nsIObserver)
-
-NotificationTelemetryService::NotificationTelemetryService()
-    : mDNDRecorded(false) {}
-
-NotificationTelemetryService::~NotificationTelemetryService() {}
-
-/* static */
-already_AddRefed<NotificationTelemetryService>
-NotificationTelemetryService::GetInstance() {
-  nsCOMPtr<nsISupports> telemetrySupports =
-      do_GetService(NOTIFICATIONTELEMETRYSERVICE_CONTRACTID);
-  if (!telemetrySupports) {
-    return nullptr;
-  }
-  RefPtr<NotificationTelemetryService> telemetry =
-      static_cast<NotificationTelemetryService*>(telemetrySupports.get());
-  return telemetry.forget();
-}
-
-nsresult NotificationTelemetryService::Init() {
-  // Only perform permissions telemetry collection in the parent process.
-  if (!XRE_IsParentProcess()) {
-    return NS_OK;
-  }
-
-  RecordPermissions();
-
-  return NS_OK;
-}
-
-void NotificationTelemetryService::RecordPermissions() {
-  MOZ_ASSERT(XRE_IsParentProcess(),
-             "RecordPermissions may only be called in the parent process");
-
-  if (!Telemetry::CanRecordBase() || !Telemetry::CanRecordExtended()) {
-    return;
-  }
-
-  nsCOMPtr<nsIPermissionManager> permissionManager =
-      services::GetPermissionManager();
-  if (!permissionManager) {
-    return;
-  }
-
-  nsCOMPtr<nsISimpleEnumerator> enumerator;
-  nsresult rv = permissionManager->GetEnumerator(getter_AddRefs(enumerator));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return;
-  }
-
-  for (;;) {
-    bool hasMoreElements;
-    nsresult rv = enumerator->HasMoreElements(&hasMoreElements);
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      return;
-    }
-    if (!hasMoreElements) {
-      break;
-    }
-    nsCOMPtr<nsISupports> supportsPermission;
-    rv = enumerator->GetNext(getter_AddRefs(supportsPermission));
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      return;
-    }
-    uint32_t capability;
-    if (!GetNotificationPermission(supportsPermission, &capability)) {
-      continue;
-    }
-  }
-}
-
-bool NotificationTelemetryService::GetNotificationPermission(
-    nsISupports* aSupports, uint32_t* aCapability) {
-  nsCOMPtr<nsIPermission> permission = do_QueryInterface(aSupports);
-  if (!permission) {
-    return false;
-  }
-  nsAutoCString type;
-  permission->GetType(type);
-  if (!type.EqualsLiteral("desktop-notification")) {
-    return false;
-  }
-  permission->GetCapability(aCapability);
-  return true;
-}
-
-void NotificationTelemetryService::RecordDNDSupported() {
-  if (mDNDRecorded) {
-    return;
-  }
-
-  nsCOMPtr<nsIAlertsService> alertService = components::Alerts::Service();
-  if (!alertService) {
-    return;
-  }
-
-  nsCOMPtr<nsIAlertsDoNotDisturb> alertServiceDND =
-      do_QueryInterface(alertService);
-  if (!alertServiceDND) {
-    return;
-  }
-
-  mDNDRecorded = true;
-  bool isEnabled;
-  nsresult rv = alertServiceDND->GetManualDoNotDisturb(&isEnabled);
-  if (NS_FAILED(rv)) {
-    return;
-  }
-
-  Telemetry::Accumulate(Telemetry::ALERTS_SERVICE_DND_SUPPORTED_FLAG, true);
-}
-
-NS_IMETHODIMP
-NotificationTelemetryService::Observe(nsISupports* aSubject, const char* aTopic,
-                                      const char16_t* aData) {
-  return NS_OK;
-}
-
 // Observer that the alert service calls to do common tasks and/or dispatch to
 // the specific observer for the context e.g. main thread, worker, or service
 // worker.
 class NotificationObserver final : public nsIObserver {
  public:
   nsCOMPtr<nsIObserver> mObserver;
   nsCOMPtr<nsIPrincipal> mPrincipal;
   bool mInPrivateBrowsing;
@@ -1179,23 +1060,16 @@ NotificationObserver::Observe(nsISupport
       return Notification::OpenSettings(mPrincipal);
     }
     // `ContentParent::RecvOpenNotificationSettings` notifies observers in the
     // parent process.
     ContentChild::GetSingleton()->SendOpenNotificationSettings(
         IPC::Principal(mPrincipal));
     return NS_OK;
   } else if (!strcmp("alertshow", aTopic) || !strcmp("alertfinished", aTopic)) {
-    RefPtr<NotificationTelemetryService> telemetry =
-        NotificationTelemetryService::GetInstance();
-    if (telemetry) {
-      // Record whether "do not disturb" is supported after the first
-      // notification, to account for falling back to XUL alerts.
-      telemetry->RecordDNDSupported();
-    }
     Unused << NS_WARN_IF(NS_FAILED(AdjustPushQuota(aTopic)));
   }
 
   return mObserver->Observe(aSubject, aTopic, aData);
 }
 
 nsresult NotificationObserver::AdjustPushQuota(const char* aTopic) {
   nsCOMPtr<nsIPushQuotaManager> pushQuotaManager =
--- a/dom/notification/Notification.h
+++ b/dom/notification/Notification.h
@@ -14,54 +14,28 @@
 #include "nsIObserver.h"
 #include "nsISupports.h"
 
 #include "nsCycleCollectionParticipant.h"
 #include "nsHashKeys.h"
 #include "nsTHashtable.h"
 #include "nsWeakReference.h"
 
-#define NOTIFICATIONTELEMETRYSERVICE_CONTRACTID \
-  "@mozilla.org/notificationTelemetryService;1"
-
 class nsIPrincipal;
 class nsIVariant;
 
 namespace mozilla {
 namespace dom {
 
 class NotificationRef;
 class WorkerNotificationObserver;
 class Promise;
 class StrongWorkerRef;
 class WorkerPrivate;
 
-// Records telemetry probes at application startup, when a notification is
-// shown, and when the notification permission is revoked for a site.
-class NotificationTelemetryService final : public nsIObserver {
- public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIOBSERVER
-
-  NotificationTelemetryService();
-
-  static already_AddRefed<NotificationTelemetryService> GetInstance();
-
-  nsresult Init();
-  void RecordDNDSupported();
-  void RecordPermissions();
-
- private:
-  virtual ~NotificationTelemetryService();
-
-  bool GetNotificationPermission(nsISupports* aSupports, uint32_t* aCapability);
-
-  bool mDNDRecorded;
-};
-
 /*
  * Notifications on workers introduce some lifetime issues. The property we
  * are trying to satisfy is:
  *   Whenever a task is dispatched to the main thread to operate on
  *   a Notification, the Notification should be addrefed on the worker thread
  *   and a feature should be added to observe the worker lifetime. This main
  *   thread owner should ensure it properly releases the reference to the
  *   Notification, additionally removing the feature if necessary.
@@ -115,17 +89,16 @@ class Notification : public DOMEventTarg
   friend class CloseNotificationRunnable;
   friend class NotificationTask;
   friend class NotificationPermissionRequest;
   friend class MainThreadNotificationObserver;
   friend class NotificationStorageCallback;
   friend class ServiceWorkerNotificationObserver;
   friend class WorkerGetRunnable;
   friend class WorkerNotificationObserver;
-  friend class NotificationTelemetryService;
 
  public:
   IMPL_EVENT_HANDLER(click)
   IMPL_EVENT_HANDLER(show)
   IMPL_EVENT_HANDLER(error)
   IMPL_EVENT_HANDLER(close)
 
   NS_DECL_ISUPPORTS_INHERITED
--- a/layout/build/components.conf
+++ b/layout/build/components.conf
@@ -301,23 +301,16 @@ Classes = [
     {
         'cid': '{ac9e3e82-bfbd-4f26-941e-f58c8ee178c1}',
         'contract_ids': ['@mozilla.org/no-data-protocol-content-policy;1'],
         'type': 'nsNoDataProtocolContentPolicy',
         'headers': ['/dom/base/nsNoDataProtocolContentPolicy.h'],
         'categories': {'content-policy': '@mozilla.org/no-data-protocol-content-policy;1'},
     },
     {
-        'cid': '{5995b782-6a0e-4066-aac5-276f0a9ad8cf}',
-        'contract_ids': ['@mozilla.org/notificationTelemetryService;1'],
-        'type': 'mozilla::dom::NotificationTelemetryService',
-        'headers': ['mozilla/dom/Notification.h'],
-        'init_method': 'Init',
-    },
-    {
         'cid': '{bd066e5f-146f-4472-8331-7bfd05b1ed90}',
         'contract_ids': ['@mozilla.org/nullprincipal;1'],
         'type': 'mozilla::NullPrincipal',
         'headers': ['/caps/NullPrincipal.h'],
         'init_method': 'Init',
     },
     {
         'cid': '{2a058404-fb85-44ec-8cfd-e8cbdc988dc1}',
--- a/toolkit/components/alerts/nsXULAlerts.cpp
+++ b/toolkit/components/alerts/nsXULAlerts.cpp
@@ -13,17 +13,16 @@
 #include "mozilla/dom/Notification.h"
 #include "mozilla/Unused.h"
 #include "nsIServiceManager.h"
 #include "nsISupportsPrimitives.h"
 #include "nsPIDOMWindow.h"
 #include "nsIWindowWatcher.h"
 
 using namespace mozilla;
-using mozilla::dom::NotificationTelemetryService;
 
 #define ALERT_CHROME_URL "chrome://global/content/alerts/alert.xul"
 
 namespace {
 StaticRefPtr<nsXULAlerts> gXULAlerts;
 }  // anonymous namespace
 
 NS_IMPL_CYCLE_COLLECTION(nsXULAlertObserver, mAlertWindow)
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -13344,25 +13344,16 @@
     "record_in_processes": ["main", "content"],
     "products": ["firefox", "fennec", "geckoview"],
     "alert_emails": ["firefox-dev@mozilla.org"],
     "bug_numbers": [1219030],
     "expires_in_version": "50",
     "kind": "boolean",
     "description": "XUL-only: whether the user has toggled do not disturb."
   },
-  "ALERTS_SERVICE_DND_SUPPORTED_FLAG": {
-    "record_in_processes": ["main", "content"],
-    "products": ["firefox", "fennec", "geckoview"],
-    "alert_emails": ["firefox-dev@mozilla.org"],
-    "bug_numbers": [1219030],
-    "expires_in_version": "50",
-    "kind": "flag",
-    "description": "Whether the do not disturb option is supported. True if the browser uses XUL alerts."
-  },
   "PLUGIN_DRAWING_MODEL": {
     "record_in_processes": ["main", "content"],
     "products": ["firefox", "fennec", "geckoview"],
     "alert_emails": ["gfx-telemetry-alerts@mozilla.com", "rhunt@mozilla.com"],
     "expires_in_version": "never",
     "kind": "enumerated",
     "bug_numbers": [1229961],
     "n_values": 12,
--- a/toolkit/components/telemetry/histogram-allowlists.json
+++ b/toolkit/components/telemetry/histogram-allowlists.json
@@ -1256,17 +1256,16 @@
     "GEOLOCATION_WIN8_SOURCE_IS_MLS"
   ],
   "kind": [
     "A11Y_IATABLE_USAGE_FLAG",
     "A11Y_INSTANTIATED_FLAG",
     "A11Y_ISIMPLEDOM_USAGE_FLAG",
     "ADDON_FORBIDDEN_CPOW_USAGE",
     "ADDON_MANAGER_UPGRADE_UI_SHOWN",
-    "ALERTS_SERVICE_DND_SUPPORTED_FLAG",
     "AUTO_REJECTED_TRANSLATION_OFFERS",
     "BROWSER_SHIM_USAGE_BLOCKED",
     "CANVAS_WEBGL_ACCL_FAILURE_ID",
     "CANVAS_WEBGL_FAILURE_ID",
     "CHANGES_OF_TARGET_LANGUAGE",
     "COMPONENTS_SHIM_ACCESSED_BY_CONTENT",
     "CONTENT_DOCUMENTS_DESTROYED",
     "CSP_DOCUMENTS_COUNT",