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() {
if (!GetFrame()->GetSettings()->GetShouldThrottlePushState())
return false;
const int kStateUpdateLimit = 50;
if (state_flood_guard.count > kStateUpdateLimit) {
static constexpr auto kStateUpdateLimitResetInterval =
TimeDelta::FromSeconds(10);
const auto now = CurrentTimeTicks();
if (now - state_flood_guard.last_updated > kStateUpdateLimitResetInterval) {
state_flood_guard.count = 0;
state_flood_guard.last_updated = now;
return false;
}
return true;
if (state_flood_guard.tokens > 0) {
state_flood_guard.tokens--;
return false;
}
const auto now = TimeTicks::Now();
const TimeDelta elapsed = now - state_flood_guard.last_token_grant;
static constexpr base::TimeDelta kTimePerToken =
base::TimeDelta::FromMilliseconds(16);
static constexpr int kMaxTokens = 50;
// It is OK to truncate from int64_t to int here.
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++;
return false;
// Drop this event (though ideally it would be delivered once there are tokens
// again, unless obsoleted by a subsequent state object change).
return true;
}
bool History::stateChanged() const {
......
......@@ -107,8 +107,8 @@ class CORE_EXPORT History final : public ScriptWrappable,
scoped_refptr<SerializedScriptValue> last_state_object_requested_;
struct {
int count;
TimeTicks last_updated;
int tokens = 0;
TimeTicks last_token_grant;
} 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