Commit ad2f5b9f authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

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

This reverts commit 1f637a1a.

Reason for revert: Part 2 of trying to revert history throttling changes to see if https://bugs.chromium.org/p/chromium/issues/detail?id=870861 improves.

Original change's description:
> 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: Daniel Cheng <dcheng@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#580455}

TBR=palmer@chromium.org,dcheng@chromium.org,kinuko@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 786211
Change-Id: Ia6a35add136361834c3afb40295b950c05cb9169
Reviewed-on: https://chromium-review.googlesource.com/1171709Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582434}
parent 31322898
......@@ -148,28 +148,22 @@ bool History::ShouldThrottleStateObjectChanges() {
if (!GetFrame()->GetSettings()->GetShouldThrottlePushState())
return false;
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;
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;
}
// Drop this event (though ideally it would be delivered once there are tokens
// again, unless obsoleted by a subsequent state object change).
return true;
state_flood_guard.count++;
return false;
}
bool History::stateChanged() const {
......
......@@ -107,8 +107,8 @@ class CORE_EXPORT History final : public ScriptWrappable,
scoped_refptr<SerializedScriptValue> last_state_object_requested_;
struct {
int tokens = 0;
TimeTicks last_token_grant;
int count;
TimeTicks last_updated;
} 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