Bug 1657083 - Make sendTopSiteAttributionRequest optional. r=mikedeboer
authorDão Gottwald <dao@mozilla.com>
Thu, 20 Aug 2020 14:46:11 +0000
changeset 610155 500009648a7cfe02b1534f092d5e148782c8b768
parent 610154 da2ca8466508070950b870a6906a595e690abdd3
child 610156 00693a1768762d0199817ac1b929ef67c5519809
push id13553
push userffxbld-merge
push dateMon, 24 Aug 2020 12:51:36 +0000
treeherdermozilla-beta@a54f8b5d0977 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1657083
milestone81.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 1657083 - Make sendTopSiteAttributionRequest optional. r=mikedeboer Differential Revision: https://phabricator.services.mozilla.com/D87599
browser/components/newtab/karma.mc.config.js
browser/components/newtab/lib/TopSitesFeed.jsm
--- a/browser/components/newtab/karma.mc.config.js
+++ b/browser/components/newtab/karma.mc.config.js
@@ -82,18 +82,18 @@ module.exports = function(config) {
             },
             "lib/UTEventReporting.jsm": {
               statements: 100,
               lines: 100,
               functions: 100,
               branches: 75,
             },
             "lib/TopSitesFeed.jsm": {
-              statements: 94,
-              lines: 94,
+              statements: 80,
+              lines: 80,
               functions: 97,
               branches: 84,
             },
             "lib/Screenshots.jsm": {
               statements: 94,
               lines: 94,
               functions: 100,
               branches: 84,
--- a/browser/components/newtab/lib/TopSitesFeed.jsm
+++ b/browser/components/newtab/lib/TopSitesFeed.jsm
@@ -191,24 +191,54 @@ this.TopSitesFeed = class TopSitesFeed {
 
     if (!this._useRemoteSetting) {
       this.refreshDefaults(
         this.store.getState().Prefs.values[DEFAULT_SITES_PREF]
       );
       return;
     }
 
+    // Read override pref if present.
     let sites;
     try {
       sites = Services.prefs.getStringPref(REMOTE_SETTING_OVERRIDE_PREF);
-    } catch (e) {
-      // Placeholder for the actual remote setting (bug 1653937).
-      sites = "https://mozilla.org/#%YYYYMMDDHH%,https://firefox.com";
+    } catch (e) {}
+    if (sites) {
+      this.refreshDefaults(sites);
+      return;
     }
-    this.refreshDefaults(sites);
+
+    // Read defaults from remote settings.
+    // Placeholder for the actual remote setting (bug 1653937).
+    let remoteSettingData = [
+      {
+        title: "Mozilla!",
+        url: "https://mozilla.org/#%YYYYMMDDHH%",
+        send_attribution_request: true,
+      },
+      {
+        url: "https://firefox.com",
+      },
+    ];
+
+    // Clear out the array of any previous defaults.
+    DEFAULT_TOP_SITES.length = 0;
+
+    for (let siteData of remoteSettingData) {
+      let link = {
+        isDefault: true,
+        url: siteData.url,
+        hostname: shortURL(siteData),
+        sendTopSiteAttributionRequest: !!siteData.send_attribution_request,
+      };
+      if (siteData.title) {
+        link.label = siteData.title;
+      }
+      DEFAULT_TOP_SITES.push(link);
+    }
   }
 
   refreshDefaults(sites) {
     // Clear out the array of any previous defaults
     DEFAULT_TOP_SITES.length = 0;
 
     // Add default sites if any based on the pref
     if (sites) {
@@ -371,18 +401,16 @@ this.TopSitesFeed = class TopSitesFeed {
       pad(date.getMonth() + 1) +
       pad(date.getDate());
     let yyyymmddhh = yyyymmdd + pad(date.getHours());
     let notBlockedDefaultSites = [];
     for (let link of DEFAULT_TOP_SITES) {
       if (this._useRemoteSetting) {
         link = {
           ...link,
-          // This should be optional (bug 1657083):
-          sendTopSiteAttributionRequest: link.isDefault,
           url: link.url.replace("%YYYYMMDDHH%", yyyymmddhh),
         };
       }
       // Remove any defaults that have been blocked.
       if (NewTabUtils.blockedLinks.isBlocked({ url: link.url })) {
         continue;
       }
       if (this.shouldFilterSearchTile(link.hostname)) {