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/mapped_file.h" | 17 #include "net/disk_cache/mapped_file.h" |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 class ThreadChecker; | 20 class ThreadChecker; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace disk_cache { | 23 namespace disk_cache { |
| 24 | 24 |
| 25 // An instance of this class represents the header of a block file in memory. | |
| 26 // Note that this class doesn't perform any file operation. | |
| 27 class BlockHeader { | |
|
gavinp
2013/06/14 15:37:02
Is this class ever referenced in any translation u
rvargas (doing something else)
2013/06/14 18:32:07
Sure, https://codereview.chromium.org/15203004/dif
rvargas (doing something else)
2013/06/18 18:12:23
I'm sorry, this was not completely accurate... the
| |
| 28 public: | |
| 29 BlockHeader(); | |
| 30 explicit BlockHeader(BlockFileHeader* header); | |
| 31 explicit BlockHeader(MappedFile* file); | |
| 32 BlockHeader(const BlockHeader& other); | |
| 33 ~BlockHeader(); | |
| 34 | |
| 35 // Creates a new entry on the allocation map, updating the apropriate | |
| 36 // counters. |target| is the type of block to use (number of empty blocks), | |
| 37 // and |size| is the actual number of blocks to use. | |
| 38 bool CreateMapBlock(int target, int size, int* index); | |
| 39 | |
| 40 // Deletes the block pointed by |index|. | |
| 41 void DeleteMapBlock(int index, int block_size); | |
| 42 | |
| 43 // Returns true if the specified block is used. | |
| 44 bool UsedMapBlock(int index, int size); | |
| 45 | |
| 46 // Restores the "empty counters" and allocation hints. | |
| 47 void FixAllocationCounters(); | |
| 48 | |
| 49 // Returns true if the current block file should not be used as-is to store | |
| 50 // more records. |block_count| is the number of blocks to allocate. | |
| 51 bool NeedToGrowBlockFile(int block_count); | |
| 52 | |
| 53 // Returns the number of empty blocks for this file. | |
| 54 int EmptyBlocks() const; | |
| 55 | |
| 56 // Returns true if the counters look OK. | |
| 57 bool ValidateCounters() const; | |
| 58 | |
| 59 // Returns the size of the wrapped structure (BlockFileHeader). | |
| 60 int Size() const; | |
| 61 | |
| 62 BlockFileHeader* operator->() { return header_; } | |
| 63 void operator=(const BlockHeader& other) { header_ = other.header_; } | |
| 64 BlockFileHeader* Get() { return header_; } | |
| 65 | |
| 66 private: | |
| 67 BlockFileHeader* header_; | |
|
gavinp
2013/06/14 15:37:02
#include "net/disk_cache/disk_format_base.h"
rvargas (doing something else)
2013/06/14 18:32:07
Done.
| |
| 68 }; | |
| 69 | |
| 70 typedef std::vector<BlockHeader> BlockFilesBitmaps; | |
| 71 | |
| 25 // This class handles the set of block-files open by the disk cache. | 72 // This class handles the set of block-files open by the disk cache. |
| 26 class NET_EXPORT_PRIVATE BlockFiles { | 73 class NET_EXPORT_PRIVATE BlockFiles { |
| 27 public: | 74 public: |
| 28 explicit BlockFiles(const base::FilePath& path); | 75 explicit BlockFiles(const base::FilePath& path); |
| 29 ~BlockFiles(); | 76 ~BlockFiles(); |
| 30 | 77 |
| 31 // Performs the object initialization. create_files indicates if the backing | 78 // Performs the object initialization. create_files indicates if the backing |
| 32 // files should be created or just open. | 79 // files should be created or just open. |
| 33 bool Init(bool create_files); | 80 bool Init(bool create_files); |
| 34 | 81 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_TruncatedFile); | 142 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_TruncatedFile); |
| 96 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_InvalidFile); | 143 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_InvalidFile); |
| 97 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_Stats); | 144 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_Stats); |
| 98 | 145 |
| 99 DISALLOW_COPY_AND_ASSIGN(BlockFiles); | 146 DISALLOW_COPY_AND_ASSIGN(BlockFiles); |
| 100 }; | 147 }; |
| 101 | 148 |
| 102 } // namespace disk_cache | 149 } // namespace disk_cache |
| 103 | 150 |
| 104 #endif // NET_DISK_CACHE_BLOCK_FILES_H_ | 151 #endif // NET_DISK_CACHE_BLOCK_FILES_H_ |
| OLD | NEW |