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. |
gavinp
2013/08/05 17:06:15
Is "file operation" well defined?
This class defi
rvargas (doing something else)
2013/08/05 19:50:45
I meant the usual meaning of file operations (file
Randy Smith (Not in Mondays)
2013/08/05 20:23:49
For what it's worth, this confused me a bit too wh
rvargas (doing something else)
2013/08/05 21:03:02
Now I'm confused too. I can certainly remove the c
gavinp
2013/08/06 01:11:02
Is this class constructed on something other than
gavinp
2013/08/06 01:11:02
Dereferencing a pointer into a memory map is no di
Randy Smith (Not in Mondays)
2013/08/06 15:16:28
Just to make explicit what may be obvious to both
| |
28 class NET_EXPORT_PRIVATE BlockHeader { | 28 class NET_EXPORT_PRIVATE BlockHeader { |
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); |
gavinp
2013/08/05 17:06:15
Is it appropriate to add a TODO(rvargas): Remove t
gavinp
2013/08/26 14:30:56
Do these TODO comments make sense? I was asking as
rvargas (doing something else)
2013/09/11 02:49:53
I added a TODO at line 81 of PS9... I thought that
| |
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 // Returns a pointer to the underlying BlockFileHeader. |
gavinp
2013/08/05 17:06:15
Is it appropriate to add a TODO(rvargas): Remove t
gavinp
2013/08/26 14:30:56
Do these TODO comments make sense? I was asking as
| |
64 void operator=(const BlockHeader& other) { header_ = other.header_; } | 68 BlockFileHeader* Header(); |
65 BlockFileHeader* Get() { return header_; } | |
66 | 69 |
67 private: | 70 private: |
68 BlockFileHeader* header_; | 71 BlockFileHeader* header_; |
69 }; | 72 }; |
70 | 73 |
71 typedef std::vector<BlockHeader> BlockFilesBitmaps; | 74 typedef std::vector<BlockHeader> BlockFilesBitmaps; |
gavinp
2013/08/05 17:06:15
In reviewing this code, I think this typedef is ca
rvargas (doing something else)
2013/08/05 19:50:45
It is used more that twice on the V3 code. This is
gavinp
2013/08/26 14:30:56
I'll go look at the V3 code. But I'm still scared;
rvargas (doing something else)
2013/09/11 02:49:53
I could move the define to block_bitmaps.h in this
| |
72 | 75 |
73 // This class handles the set of block-files open by the disk cache. | 76 // This class handles the set of block-files open by the disk cache. |
74 class NET_EXPORT_PRIVATE BlockFiles { | 77 class NET_EXPORT_PRIVATE BlockFiles { |
75 public: | 78 public: |
76 explicit BlockFiles(const base::FilePath& path); | 79 explicit BlockFiles(const base::FilePath& path); |
77 ~BlockFiles(); | 80 ~BlockFiles(); |
78 | 81 |
79 // Performs the object initialization. create_files indicates if the backing | 82 // Performs the object initialization. create_files indicates if the backing |
80 // files should be created or just open. | 83 // files should be created or just open. |
81 bool Init(bool create_files); | 84 bool Init(bool create_files); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_TruncatedFile); | 146 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_TruncatedFile); |
144 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_InvalidFile); | 147 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_InvalidFile); |
145 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_Stats); | 148 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_Stats); |
146 | 149 |
147 DISALLOW_COPY_AND_ASSIGN(BlockFiles); | 150 DISALLOW_COPY_AND_ASSIGN(BlockFiles); |
148 }; | 151 }; |
149 | 152 |
150 } // namespace disk_cache | 153 } // namespace disk_cache |
151 | 154 |
152 #endif // NET_DISK_CACHE_BLOCK_FILES_H_ | 155 #endif // NET_DISK_CACHE_BLOCK_FILES_H_ |
OLD | NEW |