From 769856eeb59b47712e62a5342659d3ac8a697633 Mon Sep 17 00:00:00 2001 From: Mark Hammond Date: Thu, 12 Feb 2015 12:49:18 +1100 Subject: [PATCH] Bug 1130132 - add telemetry to determine how consistent our geoip country code is with Windows. r=gavin --- toolkit/components/search/nsSearchService.js | 34 ++++++++++++++----- .../search/tests/xpcshell/test_location.js | 32 +++++++++++------ toolkit/components/telemetry/Histograms.json | 12 +++++++ 3 files changed, 59 insertions(+), 19 deletions(-) diff --git a/toolkit/components/search/nsSearchService.js b/toolkit/components/search/nsSearchService.js index 224b7c5f4542..8edad71a4e5e 100644 --- a/toolkit/components/search/nsSearchService.js +++ b/toolkit/components/search/nsSearchService.js @@ -555,21 +555,37 @@ function storeCountryCode(cc) { Services.telemetry.getHistogramById("SEARCH_SERVICE_US_TIMEZONE_MISMATCHED_COUNTRY").add(1); } // telemetry to compare our geoip response with platform-specific country data. - // On Mac, we can get a country code via nsIGfxInfo2 + // On Mac and Windows, we can get a country code via nsIGfxInfo2 let gfxInfo2; try { gfxInfo2 = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo2); } catch (ex) { - // not on Mac. + // not available on this platform. } if (gfxInfo2) { - let macCC = gfxInfo2.countryCode; - if (cc == "US" || macCC == "US") { - // one of the 2 said US, so record if they are the same. - Services.telemetry.getHistogramById("SEARCH_SERVICE_US_COUNTRY_MISMATCHED_PLATFORM_OSX").add(cc != macCC); - } else { - // different country - record if they are the same - Services.telemetry.getHistogramById("SEARCH_SERVICE_NONUS_COUNTRY_MISMATCHED_PLATFORM_OSX").add(cc != macCC); + let probeUSMismatched, probeNonUSMismatched; + switch (Services.appinfo.OS) { + case "Darwin": + probeUSMismatched = "SEARCH_SERVICE_US_COUNTRY_MISMATCHED_PLATFORM_OSX"; + probeNonUSMismatched = "SEARCH_SERVICE_NONUS_COUNTRY_MISMATCHED_PLATFORM_OSX"; + break; + case "WINNT": + probeUSMismatched = "SEARCH_SERVICE_US_COUNTRY_MISMATCHED_PLATFORM_WIN"; + probeNonUSMismatched = "SEARCH_SERVICE_NONUS_COUNTRY_MISMATCHED_PLATFORM_WIN"; + break; + default: + Cu.reportError("Platform " + Services.appinfo.OS + " has nsIGfxInfo2 but no search service telemetry probes"); + break; + } + if (probeUSMismatched && probeNonUSMismatched) { + let platformCC = gfxInfo2.countryCode; + if (cc == "US" || platformCC == "US") { + // one of the 2 said US, so record if they are the same. + Services.telemetry.getHistogramById(probeUSMismatched).add(cc != platformCC); + } else { + // different country - record if they are the same + Services.telemetry.getHistogramById(probeNonUSMismatched).add(cc != platformCC); + } } } } diff --git a/toolkit/components/search/tests/xpcshell/test_location.js b/toolkit/components/search/tests/xpcshell/test_location.js index afdb6b4b56ac..cc569480b5b9 100644 --- a/toolkit/components/search/tests/xpcshell/test_location.js +++ b/toolkit/components/search/tests/xpcshell/test_location.js @@ -24,22 +24,34 @@ function run_test() { // simple checks for our platform-specific telemetry. We can't influence // what they return (as we can't influence the countryCode the platform // thinks we are in), but we can check the values are correct given reality. - // NOTE: head_search.js mocks the XULRuntime values, but saves the original - // OS in an OS global - if (Services.appinfo.OS == "Darwin") { + let probeUSMismatched, probeNonUSMismatched; + switch (Services.appinfo.OS) { + case "Darwin": + probeUSMismatched = "SEARCH_SERVICE_US_COUNTRY_MISMATCHED_PLATFORM_OSX"; + probeNonUSMismatched = "SEARCH_SERVICE_NONUS_COUNTRY_MISMATCHED_PLATFORM_OSX"; + break; + case "WINNT": + probeUSMismatched = "SEARCH_SERVICE_US_COUNTRY_MISMATCHED_PLATFORM_WIN"; + probeNonUSMismatched = "SEARCH_SERVICE_NONUS_COUNTRY_MISMATCHED_PLATFORM_WIN"; + break; + default: + break; + } + + if (probeUSMismatched && probeNonUSMismatched) { let gfxInfo2 = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo2); - print("OSX says the country-code is", gfxInfo2.countryCode); + print("Platform says the country-code is", gfxInfo2.countryCode); let expectedResult; let hid; - // We know geoip said AU - if mac thinks US then we expect - // SEARCH_SERVICE_US_COUNTRY_MISMATCHED_PLATFORM_OSX with true (ie, a mismatch) + // We know geoip said AU - if the platform thinks US then we expect + // probeUSMismatched with true (ie, a mismatch) if (gfxInfo2.countryCode == "US") { - hid = "SEARCH_SERVICE_US_COUNTRY_MISMATCHED_PLATFORM_OSX"; + hid = probeUSMismatched; expectedResult = [0,1,0]; // boolean probe so 3 buckets, expect 1 result for |1|. } else { - // We are expecting SEARCH_SERVICE_NONUS_COUNTRY_MISMATCHED_PLATFORM_OSX - // with false if OSX says AU (not a mismatch) and true otherwise. - hid = "SEARCH_SERVICE_NONUS_COUNTRY_MISMATCHED_PLATFORM_OSX"; + // We are expecting probeNonUSMismatched with false if the platform + // says AU (not a mismatch) and true otherwise. + hid = probeNonUSMismatched; expectedResult = gfxInfo2.countryCode == "AU" ? [1,0,0] : [0,1,0]; } diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index 0899137d4348..0566cc8c7534 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -4671,6 +4671,18 @@ "kind": "boolean", "description": "If we are on OSX and neither the OSX countryCode nor the geoip countryCode indicates we are in the US, set to false if they both agree on the value or true otherwise" }, + "SEARCH_SERVICE_US_COUNTRY_MISMATCHED_PLATFORM_WIN": { + "alert_emails": ["mhammond@mozilla.com", "gavin@mozilla.com"], + "expires_in_version": "never", + "kind": "boolean", + "description": "If we are on Windows and either the Windows countryCode or the geoip countryCode indicates we are in the US, set to false if they both do or true otherwise" + }, + "SEARCH_SERVICE_NONUS_COUNTRY_MISMATCHED_PLATFORM_WIN": { + "alert_emails": ["mhammond@mozilla.com", "gavin@mozilla.com"], + "expires_in_version": "never", + "kind": "boolean", + "description": "If we are on Windows and neither the Windows countryCode nor the geoip countryCode indicates we are in the US, set to false if they both agree on the value or true otherwise" + }, "SOCIAL_ENABLED_ON_SESSION": { "expires_in_version": "never", "kind": "flag",