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

Unified Diff: net/disk_cache/simple/simple_synchronous_entry.cc

Issue 2015263002: Simple Cache: avoid extraneous stream 0 (http header) writes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/entry_unittest.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/simple/simple_synchronous_entry.cc
diff --git a/net/disk_cache/simple/simple_synchronous_entry.cc b/net/disk_cache/simple/simple_synchronous_entry.cc
index 02818add30d0042a571ee741dd56ebf9d5b49fb6..71f1cb9fffb40364fb38864f2f76146bb0402769 100644
--- a/net/disk_cache/simple/simple_synchronous_entry.cc
+++ b/net/disk_cache/simple/simple_synchronous_entry.cc
@@ -687,24 +687,6 @@ void SimpleSynchronousEntry::Close(
std::unique_ptr<std::vector<CRCRecord>> crc32s_to_write,
net::GrowableIOBuffer* stream_0_data) {
DCHECK(stream_0_data);
- // Write stream 0 data.
- int stream_0_offset = entry_stat.GetOffsetInFile(key_.size(), 0, 0);
- if (files_[0].Write(stream_0_offset, stream_0_data->data(),
- entry_stat.data_size(0)) !=
- entry_stat.data_size(0)) {
- RecordCloseResult(cache_type_, CLOSE_RESULT_WRITE_FAILURE);
- DVLOG(1) << "Could not write stream 0 data.";
- Doom();
- }
- net::SHA256HashValue hash_value;
- CalculateSHA256OfKey(key_, &hash_value);
- if (files_[0].Write(stream_0_offset + entry_stat.data_size(0),
- reinterpret_cast<char*>(hash_value.data),
- sizeof(hash_value)) != sizeof(hash_value)) {
- RecordCloseResult(cache_type_, CLOSE_RESULT_WRITE_FAILURE);
- DVLOG(1) << "Could not write stream 0 data.";
- Doom();
- }
for (std::vector<CRCRecord>::const_iterator it = crc32s_to_write->begin();
it != crc32s_to_write->end(); ++it) {
@@ -713,6 +695,26 @@ void SimpleSynchronousEntry::Close(
if (empty_file_omitted_[file_index])
continue;
+ if (stream_index == 0) {
+ // Write stream 0 data.
+ int stream_0_offset = entry_stat.GetOffsetInFile(key_.size(), 0, 0);
+ if (files_[0].Write(stream_0_offset, stream_0_data->data(),
+ entry_stat.data_size(0)) != entry_stat.data_size(0)) {
+ RecordCloseResult(cache_type_, CLOSE_RESULT_WRITE_FAILURE);
+ DVLOG(1) << "Could not write stream 0 data.";
+ Doom();
+ }
+ net::SHA256HashValue hash_value;
+ CalculateSHA256OfKey(key_, &hash_value);
+ if (files_[0].Write(stream_0_offset + entry_stat.data_size(0),
+ reinterpret_cast<char*>(hash_value.data),
+ sizeof(hash_value)) != sizeof(hash_value)) {
+ RecordCloseResult(cache_type_, CLOSE_RESULT_WRITE_FAILURE);
+ DVLOG(1) << "Could not write stream 0 data.";
+ Doom();
+ }
+ }
+
SimpleFileEOF eof_record;
eof_record.stream_size = entry_stat.data_size(stream_index);
eof_record.final_magic_number = kSimpleFinalMagicNumber;
« no previous file with comments | « net/disk_cache/entry_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698