Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(544)

Side by Side Diff: net/disk_cache/block_files.h

Issue 17816008: Disk cache: Introduce BlockBitmaps for V3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/disk_cache/block_files.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 (as in it only deals
28 // with entities in memory).
29 // The header of a block file (and hence, this object) is all that is needed to
30 // perform common operations like allocating or releasing space for storage;
31 // actual access to that storage, however, is not performed through this class.
28 class NET_EXPORT_PRIVATE BlockHeader { 32 class NET_EXPORT_PRIVATE BlockHeader {
29 public: 33 public:
30 BlockHeader(); 34 BlockHeader();
31 explicit BlockHeader(BlockFileHeader* header); 35 explicit BlockHeader(BlockFileHeader* header);
32 explicit BlockHeader(MappedFile* file); 36 explicit BlockHeader(MappedFile* file);
33 BlockHeader(const BlockHeader& other); 37 BlockHeader(const BlockHeader& other);
34 ~BlockHeader(); 38 ~BlockHeader();
35 39
36 // Creates a new entry on the allocation map, updating the apropriate 40 // Creates a new entry of |size| blocks on the allocation map, updating the
37 // counters. |target| is the type of block to use (number of empty blocks), 41 // apropriate counters.
38 // and |size| is the actual number of blocks to use. 42 bool CreateMapBlock(int size, int* index);
39 bool CreateMapBlock(int target, int size, int* index);
40 43
41 // Deletes the block pointed by |index|. 44 // Deletes the block pointed by |index|.
42 void DeleteMapBlock(int index, int block_size); 45 void DeleteMapBlock(int index, int block_size);
43 46
44 // Returns true if the specified block is used. 47 // Returns true if the specified block is used.
45 bool UsedMapBlock(int index, int size); 48 bool UsedMapBlock(int index, int size);
46 49
47 // Restores the "empty counters" and allocation hints. 50 // Restores the "empty counters" and allocation hints.
48 void FixAllocationCounters(); 51 void FixAllocationCounters();
49 52
50 // Returns true if the current block file should not be used as-is to store 53 // 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. 54 // more records. |block_count| is the number of blocks to allocate.
52 bool NeedToGrowBlockFile(int block_count); 55 bool NeedToGrowBlockFile(int block_count) const;
56
57 // Returns true if this block file can be used to store an extra record of
58 // size |block_count|.
59 bool CanAllocate(int block_count) const;
53 60
54 // Returns the number of empty blocks for this file. 61 // Returns the number of empty blocks for this file.
55 int EmptyBlocks() const; 62 int EmptyBlocks() const;
56 63
64 // Returns the minumum number of allocations that can be satisfied.
65 int MinimumAllocations() const;
66
67 // Returns the number of blocks that this file can store.
68 int Capacity() const;
69
57 // Returns true if the counters look OK. 70 // Returns true if the counters look OK.
58 bool ValidateCounters() const; 71 bool ValidateCounters() const;
59 72
73 // Returns the identifiers of this and the next file (0 if there is none).
74 int FileId() const;
75 int NextFileId() const;
76
60 // Returns the size of the wrapped structure (BlockFileHeader). 77 // Returns the size of the wrapped structure (BlockFileHeader).
61 int Size() const; 78 int Size() const;
62 79
63 BlockFileHeader* operator->() { return header_; } 80 // Returns a pointer to the underlying BlockFileHeader.
64 void operator=(const BlockHeader& other) { header_ = other.header_; } 81 // TODO(rvargas): This may be removed with the support for V2.
65 BlockFileHeader* Get() { return header_; } 82 BlockFileHeader* Header();
66 83
67 private: 84 private:
68 BlockFileHeader* header_; 85 BlockFileHeader* header_;
69 }; 86 };
70 87
71 typedef std::vector<BlockHeader> BlockFilesBitmaps; 88 typedef std::vector<BlockHeader> BlockFilesBitmaps;
72 89
73 // This class handles the set of block-files open by the disk cache. 90 // This class handles the set of block-files open by the disk cache.
74 class NET_EXPORT_PRIVATE BlockFiles { 91 class NET_EXPORT_PRIVATE BlockFiles {
75 public: 92 public:
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_TruncatedFile); 160 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_TruncatedFile);
144 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_InvalidFile); 161 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_InvalidFile);
145 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_Stats); 162 FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_Stats);
146 163
147 DISALLOW_COPY_AND_ASSIGN(BlockFiles); 164 DISALLOW_COPY_AND_ASSIGN(BlockFiles);
148 }; 165 };
149 166
150 } // namespace disk_cache 167 } // namespace disk_cache
151 168
152 #endif // NET_DISK_CACHE_BLOCK_FILES_H_ 169 #endif // NET_DISK_CACHE_BLOCK_FILES_H_
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/block_files.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698