| 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_V3_BLOCK_BITMAPS_H_ | 7 #ifndef NET_DISK_CACHE_V3_BLOCK_BITMAPS_H_ |
| 8 #define NET_DISK_CACHE_V3_BLOCK_BITMAPS_H_ | 8 #define NET_DISK_CACHE_V3_BLOCK_BITMAPS_H_ |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 11 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
| 12 #include "net/disk_cache/addr.h" | 14 #include "net/disk_cache/addr.h" |
| 13 #include "net/disk_cache/block_files.h" | 15 #include "net/disk_cache/block_files.h" |
| 16 #include "net/disk_cache/mapped_file.h" |
| 14 | 17 |
| 15 namespace disk_cache { | 18 namespace disk_cache { |
| 16 | 19 |
| 17 class BackendImplV3; | 20 class BackendImplV3; |
| 18 | 21 |
| 19 // This class is the interface in the v3 disk cache to the set of files holding | 22 // This class is the interface in the v3 disk cache to the set of files holding |
| 20 // cached data that is small enough to not be efficiently stored in a dedicated | 23 // cached data that is small enough to not be efficiently stored in a dedicated |
| 21 // file (i.e. < kMaxBlockSize). It is primarily used to allocate and free | 24 // file (i.e. < kMaxBlockSize). It is primarily used to allocate and free |
| 22 // regions in those files used to store data. | 25 // regions in those files used to store data. |
| 23 class NET_EXPORT_PRIVATE BlockBitmaps { | 26 class NET_EXPORT_PRIVATE BlockBitmaps { |
| 24 public: | 27 public: |
| 25 BlockBitmaps(); | 28 explicit BlockBitmaps(BackendImplV3* backend); |
| 26 ~BlockBitmaps(); | 29 ~BlockBitmaps(); |
| 27 | 30 |
| 28 void Init(const BlockFilesBitmaps& bitmaps); | 31 void Init(const BlockFilesBitmaps& bitmaps); |
| 29 | 32 |
| 30 // Creates a new entry on a block file. block_type indicates the size of block | 33 // Creates a new entry on a block file. block_type indicates the size of block |
| 31 // to be used (as defined on cache_addr.h), block_count is the number of | 34 // to be used (as defined on cache_addr.h), block_count is the number of |
| 32 // blocks to allocate, and block_address is the address of the new entry. | 35 // blocks to allocate, and block_address is the address of the new entry. |
| 33 bool CreateBlock(FileType block_type, int block_count, Addr* block_address); | 36 bool CreateBlock(FileType block_type, int block_count, Addr* block_address); |
| 34 | 37 |
| 35 // Removes an entry from the block files. | 38 // Removes an entry from the block files. |
| 36 void DeleteBlock(Addr address); | 39 void DeleteBlock(Addr address); |
| 37 | 40 |
| 38 // Releases the internal bitmaps. The cache is being purged. | 41 // Releases the internal bitmaps. The cache is being purged. |
| 39 void Clear(); | 42 void Clear(); |
| 40 | 43 |
| 41 // Sends UMA stats. | 44 // Sends UMA stats. |
| 42 void ReportStats(); | 45 void ReportStats(); |
| 43 | 46 |
| 44 // Returns true if the blocks pointed by a given address are currently used. | 47 // Returns true if the blocks pointed by a given address are currently used. |
| 45 // This method is only intended for debugging. | 48 // This method is only intended for debugging. |
| 46 bool IsValid(Addr address); | 49 bool IsValid(Addr address); |
| 47 | 50 |
| 48 private: | 51 private: |
| 49 // Returns the header number that stores a given address. | 52 // Returns the header number that stores a given address. |
| 50 int GetHeaderNumber(Addr address); | 53 int GetHeaderNumber(Addr address); |
| 51 | 54 |
| 55 // Returns the number of entry blocks for the given file type. |
| 56 int EmptyBlocksForType(int first_file); |
| 57 |
| 52 // Returns the appropriate header to use for a new block. | 58 // Returns the appropriate header to use for a new block. |
| 53 int HeaderNumberForNewBlock(FileType block_type, int block_count); | 59 int HeaderNumberForNewBlock(FileType block_type, int block_count); |
| 54 | 60 |
| 55 // Retrieves stats for the given file index. | 61 // Retrieves stats for the given file index. |
| 56 void GetFileStats(int index, int* used_count, int* load); | 62 void GetFileStats(int index, int* used_count, int* load); |
| 57 | 63 |
| 58 BlockFilesBitmaps bitmaps_; | 64 BlockFilesBitmaps bitmaps_; |
| 65 BackendImplV3* backend_; |
| 66 int empty_counts_[kFirstAdditionalBlockFileV3]; |
| 59 | 67 |
| 60 DISALLOW_COPY_AND_ASSIGN(BlockBitmaps); | 68 DISALLOW_COPY_AND_ASSIGN(BlockBitmaps); |
| 61 }; | 69 }; |
| 62 | 70 |
| 63 } // namespace disk_cache | 71 } // namespace disk_cache |
| 64 | 72 |
| 65 #endif // NET_DISK_CACHE_V3_BLOCK_BITMAPS_H_ | 73 #endif // NET_DISK_CACHE_V3_BLOCK_BITMAPS_H_ |
| OLD | NEW |