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 <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/atomicops.h" | 9 #include "base/atomicops.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 } | 508 } |
509 | 509 |
510 if (index == 0) { | 510 if (index == 0) { |
511 // Load the links file into memory. | 511 // Load the links file into memory. |
512 if (!file->Preload()) | 512 if (!file->Preload()) |
513 return false; | 513 return false; |
514 } | 514 } |
515 | 515 |
516 ScopedFlush flush(file.get()); | 516 ScopedFlush flush(file.get()); |
517 DCHECK(!block_files_[index]); | 517 DCHECK(!block_files_[index]); |
518 file.swap(&block_files_[index]); | 518 block_files_[index] = file.get(); |
| 519 file->AddRef(); |
519 return true; | 520 return true; |
520 } | 521 } |
521 | 522 |
522 bool BlockFiles::GrowBlockFile(MappedFile* file, BlockFileHeader* header) { | 523 bool BlockFiles::GrowBlockFile(MappedFile* file, BlockFileHeader* header) { |
523 if (kMaxBlocks == header->max_entries) | 524 if (kMaxBlocks == header->max_entries) |
524 return false; | 525 return false; |
525 | 526 |
526 ScopedFlush flush(file); | 527 ScopedFlush flush(file); |
527 DCHECK(!header->empty[3]); | 528 DCHECK(!header->empty[3]); |
528 int new_size = header->max_entries + 1024; | 529 int new_size = header->max_entries + 1024; |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 } | 725 } |
725 | 726 |
726 base::FilePath BlockFiles::Name(int index) { | 727 base::FilePath BlockFiles::Name(int index) { |
727 // The file format allows for 256 files. | 728 // The file format allows for 256 files. |
728 DCHECK(index < 256 && index >= 0); | 729 DCHECK(index < 256 && index >= 0); |
729 std::string tmp = base::StringPrintf("%s%d", kBlockName, index); | 730 std::string tmp = base::StringPrintf("%s%d", kBlockName, index); |
730 return path_.AppendASCII(tmp); | 731 return path_.AppendASCII(tmp); |
731 } | 732 } |
732 | 733 |
733 } // namespace disk_cache | 734 } // namespace disk_cache |
OLD | NEW |