Prevent Google Mail Checker from scheduling more than one concurrent request.
In the case of failures (simulated by blackholing mail.google.com in /etc/hosts,
getInboxCount was calling onError in both the onreadystatechange and onerror
handlers). Prevent this in two ways: by only invoking the callback once and by
making scheduleRequest cancel any already-scheduled requests.
BUG=88514
TEST=no
R=mpcomplete@chromium.org
Review URL: http://codereview.chromium.org/7470036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94342 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/common/extensions/docs/examples/extensions/gmail.zip b/chrome/common/extensions/docs/examples/extensions/gmail.zip
index 123ef5a..0a735b6 100644
--- a/chrome/common/extensions/docs/examples/extensions/gmail.zip
+++ b/chrome/common/extensions/docs/examples/extensions/gmail.zip
Binary files differ
diff --git a/chrome/common/extensions/docs/examples/extensions/gmail/background.html b/chrome/common/extensions/docs/examples/extensions/gmail/background.html
index bb24259..bce2c3f 100644
--- a/chrome/common/extensions/docs/examples/extensions/gmail/background.html
+++ b/chrome/common/extensions/docs/examples/extensions/gmail/background.html
@@ -16,6 +16,7 @@
var rotation = 0;
var unreadCount = -1;
var loadingAnimation = new LoadingAnimation();
+var requestTimerId;
function getGmailUrl() {
var url = "https://mail.google.com/";
@@ -109,13 +110,16 @@
}
function scheduleRequest() {
+ if (requestTimerId) {
+ window.clearTimeout(requestTimerId);
+ }
var randomness = Math.random() * 2;
var exponent = Math.pow(2, requestFailureCount);
var multiplier = Math.max(randomness * exponent, 1);
var delay = Math.min(multiplier * pollIntervalMin, pollIntervalMax);
delay = Math.round(delay);
- window.setTimeout(startRequest, delay);
+ requestTimerId = window.setTimeout(startRequest, delay);
}
// ajax stuff
@@ -147,11 +151,13 @@
onSuccess(count);
}
+ var invokedErrorCallback = false;
function handleError() {
++requestFailureCount;
window.clearTimeout(abortTimerId);
- if (onError)
+ if (onError && !invokedErrorCallback)
onError();
+ invokedErrorCallback = true;
}
try {
diff --git a/chrome/common/extensions/docs/samples.json b/chrome/common/extensions/docs/samples.json
index 56dbf218..0addcc1e 100644
--- a/chrome/common/extensions/docs/samples.json
+++ b/chrome/common/extensions/docs/samples.json
@@ -986,7 +986,7 @@
"manifest.json",
"options.html"
],
- "source_hash": "327e6bf6005b861f17848b59dc50ebb18d1a57f4",
+ "source_hash": "6c4da0f4e9348842619fce0179f3f35ca24027ad",
"zip_path": "examples\/extensions\/gmail.zip"
},
{