Commit 1f637a1a authored by Chris Palmer's avatar Chris Palmer Committed by Commit Bot

Soften the history.{push,replace}State throttling mechanism.

johnme@ suggests a better way to handle it; let's do that.

Bug: 786211
Change-Id: I446c70117451d2ef49ce13f5884ebb858d9ee392
Reviewed-on: https://chromium-review.googlesource.com/1161400
Commit-Queue: Chris Palmer <palmer@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580455}
parent 5a599ae2
...@@ -148,22 +148,28 @@ bool History::ShouldThrottleStateObjectChanges() { ...@@ -148,22 +148,28 @@ bool History::ShouldThrottleStateObjectChanges() {
if (!GetFrame()->GetSettings()->GetShouldThrottlePushState()) if (!GetFrame()->GetSettings()->GetShouldThrottlePushState())
return false; return false;
const int kStateUpdateLimit = 50; if (state_flood_guard.tokens > 0) {
state_flood_guard.tokens--;
if (state_flood_guard.count > kStateUpdateLimit) { return false;
static constexpr auto kStateUpdateLimitResetInterval = }
TimeDelta::FromSeconds(10);
const auto now = CurrentTimeTicks(); const auto now = TimeTicks::Now();
if (now - state_flood_guard.last_updated > kStateUpdateLimitResetInterval) { const TimeDelta elapsed = now - state_flood_guard.last_token_grant;
state_flood_guard.count = 0; static constexpr base::TimeDelta kTimePerToken =
state_flood_guard.last_updated = now; base::TimeDelta::FromMilliseconds(16);
return false; static constexpr int kMaxTokens = 50;
} // It is OK to truncate from int64_t to int here.
return true; const int tokens_earned = std::min<int>(elapsed / kTimePerToken, kMaxTokens);
if (tokens_earned > 0) {
state_flood_guard.tokens = tokens_earned - 1; // One consumed immediately.
state_flood_guard.last_token_grant = now;
return false;
} }
state_flood_guard.count++; // Drop this event (though ideally it would be delivered once there are tokens
return false; // again, unless obsoleted by a subsequent state object change).
return true;
} }
bool History::stateChanged() const { bool History::stateChanged() const {
......
...@@ -107,8 +107,8 @@ class CORE_EXPORT History final : public ScriptWrappable, ...@@ -107,8 +107,8 @@ class CORE_EXPORT History final : public ScriptWrappable,
scoped_refptr<SerializedScriptValue> last_state_object_requested_; scoped_refptr<SerializedScriptValue> last_state_object_requested_;
struct { struct {
int count; int tokens = 0;
TimeTicks last_updated; TimeTicks last_token_grant;
} state_flood_guard; } state_flood_guard;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment