Chromium Code Reviews| 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/disk_format_base.h" | 17 #include "net/disk_cache/disk_format_base.h" |
| 18 #include "net/disk_cache/mapped_file.h" | 18 #include "net/disk_cache/mapped_file.h" |
| 19 | 19 |
| 20 namespace base { | 20 namespace base { |
| 21 class ThreadChecker; | 21 class ThreadChecker; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace disk_cache { | 24 namespace disk_cache { |
| 25 | 25 |
| 26 // An instance of this class represents the header of a block file in memory. | 26 // An instance of this class represents the header of a block file in memory. |
| 27 // Note that this class doesn't perform any file operation. | 27 // Note that this class doesn't perform any file operation. |
| 28 class NET_EXPORT_PRIVATE BlockHeader { | 28 class NET_EXPORT_PRIVATE BlockHeader { |
|
gavinp
2013/06/28 21:47:45
This class continues to look like a lot of mechani
rvargas (doing something else)
2013/07/11 19:54:55
I'm not sure if it's a matter of naming what is bo
gavinp
2013/07/15 18:23:35
No, it's the structure. This abstraction does only
| |
| 29 public: | 29 public: |
| 30 BlockHeader(); | 30 BlockHeader(); |
| 31 explicit BlockHeader(BlockFileHeader* header); | 31 explicit BlockHeader(BlockFileHeader* header); |
| 32 explicit BlockHeader(MappedFile* file); | 32 explicit BlockHeader(MappedFile* file); |
| 33 BlockHeader(const BlockHeader& other); | 33 BlockHeader(const BlockHeader& other); |
| 34 ~BlockHeader(); | 34 ~BlockHeader(); |
| 35 | 35 |
| 36 // Creates a new entry on the allocation map, updating the apropriate | 36 // Creates a new entry on the allocation map, updating the apropriate |
| 37 // counters. |target| is the type of block to use (number of empty blocks), | 37 // counters. |target| is the type of block to use (number of empty blocks), |
| 38 // and |size| is the actual number of blocks to use. | 38 // and |size| is the actual number of blocks to use. |
| 39 bool CreateMapBlock(int target, int size, int* index); | 39 bool CreateMapBlock(int target, int size, int* index); |
| 40 | 40 |
| 41 // Deletes the block pointed by |index|. | 41 // Deletes the block pointed by |index|. |
| 42 void DeleteMapBlock(int index, int block_size); | 42 void DeleteMapBlock(int index, int block_size); |
| 43 | 43 |
| 44 // Returns true if the specified block is used. | 44 // Returns true if the specified block is used. |
| 45 bool UsedMapBlock(int index, int size); | 45 bool UsedMapBlock(int index, int size); |
| 46 | 46 |
| 47 // Restores the "empty counters" and allocation hints. | 47 // Restores the "empty counters" and allocation hints. |
| 48 void FixAllocationCounters(); | 48 void FixAllocationCounters(); |
| 49 | 49 |
| 50 // Returns true if the current block file should not be used as-is to store | 50 // Returns true if the current block file should not be used as-is to store |
| 51 // more records. |block_count| is the number of blocks to allocate. | 51 // more records. |block_count| is the number of blocks to allocate. |
| 52 bool NeedToGrowBlockFile(int block_count); | 52 bool NeedToGrowBlockFile(int block_count) const; |
| 53 | |
| 54 // Returns true if this block file can be used to store an extra record of | |
| 55 // size |block_count|. | |
| 56 bool CanAllocate(int block_count) const; | |
| 53 | 57 |
| 54 // Returns the number of empty blocks for this file. | 58 // Returns the number of empty blocks for this file. |
| 55 int EmptyBlocks() const; | 59 int EmptyBlocks() const; |
| 56 | 60 |
| 57 // Returns true if the counters look OK. | 61 // Returns true if the counters look OK. |
| 58 bool ValidateCounters() const; | 62 bool ValidateCounters() const; |
| 59 | 63 |
| 60 // Returns the size of the wrapped structure (BlockFileHeader). | 64 // Returns the size of the wrapped structure (BlockFileHeader). |
| 61 int Size() const; | 65 int Size() const; |
| 62 | 66 |
| 63 BlockFileHeader* operator->() { return header_; } | 67 BlockFileHeader* operator->() { return header_; } |
|
gavinp
2013/06/28 21:47:45
The Google C++ style guide has a strong presumptio
rvargas (doing something else)
2013/07/11 19:54:55
Happy to remove it.
| |
| 64 void operator=(const BlockHeader& other) { header_ = other.header_; } | 68 void operator=(const BlockHeader& other) { header_ = other.header_; } |
| 65 BlockFileHeader* Get() { return header_; } | 69 BlockFileHeader* Get() { return header_; } |
| 66 | 70 |
| 67 private: | 71 private: |
| 68 BlockFileHeader* header_; | 72 BlockFileHeader* header_; |
| 69 }; | 73 }; |
| 70 | 74 |
| 71 typedef std::vector<BlockHeader> BlockFilesBitmaps; | 75 typedef std::vector<BlockHeader> BlockFilesBitmaps; |
| 72 | 76 |
| 73 // This class handles the set of block-files open by the disk cache. | 77 // This class handles the set of block-files open by the disk cache. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_TruncatedFile); | 147 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_TruncatedFile); |
| 144 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_InvalidFile); | 148 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_InvalidFile); |
| 145 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_Stats); | 149 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_Stats); |
| 146 | 150 |
| 147 DISALLOW_COPY_AND_ASSIGN(BlockFiles); | 151 DISALLOW_COPY_AND_ASSIGN(BlockFiles); |
| 148 }; | 152 }; |
| 149 | 153 |
| 150 } // namespace disk_cache | 154 } // namespace disk_cache |
| 151 | 155 |
| 152 #endif // NET_DISK_CACHE_BLOCK_FILES_H_ | 156 #endif // NET_DISK_CACHE_BLOCK_FILES_H_ |
| OLD | NEW |