Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: chrome/ext/background.js

Issue 6615790883176448: Issue 2034 - Respect chrome.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES (Closed)
Patch Set: Created Feb. 23, 2015, 5:18 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webrequest.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/ext/background.js
===================================================================
--- a/chrome/ext/background.js
+++ b/chrome/ext/background.js
@@ -326,9 +326,58 @@
return (framesOfTabs[tabId] || {})[frameId];
};
+ var handlerBehaviorChangedQuota = chrome.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES;
+ var handlerBehaviorChangedQuotaExceeded = false;
+ var handlerBehaviorChangedPending = false;
+
+ function handlerBehaviorChanged()
+ {
+ chrome.webRequest.handlerBehaviorChanged();
+ handlerBehaviorChangedQuota--;
+
+ // Make sure to not call handlerBehaviorChanged() more often than allowed
+ // by chrome.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES.
+ // Otherwise Chrome notifies the user that this extension is causing issues.
+ setTimeout(function()
+ {
+ handlerBehaviorChangedQuota++;
+
+ // If the quota were exceeded, call handlerBehaviorChanged()
+ // delayed, when 10 minutes since the first call within the
+ // past 10 minutes passed.
+ if (handlerBehaviorChangedQuotaExceeded)
+ {
+ handlerBehaviorChangedQuotaExceeded = false;
+ handlerBehaviorChanged();
+ }
+ }, 600000);
+ }
Wladimir Palant 2015/02/23 18:25:26 Is this really a good approach? I think that we sh
Sebastian Noack 2015/02/23 19:12:08 We call handlerBehaviorChanged() only if it did. T
Wladimir Palant 2015/02/23 19:22:42 If users are changing filters frequently (more oft
Sebastian Noack 2015/04/09 07:04:55 How about this: The new patch defers handlerBehavi
+
ext.webRequest = {
onBeforeRequest: new ext._EventTarget(),
- handlerBehaviorChanged: chrome.webRequest.handlerBehaviorChanged
+ handlerBehaviorChanged: function()
+ {
+ if (handlerBehaviorChangedQuota > 0)
+ {
+ // Call handlerBehaviorChanged() asynchronously, and only if it
+ // hasn't been scheduled yet. That way we avoid to call it multiple
+ // times, if multiple filters were added/removed simultanously.
+ if (!handlerBehaviorChangedPending)
+ {
+ handlerBehaviorChangedPending = true;
+
+ setTimeout(function()
+ {
+ handlerBehaviorChanged();
+ handlerBehaviorChangedPending = false;
+ }, 0);
+ }
+ }
+ else
+ {
+ handlerBehaviorChangedQuotaExceeded = true;
+ }
+ }
};
chrome.tabs.query({}, function(tabs)
« no previous file with comments | « no previous file | webrequest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld