| OLD | NEW |
| 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 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 } | 501 } |
| 502 } | 502 } |
| 503 | 503 |
| 504 if (static_cast<int>(file_len) < | 504 if (static_cast<int>(file_len) < |
| 505 header->max_entries * header->entry_size + kBlockHeaderSize) { | 505 header->max_entries * header->entry_size + kBlockHeaderSize) { |
| 506 LOG(ERROR) << "File too small " << name.value(); | 506 LOG(ERROR) << "File too small " << name.value(); |
| 507 return false; | 507 return false; |
| 508 } | 508 } |
| 509 | 509 |
| 510 if (index == 0) { | 510 if (index == 0) { |
| 511 // Load the links file into memory with a single read. | 511 // Load the links file into memory. |
| 512 scoped_ptr<char[]> buf(new char[file_len]); | 512 if (!file->Preload()) |
| 513 if (!file->Read(buf.get(), file_len, 0)) | |
| 514 return false; | 513 return false; |
| 515 } | 514 } |
| 516 | 515 |
| 517 ScopedFlush flush(file.get()); | 516 ScopedFlush flush(file.get()); |
| 518 DCHECK(!block_files_[index]); | 517 DCHECK(!block_files_[index]); |
| 519 file.swap(&block_files_[index]); | 518 file.swap(&block_files_[index]); |
| 520 return true; | 519 return true; |
| 521 } | 520 } |
| 522 | 521 |
| 523 bool BlockFiles::GrowBlockFile(MappedFile* file, BlockFileHeader* header) { | 522 bool BlockFiles::GrowBlockFile(MappedFile* file, BlockFileHeader* header) { |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 } | 723 } |
| 725 | 724 |
| 726 base::FilePath BlockFiles::Name(int index) { | 725 base::FilePath BlockFiles::Name(int index) { |
| 727 // The file format allows for 256 files. | 726 // The file format allows for 256 files. |
| 728 DCHECK(index < 256 && index >= 0); | 727 DCHECK(index < 256 && index >= 0); |
| 729 std::string tmp = base::StringPrintf("%s%d", kBlockName, index); | 728 std::string tmp = base::StringPrintf("%s%d", kBlockName, index); |
| 730 return path_.AppendASCII(tmp); | 729 return path_.AppendASCII(tmp); |
| 731 } | 730 } |
| 732 | 731 |
| 733 } // namespace disk_cache | 732 } // namespace disk_cache |
| OLD | NEW |