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/block_files.h" | 5 #include "net/disk_cache/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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 LOG(ERROR) << "Failed to open " << name.value(); | 443 LOG(ERROR) << "Failed to open " << name.value(); |
444 return false; | 444 return false; |
445 } | 445 } |
446 | 446 |
447 size_t file_len = file->GetLength(); | 447 size_t file_len = file->GetLength(); |
448 if (file_len < static_cast<size_t>(kBlockHeaderSize)) { | 448 if (file_len < static_cast<size_t>(kBlockHeaderSize)) { |
449 LOG(ERROR) << "File too small " << name.value(); | 449 LOG(ERROR) << "File too small " << name.value(); |
450 return false; | 450 return false; |
451 } | 451 } |
452 | 452 |
453 BlockHeader header(file); | 453 BlockHeader header(file.get()); |
454 if (kBlockMagic != header->magic || kBlockVersion2 != header->version) { | 454 if (kBlockMagic != header->magic || kBlockVersion2 != header->version) { |
455 LOG(ERROR) << "Invalid file version or magic " << name.value(); | 455 LOG(ERROR) << "Invalid file version or magic " << name.value(); |
456 return false; | 456 return false; |
457 } | 457 } |
458 | 458 |
459 if (header->updating || !header.ValidateCounters()) { | 459 if (header->updating || !header.ValidateCounters()) { |
460 // Last instance was not properly shutdown, or counters are out of sync. | 460 // Last instance was not properly shutdown, or counters are out of sync. |
461 if (!FixBlockFileHeader(file.get())) { | 461 if (!FixBlockFileHeader(file.get())) { |
462 LOG(ERROR) << "Unable to fix block file " << name.value(); | 462 LOG(ERROR) << "Unable to fix block file " << name.value(); |
463 return false; | 463 return false; |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 } | 686 } |
687 | 687 |
688 base::FilePath BlockFiles::Name(int index) { | 688 base::FilePath BlockFiles::Name(int index) { |
689 // The file format allows for 256 files. | 689 // The file format allows for 256 files. |
690 DCHECK(index < 256 || index >= 0); | 690 DCHECK(index < 256 || index >= 0); |
691 std::string tmp = base::StringPrintf("%s%d", kBlockName, index); | 691 std::string tmp = base::StringPrintf("%s%d", kBlockName, index); |
692 return path_.AppendASCII(tmp); | 692 return path_.AppendASCII(tmp); |
693 } | 693 } |
694 | 694 |
695 } // namespace disk_cache | 695 } // namespace disk_cache |
OLD | NEW |