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

Side by Side Diff: net/disk_cache/blockfile/block_files.cc

Issue 903273002: Update from https://crrev.com/315085 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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/cert/x509_certificate_mac.cc ('k') | net/dns/dns_config_service_posix.cc » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/blockfile/block_files.h" 5 #include "net/disk_cache/blockfile/block_files.h"
6 6
7 #include "base/atomicops.h" 7 #include "base/atomicops.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 649
650 // Note that we expect to be called outside of a FileLock... however, we cannot 650 // Note that we expect to be called outside of a FileLock... however, we cannot
651 // DCHECK on header->updating because we may be fixing a crash. 651 // DCHECK on header->updating because we may be fixing a crash.
652 bool BlockFiles::FixBlockFileHeader(MappedFile* file) { 652 bool BlockFiles::FixBlockFileHeader(MappedFile* file) {
653 ScopedFlush flush(file); 653 ScopedFlush flush(file);
654 BlockHeader file_header(file); 654 BlockHeader file_header(file);
655 int file_size = static_cast<int>(file->GetLength()); 655 int file_size = static_cast<int>(file->GetLength());
656 if (file_size < file_header.Size()) 656 if (file_size < file_header.Size())
657 return false; // file_size > 2GB is also an error. 657 return false; // file_size > 2GB is also an error.
658 658
659 const int kMinBlockSize = 36; 659 const int kMinHeaderBlockSize = 36;
660 const int kMaxBlockSize = 4096; 660 const int kMaxHeaderBlockSize = 4096;
661 BlockFileHeader* header = file_header.Header(); 661 BlockFileHeader* header = file_header.Header();
662 if (header->entry_size < kMinBlockSize || 662 if (header->entry_size < kMinHeaderBlockSize ||
663 header->entry_size > kMaxBlockSize || header->num_entries < 0) 663 header->entry_size > kMaxHeaderBlockSize || header->num_entries < 0)
664 return false; 664 return false;
665 665
666 // Make sure that we survive crashes. 666 // Make sure that we survive crashes.
667 header->updating = 1; 667 header->updating = 1;
668 int expected = header->entry_size * header->max_entries + file_header.Size(); 668 int expected = header->entry_size * header->max_entries + file_header.Size();
669 if (file_size != expected) { 669 if (file_size != expected) {
670 int max_expected = header->entry_size * kMaxBlocks + file_header.Size(); 670 int max_expected = header->entry_size * kMaxBlocks + file_header.Size();
671 if (file_size < expected || header->empty[3] || file_size > max_expected) { 671 if (file_size < expected || header->empty[3] || file_size > max_expected) {
672 NOTREACHED(); 672 NOTREACHED();
673 LOG(ERROR) << "Unexpected file size"; 673 LOG(ERROR) << "Unexpected file size";
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 } 722 }
723 723
724 base::FilePath BlockFiles::Name(int index) { 724 base::FilePath BlockFiles::Name(int index) {
725 // The file format allows for 256 files. 725 // The file format allows for 256 files.
726 DCHECK(index < 256 && index >= 0); 726 DCHECK(index < 256 && index >= 0);
727 std::string tmp = base::StringPrintf("%s%d", kBlockName, index); 727 std::string tmp = base::StringPrintf("%s%d", kBlockName, index);
728 return path_.AppendASCII(tmp); 728 return path_.AppendASCII(tmp);
729 } 729 }
730 730
731 } // namespace disk_cache 731 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/cert/x509_certificate_mac.cc ('k') | net/dns/dns_config_service_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698