Bug 1518326 - Sanity check US region against timezone. r=adw
authorMichael Kaply <mozilla@kaply.com>
Tue, 15 Jan 2019 22:16:52 +0000
changeset 511207 d7f17000fa1cde11afdce450af71f9e08fcfd04a
parent 511206 a41a7e9cdf4e84446a85f3d0fa5c8c06a4e1a92a
child 511208 364d70626f4b348628e33e627e42353fad91b5fd
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs1518326
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 1518326 - Sanity check US region against timezone. r=adw Differential Revision: https://phabricator.services.mozilla.com/D16073
browser/components/nsBrowserGlue.js
toolkit/components/search/nsSearchService.js
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -2187,17 +2187,17 @@ BrowserGlue.prototype = {
       }
     }
   },
 
   // eslint-disable-next-line complexity
   _migrateUI: function BG__migrateUI() {
     // Use an increasing number to keep track of the current migration state.
     // Completely unrelated to the current Firefox release number.
-    const UI_VERSION = 77;
+    const UI_VERSION = 78;
     const BROWSER_DOCURL = AppConstants.BROWSER_CHROME_URL;
 
     let currentUIVersion;
     if (Services.prefs.prefHasUserValue("browser.migration.version")) {
       currentUIVersion = Services.prefs.getIntPref("browser.migration.version");
     } else {
       // This is a new profile, nothing to migrate.
       Services.prefs.setIntPref("browser.migration.version", UI_VERSION);
@@ -2526,20 +2526,16 @@ BrowserGlue.prototype = {
                         { ignoreAbsent: true });
       for (const filename of ["addons.json", "plugins.json", "gfx.json"]) {
         // Some old versions used to dump without subfolders. Clean them while we are at it.
         const path = OS.Path.join(OS.Constants.Path.profileDir, `blocklists-${filename}`);
         OS.File.remove(path, { ignoreAbsent: true });
       }
     }
 
-    if (currentUIVersion < 74) {
-      Services.prefs.clearUserPref("browser.search.region");
-    }
-
     if (currentUIVersion < 75) {
       // Ensure we try to migrate any live bookmarks the user might have, trying up to
       // 5 times. We set this early, and here, to avoid running the migration on
       // new profile (or, indeed, ever creating the pref there).
       Services.prefs.setIntPref("browser.livebookmarks.migrationAttemptsLeft", 5);
     }
 
     if (currentUIVersion < 76) {
@@ -2556,16 +2552,20 @@ BrowserGlue.prototype = {
     if (currentUIVersion < 77) {
       // Remove currentset from all the toolbars
       let toolbars = ["nav-bar", "PersonalToolbar", "TabsToolbar", "toolbar-menubar"];
       for (let toolbarId of toolbars) {
         xulStore.removeValue(BROWSER_DOCURL, toolbarId, "currentset");
       }
     }
 
+    if (currentUIVersion < 78) {
+      Services.prefs.clearUserPref("browser.search.region");
+    }
+
     // Update the migration version.
     Services.prefs.setIntPref("browser.migration.version", UI_VERSION);
   },
 
   _checkForDefaultBrowser() {
     // Perform default browser checking.
     if (!ShellService) {
       return;
--- a/toolkit/components/search/nsSearchService.js
+++ b/toolkit/components/search/nsSearchService.js
@@ -435,23 +435,30 @@ var ensureKnownRegion = async function(s
   // If gInitialized is true then the search service was forced to perform
   // a sync initialization during our XHRs - capture this via telemetry.
   Services.telemetry.getHistogramById("SEARCH_SERVICE_COUNTRY_FETCH_CAUSED_SYNC_INIT").add(gInitialized);
 };
 
 // Store the result of the geoip request as well as any other values and
 // telemetry which depend on it.
 function storeRegion(region) {
-  Services.prefs.setCharPref("browser.search.region", region);
+  let isTimezoneUS = isUSTimezone();
+  // If it's a US region, but not a US timezone, we don't store the value.
+  // This works because no region defaults to ZZ (unknown) in nsURLFormatter
+  if (region != "US" || isTimezoneUS) {
+    Services.prefs.setCharPref("browser.search.region", region);
+  }
+
   // and telemetry...
-  let isTimezoneUS = isUSTimezone();
   if (region == "US" && !isTimezoneUS) {
+    LOG("storeRegion mismatch - US Region, non-US timezone");
     Services.telemetry.getHistogramById("SEARCH_SERVICE_US_COUNTRY_MISMATCHED_TIMEZONE").add(1);
   }
   if (region != "US" && isTimezoneUS) {
+    LOG("storeRegion mismatch - non-US Region, US timezone");
     Services.telemetry.getHistogramById("SEARCH_SERVICE_US_TIMEZONE_MISMATCHED_COUNTRY").add(1);
   }
   // telemetry to compare our geoip response with platform-specific country data.
   // On Mac and Windows, we can get a country code via sysinfo
   let platformCC = Services.sysinfo.get("countryCode");
   if (platformCC) {
     let probeUSMismatched, probeNonUSMismatched;
     switch (Services.appinfo.OS) {