Commit 7c97bc65 authored by Maks Orlovich's avatar Maks Orlovich Committed by Commit Bot

Fix handling of negative max_size in ::SimpleBackendImpl

Change-Id: I9d66473203995ff21d915b17cffa42c44f84a000
Reviewed-on: https://chromium-review.googlesource.com/598108
Commit-Queue: Maks Orlovich <morlovich@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491399}
parent e95247e5
......@@ -3998,6 +3998,24 @@ TEST_F(DiskCacheBackendTest, SimpleCacheLateDoom) {
simple_cache_impl_->index()->init_method());
}
TEST_F(DiskCacheBackendTest, SimpleCacheNegMaxSize) {
SetMaxSize(-1);
SetSimpleCacheMode();
InitCache();
// We don't know what it will pick, but it's limited to what
// disk_cache::PreferredCacheSize would return, scaled by the size experiment,
// which only goes as much as 2x. It definitely should not be MAX_UINT64.
EXPECT_NE(simple_cache_impl_->index()->max_size(),
std::numeric_limits<uint64_t>::max());
int max_default_size =
2 * disk_cache::PreferredCacheSize(std::numeric_limits<int32_t>::max());
ASSERT_GE(max_default_size, 0);
EXPECT_LT(simple_cache_impl_->index()->max_size(),
static_cast<unsigned>(max_default_size));
}
TEST_F(DiskCacheBackendTest, SimpleLastModified) {
// Simple cache used to incorrectly set LastModified on entries based on
// timestamp of the cache directory, and not the entries' file
......
......@@ -263,6 +263,10 @@ SimpleBackendImpl::SimpleBackendImpl(
? SimpleEntryImpl::OPTIMISTIC_OPERATIONS
: SimpleEntryImpl::NON_OPTIMISTIC_OPERATIONS),
net_log_(net_log) {
// Treat negative passed-in sizes same as SetMaxSize would here and in other
// backends, as default (if first call).
if (orig_max_size_ < 0)
orig_max_size_ = 0;
MaybeHistogramFdLimit(cache_type_);
}
......
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