Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Unified Diff: net/disk_cache/memory/mem_entry_impl.cc

Issue 2784803004: [HTTP Cache] Prevent memory backend from exceeding its max size (Closed)
Patch Set: Address comments from PS4 Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/disk_cache/memory/mem_backend_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/memory/mem_entry_impl.cc
diff --git a/net/disk_cache/memory/mem_entry_impl.cc b/net/disk_cache/memory/mem_entry_impl.cc
index 2910bb1afafa1396af0d0d408d8a433afbdefc4b..499142a3a3e394572bcfc1d3ffe75cef277b1f3a 100644
--- a/net/disk_cache/memory/mem_entry_impl.cc
+++ b/net/disk_cache/memory/mem_entry_impl.cc
@@ -81,6 +81,8 @@ MemEntryImpl::MemEntryImpl(MemBackendImpl* backend,
nullptr, // parent
net_log) {
Open();
+ // Just creating the entry (without any data) could cause the storage to
+ // grow beyond capacity, but we allow such infractions.
backend_->ModifyStorageSize(GetStorageSize());
}
@@ -345,6 +347,13 @@ int MemEntryImpl::InternalWriteData(int index, int offset, IOBuffer* buf,
int old_data_size = data_[index].size();
if (truncate || old_data_size < offset + buf_len) {
+ int delta = offset + buf_len - old_data_size;
+ backend_->ModifyStorageSize(delta);
+ if (backend_->HasExceededStorageSize()) {
+ backend_->ModifyStorageSize(-delta);
+ return net::ERR_INSUFFICIENT_RESOURCES;
+ }
+
data_[index].resize(offset + buf_len);
// Zero fill any hole.
@@ -352,8 +361,6 @@ int MemEntryImpl::InternalWriteData(int index, int offset, IOBuffer* buf,
std::fill(data_[index].begin() + old_data_size,
data_[index].begin() + offset, 0);
}
-
- backend_->ModifyStorageSize(data_[index].size() - old_data_size);
}
UpdateStateOnUse(ENTRY_WAS_MODIFIED);
« no previous file with comments | « net/disk_cache/memory/mem_backend_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698