summaryrefslogtreecommitdiffstats
path: root/net/disk_cache/simple/simple_entry_impl.cc
diff options
context:
space:
mode:
authorgavinp@chromium.org <gavinp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-30 09:57:48 +0000
committergavinp@chromium.org <gavinp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-30 09:57:48 +0000
commitf8e60d5306b24acfb6148cf66ebda571f99c8373 (patch)
tree3f69d40c143acfbd7ffec99deb46d3b9f2853d8f /net/disk_cache/simple/simple_entry_impl.cc
parentdb3f7fa375d1639cde008869db20aaad50756804 (diff)
downloadchromium_src-f8e60d5306b24acfb6148cf66ebda571f99c8373.zip
chromium_src-f8e60d5306b24acfb6148cf66ebda571f99c8373.tar.gz
chromium_src-f8e60d5306b24acfb6148cf66ebda571f99c8373.tar.bz2
Do not open clearly invalid entries in the SimpleCache.
In the case of premature kill, the SimpleCache backend can leave invalid entries on disk without EOF records. Now let's catch these early and fail to open the entries. R=pasko@google.com, rdsmith@chromium.org BUG=236390 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=197172 Review URL: https://codereview.chromium.org/13844016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@197329 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/simple/simple_entry_impl.cc')
-rw-r--r--net/disk_cache/simple/simple_entry_impl.cc14
1 files changed, 10 insertions, 4 deletions
diff --git a/net/disk_cache/simple/simple_entry_impl.cc b/net/disk_cache/simple/simple_entry_impl.cc
index 6847e02..df1125c 100644
--- a/net/disk_cache/simple/simple_entry_impl.cc
+++ b/net/disk_cache/simple/simple_entry_impl.cc
@@ -368,6 +368,10 @@ void SimpleEntryImpl::CreateEntryInternal(Entry** out_entry,
state_ = STATE_IO_PENDING;
+ // If creation succeeds, we should mark all streams to be saved on close.
+ for (int i = 0; i < kSimpleEntryFileCount; ++i)
+ have_written_[i] = true;
+
// We insert the entry in the index before creating the entry files in the
// SimpleSynchronousEntry, because this way the worst scenario is when we
// have the entry in the index but we don't have the created files yet, this
@@ -401,10 +405,12 @@ void SimpleEntryImpl::CloseInternal() {
crc32s_to_write(new std::vector<CRCRecord>());
for (int i = 0; i < kSimpleEntryFileCount; ++i) {
if (have_written_[i]) {
- if (data_size_[i] == crc32s_end_offset_[i])
- crc32s_to_write->push_back(CRCRecord(i, true, crc32s_[i]));
- else
+ if (data_size_[i] == crc32s_end_offset_[i]) {
+ int32 crc = data_size_[i] == 0 ? crc32(0, Z_NULL, 0) : crc32s_[i];
+ crc32s_to_write->push_back(CRCRecord(i, true, crc));
+ } else {
crc32s_to_write->push_back(CRCRecord(i, false, 0));
+ }
}
}
Closure task = base::Bind(&SimpleSynchronousEntry::Close,
@@ -493,7 +499,7 @@ void SimpleEntryImpl::CreationOperationComplete(
if (creation_failed) {
completion_callback.Run(net::ERR_FAILED);
MarkAsDoomed();
- state_ = STATE_UNINITIALIZED;
+ MakeUninitialized();
return;
}
state_ = STATE_READY;