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

Side by Side 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, 6 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 unified diff | Download patch
« no previous file with comments | « net/disk_cache/entry_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/disk_cache/simple/simple_synchronous_entry.h" 5 #include "net/disk_cache/simple/simple_synchronous_entry.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstring> 8 #include <cstring>
9 #include <functional> 9 #include <functional>
10 #include <limits> 10 #include <limits>
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 return; 680 return;
681 } 681 }
682 RecordCheckEOFResult(cache_type_, CHECK_EOF_RESULT_SUCCESS); 682 RecordCheckEOFResult(cache_type_, CHECK_EOF_RESULT_SUCCESS);
683 } 683 }
684 684
685 void SimpleSynchronousEntry::Close( 685 void SimpleSynchronousEntry::Close(
686 const SimpleEntryStat& entry_stat, 686 const SimpleEntryStat& entry_stat,
687 std::unique_ptr<std::vector<CRCRecord>> crc32s_to_write, 687 std::unique_ptr<std::vector<CRCRecord>> crc32s_to_write,
688 net::GrowableIOBuffer* stream_0_data) { 688 net::GrowableIOBuffer* stream_0_data) {
689 DCHECK(stream_0_data); 689 DCHECK(stream_0_data);
690 // Write stream 0 data.
691 int stream_0_offset = entry_stat.GetOffsetInFile(key_.size(), 0, 0);
692 if (files_[0].Write(stream_0_offset, stream_0_data->data(),
693 entry_stat.data_size(0)) !=
694 entry_stat.data_size(0)) {
695 RecordCloseResult(cache_type_, CLOSE_RESULT_WRITE_FAILURE);
696 DVLOG(1) << "Could not write stream 0 data.";
697 Doom();
698 }
699 net::SHA256HashValue hash_value;
700 CalculateSHA256OfKey(key_, &hash_value);
701 if (files_[0].Write(stream_0_offset + entry_stat.data_size(0),
702 reinterpret_cast<char*>(hash_value.data),
703 sizeof(hash_value)) != sizeof(hash_value)) {
704 RecordCloseResult(cache_type_, CLOSE_RESULT_WRITE_FAILURE);
705 DVLOG(1) << "Could not write stream 0 data.";
706 Doom();
707 }
708 690
709 for (std::vector<CRCRecord>::const_iterator it = crc32s_to_write->begin(); 691 for (std::vector<CRCRecord>::const_iterator it = crc32s_to_write->begin();
710 it != crc32s_to_write->end(); ++it) { 692 it != crc32s_to_write->end(); ++it) {
711 const int stream_index = it->index; 693 const int stream_index = it->index;
712 const int file_index = GetFileIndexFromStreamIndex(stream_index); 694 const int file_index = GetFileIndexFromStreamIndex(stream_index);
713 if (empty_file_omitted_[file_index]) 695 if (empty_file_omitted_[file_index])
714 continue; 696 continue;
715 697
698 if (stream_index == 0) {
699 // Write stream 0 data.
700 int stream_0_offset = entry_stat.GetOffsetInFile(key_.size(), 0, 0);
701 if (files_[0].Write(stream_0_offset, stream_0_data->data(),
702 entry_stat.data_size(0)) != entry_stat.data_size(0)) {
703 RecordCloseResult(cache_type_, CLOSE_RESULT_WRITE_FAILURE);
704 DVLOG(1) << "Could not write stream 0 data.";
705 Doom();
706 }
707 net::SHA256HashValue hash_value;
708 CalculateSHA256OfKey(key_, &hash_value);
709 if (files_[0].Write(stream_0_offset + entry_stat.data_size(0),
710 reinterpret_cast<char*>(hash_value.data),
711 sizeof(hash_value)) != sizeof(hash_value)) {
712 RecordCloseResult(cache_type_, CLOSE_RESULT_WRITE_FAILURE);
713 DVLOG(1) << "Could not write stream 0 data.";
714 Doom();
715 }
716 }
717
716 SimpleFileEOF eof_record; 718 SimpleFileEOF eof_record;
717 eof_record.stream_size = entry_stat.data_size(stream_index); 719 eof_record.stream_size = entry_stat.data_size(stream_index);
718 eof_record.final_magic_number = kSimpleFinalMagicNumber; 720 eof_record.final_magic_number = kSimpleFinalMagicNumber;
719 eof_record.flags = 0; 721 eof_record.flags = 0;
720 if (it->has_crc32) 722 if (it->has_crc32)
721 eof_record.flags |= SimpleFileEOF::FLAG_HAS_CRC32; 723 eof_record.flags |= SimpleFileEOF::FLAG_HAS_CRC32;
722 if (stream_index == 0) 724 if (stream_index == 0)
723 eof_record.flags |= SimpleFileEOF::FLAG_HAS_KEY_SHA256; 725 eof_record.flags |= SimpleFileEOF::FLAG_HAS_KEY_SHA256;
724 eof_record.data_crc32 = it->data_crc32; 726 eof_record.data_crc32 = it->data_crc32;
725 int eof_offset = entry_stat.GetEOFOffsetInFile(key_.size(), stream_index); 727 int eof_offset = entry_stat.GetEOFOffsetInFile(key_.size(), stream_index);
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 range.offset = offset; 1589 range.offset = offset;
1588 range.length = len; 1590 range.length = len;
1589 range.data_crc32 = data_crc32; 1591 range.data_crc32 = data_crc32;
1590 range.file_offset = data_file_offset; 1592 range.file_offset = data_file_offset;
1591 sparse_ranges_.insert(std::make_pair(offset, range)); 1593 sparse_ranges_.insert(std::make_pair(offset, range));
1592 1594
1593 return true; 1595 return true;
1594 } 1596 }
1595 1597
1596 } // namespace disk_cache 1598 } // namespace disk_cache
OLDNEW
« 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