| 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 // See net/disk_cache/disk_cache.h for the public interface. | 5 // See net/disk_cache/disk_cache.h for the public interface. |
| 6 | 6 |
| 7 #ifndef NET_DISK_CACHE_BLOCK_FILES_H_ | 7 #ifndef NET_DISK_CACHE_BLOCK_FILES_H_ |
| 8 #define NET_DISK_CACHE_BLOCK_FILES_H_ | 8 #define NET_DISK_CACHE_BLOCK_FILES_H_ |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "net/base/net_export.h" | 15 #include "net/base/net_export.h" |
| 16 #include "net/disk_cache/addr.h" | 16 #include "net/disk_cache/addr.h" |
| 17 #include "net/disk_cache/mapped_file.h" | 17 #include "net/disk_cache/mapped_file.h" |
| 18 | 18 |
| 19 namespace base { | |
| 20 class ThreadChecker; | |
| 21 } | |
| 22 | |
| 23 namespace disk_cache { | 19 namespace disk_cache { |
| 24 | 20 |
| 25 // This class handles the set of block-files open by the disk cache. | 21 // This class handles the set of block-files open by the disk cache. |
| 26 class NET_EXPORT_PRIVATE BlockFiles { | 22 class NET_EXPORT_PRIVATE BlockFiles { |
| 27 public: | 23 public: |
| 28 explicit BlockFiles(const base::FilePath& path); | 24 explicit BlockFiles(const base::FilePath& path); |
| 29 ~BlockFiles(); | 25 ~BlockFiles(); |
| 30 | 26 |
| 31 // Performs the object initialization. create_files indicates if the backing | 27 // Performs the object initialization. create_files indicates if the backing |
| 32 // files should be created or just open. | 28 // files should be created or just open. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 50 void CloseFiles(); | 46 void CloseFiles(); |
| 51 | 47 |
| 52 // Sends UMA stats. | 48 // Sends UMA stats. |
| 53 void ReportStats(); | 49 void ReportStats(); |
| 54 | 50 |
| 55 // Returns true if the blocks pointed by a given address are currently used. | 51 // Returns true if the blocks pointed by a given address are currently used. |
| 56 // This method is only intended for debugging. | 52 // This method is only intended for debugging. |
| 57 bool IsValid(Addr address); | 53 bool IsValid(Addr address); |
| 58 | 54 |
| 59 private: | 55 private: |
| 60 // Set force to true to overwrite the file if it exists. | |
| 61 bool CreateBlockFile(int index, FileType file_type, bool force); | |
| 62 bool OpenBlockFile(int index); | |
| 63 | |
| 64 // Attemp to grow this file. Fails if the file cannot be extended anymore. | 56 // Attemp to grow this file. Fails if the file cannot be extended anymore. |
| 65 bool GrowBlockFile(MappedFile* file, BlockFileHeader* header); | 57 bool GrowBlockFile(MappedFile* file, BlockFileHeader* header); |
| 66 | 58 |
| 67 // Returns the appropriate file to use for a new block. | 59 // Returns the appropriate file to use for a new block. |
| 68 MappedFile* FileForNewBlock(FileType block_type, int block_count); | 60 MappedFile* FileForNewBlock(FileType block_type, int block_count); |
| 69 | 61 |
| 70 // Returns the next block file on this chain, creating new files if needed. | |
| 71 MappedFile* NextFile(MappedFile* file); | |
| 72 | |
| 73 // Creates an empty block file and returns its index. | |
| 74 int CreateNextBlockFile(FileType block_type); | |
| 75 | |
| 76 // Removes a chained block file that is now empty. | |
| 77 bool RemoveEmptyFile(FileType block_type); | |
| 78 | |
| 79 // Restores the header of a potentially inconsistent file. | 62 // Restores the header of a potentially inconsistent file. |
| 80 bool FixBlockFileHeader(MappedFile* file); | 63 bool FixBlockFileHeader(MappedFile* file); |
| 81 | 64 |
| 82 // Retrieves stats for the given file index. | 65 // Retrieves stats for the given file index. |
| 83 void GetFileStats(int index, int* used_count, int* load); | 66 void GetFileStats(int index, int* used_count, int* load); |
| 84 | 67 |
| 85 // Returns the filename for a given file index. | |
| 86 base::FilePath Name(int index); | |
| 87 | |
| 88 bool init_; | 68 bool init_; |
| 89 char* zero_buffer_; // Buffer to speed-up cleaning deleted entries. | |
| 90 base::FilePath path_; // Path to the backing folder. | |
| 91 std::vector<MappedFile*> block_files_; // The actual files. | |
| 92 scoped_ptr<base::ThreadChecker> thread_checker_; | |
| 93 | |
| 94 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_ZeroSizeFile); | |
| 95 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_TruncatedFile); | |
| 96 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_InvalidFile); | |
| 97 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_Stats); | |
| 98 | 69 |
| 99 DISALLOW_COPY_AND_ASSIGN(BlockFiles); | 70 DISALLOW_COPY_AND_ASSIGN(BlockFiles); |
| 100 }; | 71 }; |
| 101 | 72 |
| 102 } // namespace disk_cache | 73 } // namespace disk_cache |
| 103 | 74 |
| 104 #endif // NET_DISK_CACHE_BLOCK_FILES_H_ | 75 #endif // NET_DISK_CACHE_BLOCK_FILES_H_ |
| OLD | NEW |