Bug 631092 - Large number of blocklist requestors making multiple requests per day affecting the ping for metrics. r=dtownsend, a=approval2.0

This commit is contained in:
Robert Strong 2011-02-24 03:20:02 -08:00
parent 03ff4aff40
commit f951acb391
3 changed files with 88 additions and 35 deletions

View File

@ -41,7 +41,7 @@ const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
const Cr = Components.results; const Cr = Components.results;
const PREF_BLOCKLIST_PINGCOUNT = "extensions.blocklist.pingCount"; const PREF_BLOCKLIST_PINGCOUNTVERSION = "extensions.blocklist.pingCountVersion";
const PREF_EM_UPDATE_ENABLED = "extensions.update.enabled"; const PREF_EM_UPDATE_ENABLED = "extensions.update.enabled";
const PREF_EM_LAST_APP_VERSION = "extensions.lastAppVersion"; const PREF_EM_LAST_APP_VERSION = "extensions.lastAppVersion";
const PREF_EM_AUTOUPDATE_DEFAULT = "extensions.update.autoUpdateDefault"; const PREF_EM_AUTOUPDATE_DEFAULT = "extensions.update.autoUpdateDefault";
@ -241,7 +241,7 @@ var AddonManagerInternal = {
LOG("Application has been upgraded"); LOG("Application has been upgraded");
Services.prefs.setCharPref(PREF_EM_LAST_APP_VERSION, Services.prefs.setCharPref(PREF_EM_LAST_APP_VERSION,
Services.appinfo.version); Services.appinfo.version);
Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNT, Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTVERSION,
(appChanged === undefined ? 0 : -1)); (appChanged === undefined ? 0 : -1));
} }

View File

@ -58,8 +58,8 @@ const PREF_BLOCKLIST_URL = "extensions.blocklist.url";
const PREF_BLOCKLIST_ENABLED = "extensions.blocklist.enabled"; const PREF_BLOCKLIST_ENABLED = "extensions.blocklist.enabled";
const PREF_BLOCKLIST_INTERVAL = "extensions.blocklist.interval"; const PREF_BLOCKLIST_INTERVAL = "extensions.blocklist.interval";
const PREF_BLOCKLIST_LEVEL = "extensions.blocklist.level"; const PREF_BLOCKLIST_LEVEL = "extensions.blocklist.level";
const PREF_BLOCKLIST_PINGCOUNT = "extensions.blocklist.pingCount"; const PREF_BLOCKLIST_PINGCOUNTTOTAL = "extensions.blocklist.pingCountTotal";
const PREF_BLOCKLIST_TOTALPINGCOUNT = "extensions.blocklist.totalPingCount"; const PREF_BLOCKLIST_PINGCOUNTVERSION = "extensions.blocklist.pingCountVersion";
const PREF_PLUGINS_NOTIFYUSER = "plugins.update.notifyUser"; const PREF_PLUGINS_NOTIFYUSER = "plugins.update.notifyUser";
const PREF_GENERAL_USERAGENT_LOCALE = "general.useragent.locale"; const PREF_GENERAL_USERAGENT_LOCALE = "general.useragent.locale";
const PREF_PARTNER_BRANCH = "app.partner."; const PREF_PARTNER_BRANCH = "app.partner.";
@ -429,24 +429,31 @@ Blocklist.prototype = {
return; return;
} }
var pingCount = getPref("getIntPref", PREF_BLOCKLIST_PINGCOUNT, 0); var pingCountVersion = getPref("getIntPref", PREF_BLOCKLIST_PINGCOUNTVERSION, 0);
var totalPingCount = getPref("getIntPref", PREF_BLOCKLIST_TOTALPINGCOUNT, 1); var pingCountTotal = getPref("getIntPref", PREF_BLOCKLIST_PINGCOUNTTOTAL, 1);
var daysSinceLastPing; var daysSinceLastPing = 0;
if (pingCount < 1) { if (pingCountVersion < 1 || pingCountTotal < 1) {
daysSinceLastPing = pingCount == 0 ? "new" : "reset"; daysSinceLastPing = pingCountVersion == 0 ? "new" : "reset";
pingCount = 1; if (pingCountVersion < 1)
pingCountVersion = 1;
if (pingCountTotal < 1)
pingCountTotal = 1;
} }
else { else {
// Seconds in one day is used because nsIUpdateTimerManager stores the // Seconds in one day is used because nsIUpdateTimerManager stores the
// last update time in seconds. // last update time in seconds.
let secondsInDay = 60 * 60 * 24; let secondsInDay = 60 * 60 * 24;
let lastUpdateTime = getPref("getIntPref", PREF_BLOCKLIST_LASTUPDATETIME, 0); let lastUpdateTime = getPref("getIntPref", PREF_BLOCKLIST_LASTUPDATETIME, 0);
if (lastUpdateTime != 0) { if (lastUpdateTime == 0) {
daysSinceLastPing = "invalid";
}
else {
let now = Math.round(Date.now() / 1000); let now = Math.round(Date.now() / 1000);
daysSinceLastPing = Math.floor((now - lastUpdateTime) / secondsInDay); daysSinceLastPing = Math.floor((now - lastUpdateTime) / secondsInDay);
} }
else {
daysSinceLastPing = "invalid"; if (daysSinceLastPing == 0 || daysSinceLastPing == "invalid") {
pingCountVersion = pingCountTotal = "invalid";
} }
} }
@ -464,29 +471,33 @@ Blocklist.prototype = {
getDistributionPrefValue(PREF_APP_DISTRIBUTION)); getDistributionPrefValue(PREF_APP_DISTRIBUTION));
dsURI = dsURI.replace(/%DISTRIBUTION_VERSION%/g, dsURI = dsURI.replace(/%DISTRIBUTION_VERSION%/g,
getDistributionPrefValue(PREF_APP_DISTRIBUTION_VERSION)); getDistributionPrefValue(PREF_APP_DISTRIBUTION_VERSION));
dsURI = dsURI.replace(/%PING_COUNT%/g, pingCount); dsURI = dsURI.replace(/%PING_COUNT%/g, pingCountVersion);
dsURI = dsURI.replace(/%TOTAL_PING_COUNT%/g, totalPingCount); dsURI = dsURI.replace(/%TOTAL_PING_COUNT%/g, pingCountTotal);
dsURI = dsURI.replace(/%DAYS_SINCE_LAST_PING%/g, daysSinceLastPing); dsURI = dsURI.replace(/%DAYS_SINCE_LAST_PING%/g, daysSinceLastPing);
dsURI = dsURI.replace(/\+/g, "%2B"); dsURI = dsURI.replace(/\+/g, "%2B");
// Under normal operations it will take around 5,883,516 years before the // Under normal operations it will take around 5,883,516 years before the
// preferences used to store pingCount and totalPingCount will rollover // preferences used to store pingCountVersion and pingCountTotal will rollover
// so this code doesn't bother trying to do the "right thing" here. // so this code doesn't bother trying to do the "right thing" here.
pingCount++; if (pingCountVersion != "invalid") {
if (pingCount > 2147483647) { pingCountVersion++;
// Rollover to -1 if the value is greater than what is support by an if (pingCountVersion > 2147483647) {
// integer preference. The -1 indicates that the counter has been reset. // Rollover to -1 if the value is greater than what is support by an
pingCount = -1; // integer preference. The -1 indicates that the counter has been reset.
pingCountVersion = -1;
}
gPref.setIntPref(PREF_BLOCKLIST_PINGCOUNTVERSION, pingCountVersion);
} }
gPref.setIntPref(PREF_BLOCKLIST_PINGCOUNT, pingCount);
totalPingCount++; if (pingCountTotal != "invalid") {
if (totalPingCount > 2147483647) { pingCountTotal++;
// Rollover to 1 if the value is greater than what is support by an if (pingCountTotal > 2147483647) {
// integer preference. // Rollover to 1 if the value is greater than what is support by an
totalPingCount = 1; // integer preference.
pingCountTotal = -1;
}
gPref.setIntPref(PREF_BLOCKLIST_PINGCOUNTTOTAL, pingCountTotal);
} }
gPref.setIntPref(PREF_BLOCKLIST_TOTALPINGCOUNT, totalPingCount);
// Verify that the URI is valid // Verify that the URI is valid
try { try {

View File

@ -4,8 +4,9 @@
do_load_httpd_js(); do_load_httpd_js();
const PREF_BLOCKLIST_LASTUPDATETIME = "app.update.lastUpdateTime.blocklist-background-update-timer"; const PREF_BLOCKLIST_LASTUPDATETIME = "app.update.lastUpdateTime.blocklist-background-update-timer";
const PREF_BLOCKLIST_PINGCOUNT = "extensions.blocklist.pingCount"; const PREF_BLOCKLIST_PINGCOUNTTOTAL = "extensions.blocklist.pingCountTotal";
const PREF_BLOCKLIST_PINGCOUNTVERSION = "extensions.blocklist.pingCountVersion";
const SECONDS_IN_DAY = 60 * 60 * 24; const SECONDS_IN_DAY = 60 * 60 * 24;
@ -50,7 +51,7 @@ function test1() {
function test2() { function test2() {
gNextTest = test3; gNextTest = test3;
gExpectedQueryString = "2&2&invalid"; gExpectedQueryString = "invalid&invalid&invalid";
notify_blocklist(); notify_blocklist();
} }
@ -58,24 +59,65 @@ function test3() {
Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
(getNowInSeconds() - SECONDS_IN_DAY)); (getNowInSeconds() - SECONDS_IN_DAY));
gNextTest = test4; gNextTest = test4;
gExpectedQueryString = "3&3&1"; gExpectedQueryString = "2&2&1";
notify_blocklist(); notify_blocklist();
} }
function test4() { function test4() {
Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNT, -1); Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTVERSION, -1);
Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
(getNowInSeconds() - (SECONDS_IN_DAY * 2))); (getNowInSeconds() - (SECONDS_IN_DAY * 2)));
gNextTest = test5; gNextTest = test5;
gExpectedQueryString = "1&4&reset"; gExpectedQueryString = "1&3&reset";
notify_blocklist(); notify_blocklist();
} }
function test5() { function test5() {
Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, getNowInSeconds());
gNextTest = test6;
gExpectedQueryString = "invalid&invalid&0";
notify_blocklist();
}
function test6() {
Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
(getNowInSeconds() - (SECONDS_IN_DAY * 3))); (getNowInSeconds() - (SECONDS_IN_DAY * 3)));
gNextTest = test7;
gExpectedQueryString = "2&4&3";
notify_blocklist();
}
function test7() {
Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTVERSION, 2147483647);
Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
(getNowInSeconds() - (SECONDS_IN_DAY * 4)));
gNextTest = test8;
gExpectedQueryString = "2147483647&5&4";
notify_blocklist();
}
function test8() {
Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
(getNowInSeconds() - (SECONDS_IN_DAY * 5)));
gNextTest = test9;
gExpectedQueryString = "1&6&reset";
notify_blocklist();
}
function test9() {
Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTTOTAL, 2147483647);
Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
(getNowInSeconds() - (SECONDS_IN_DAY * 6)));
gNextTest = test10;
gExpectedQueryString = "2&2147483647&6";
notify_blocklist();
}
function test10() {
Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
(getNowInSeconds() - (SECONDS_IN_DAY * 7)));
gNextTest = finish; gNextTest = finish;
gExpectedQueryString = "2&5&3"; gExpectedQueryString = "3&1&reset";
notify_blocklist(); notify_blocklist();
} }