Commit 334031b2 authored by Takashi Toyoshima's avatar Takashi Toyoshima Committed by Commit Bot

OOR-CORS: Adjust CORS preflight cache size

To ensure that the cache size can not be too large,
we have the maximum cache entries limit. We change
the limit to 1024, and also introduces the key size
limit since the URL can be too long in some cases.

Bug: 962824
Change-Id: I3252c68a46dfcfc78cdac6d05a3a2481aace7527
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1609727Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Commit-Queue: Takashi Toyoshima <toyoshim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659430}
parent e85db559
......@@ -16,7 +16,8 @@ namespace network {
namespace cors {
namespace {
constexpr size_t kMaxCacheEntries = 4096;
constexpr size_t kMaxCacheEntries = 1024u;
constexpr size_t kMaxKeyLength = 512u;
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
......@@ -44,12 +45,16 @@ void PreflightCache::AppendEntry(
std::unique_ptr<PreflightResult> preflight_result) {
DCHECK(preflight_result);
// Do not cache |preflight_result| if |url| is too long.
const std::string& key = url.spec();
if (key.length() >= kMaxKeyLength)
return;
// Since one new entry is always added below, let's purge one cache entry
// if cache size is larger than kMaxCacheEntries - 1 so that the size to be
// kMaxCacheEntries at maximum.
MayPurge(kMaxCacheEntries - 1);
const std::string& key = url.spec();
UMA_HISTOGRAM_COUNTS_1000("Net.Cors.PreflightCacheKeySize", key.length());
UMA_HISTOGRAM_COUNTS_10000("Net.Cors.PreflightCacheValueSize",
preflight_result->EstimateMemoryPressureInBytes());
......
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