| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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> |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 // Removes an entry from the block files. If deep is true, the storage is zero | 40 // Removes an entry from the block files. If deep is true, the storage is zero |
| 41 // filled; otherwise the entry is removed but the data is not altered (must be | 41 // filled; otherwise the entry is removed but the data is not altered (must be |
| 42 // already zeroed). | 42 // already zeroed). |
| 43 void DeleteBlock(Addr address, bool deep); | 43 void DeleteBlock(Addr address, bool deep); |
| 44 | 44 |
| 45 // Close all the files and set the internal state to be initializad again. The | 45 // Close all the files and set the internal state to be initializad again. The |
| 46 // cache is being purged. | 46 // cache is being purged. |
| 47 void CloseFiles(); | 47 void CloseFiles(); |
| 48 | 48 |
| 49 // Sends UMA stats. |
| 50 void ReportStats(); |
| 51 |
| 49 private: | 52 private: |
| 50 // Set force to true to overwrite the file if it exists. | 53 // Set force to true to overwrite the file if it exists. |
| 51 bool CreateBlockFile(int index, FileType file_type, bool force); | 54 bool CreateBlockFile(int index, FileType file_type, bool force); |
| 52 bool OpenBlockFile(int index); | 55 bool OpenBlockFile(int index); |
| 53 | 56 |
| 54 // Attemp to grow this file. Fails if the file cannot be extended anymore. | 57 // Attemp to grow this file. Fails if the file cannot be extended anymore. |
| 55 bool GrowBlockFile(MappedFile* file, BlockFileHeader* header); | 58 bool GrowBlockFile(MappedFile* file, BlockFileHeader* header); |
| 56 | 59 |
| 57 // Returns the appropriate file to use for a new block. | 60 // Returns the appropriate file to use for a new block. |
| 58 MappedFile* FileForNewBlock(FileType block_type, int block_count); | 61 MappedFile* FileForNewBlock(FileType block_type, int block_count); |
| 59 | 62 |
| 60 // Returns the next block file on this chain, creating new files if needed. | 63 // Returns the next block file on this chain, creating new files if needed. |
| 61 MappedFile* NextFile(const MappedFile* file); | 64 MappedFile* NextFile(const MappedFile* file); |
| 62 | 65 |
| 63 // Creates an empty block file and returns its index. | 66 // Creates an empty block file and returns its index. |
| 64 int CreateNextBlockFile(FileType block_type); | 67 int CreateNextBlockFile(FileType block_type); |
| 65 | 68 |
| 66 // Removes a chained block file that is now empty. | 69 // Removes a chained block file that is now empty. |
| 67 void RemoveEmptyFile(FileType block_type); | 70 void RemoveEmptyFile(FileType block_type); |
| 68 | 71 |
| 69 // Restores the header of a potentially inconsistent file. | 72 // Restores the header of a potentially inconsistent file. |
| 70 bool FixBlockFileHeader(MappedFile* file); | 73 bool FixBlockFileHeader(MappedFile* file); |
| 71 | 74 |
| 75 // Retrieves stats for the given file index. |
| 76 void GetFileStats(int index, int* used_count, int* load); |
| 77 |
| 72 // Returns the filename for a given file index. | 78 // Returns the filename for a given file index. |
| 73 FilePath Name(int index); | 79 FilePath Name(int index); |
| 74 | 80 |
| 75 bool init_; | 81 bool init_; |
| 76 char* zero_buffer_; // Buffer to speed-up cleaning deleted entries. | 82 char* zero_buffer_; // Buffer to speed-up cleaning deleted entries. |
| 77 FilePath path_; // Path to the backing folder. | 83 FilePath path_; // Path to the backing folder. |
| 78 std::vector<MappedFile*> block_files_; // The actual files. | 84 std::vector<MappedFile*> block_files_; // The actual files. |
| 79 | 85 |
| 80 FRIEND_TEST(DiskCacheTest, BlockFiles_ZeroSizeFile); | 86 FRIEND_TEST(DiskCacheTest, BlockFiles_ZeroSizeFile); |
| 81 FRIEND_TEST(DiskCacheTest, BlockFiles_InvalidFile); | 87 FRIEND_TEST(DiskCacheTest, BlockFiles_InvalidFile); |
| 88 FRIEND_TEST(DiskCacheTest, BlockFiles_Stats); |
| 82 | 89 |
| 83 DISALLOW_COPY_AND_ASSIGN(BlockFiles); | 90 DISALLOW_COPY_AND_ASSIGN(BlockFiles); |
| 84 }; | 91 }; |
| 85 | 92 |
| 86 } // namespace disk_cache | 93 } // namespace disk_cache |
| 87 | 94 |
| 88 #endif // NET_DISK_CACHE_BLOCK_FILES_H__ | 95 #endif // NET_DISK_CACHE_BLOCK_FILES_H__ |
| OLD | NEW |