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

Unified Diff: net/disk_cache/block_files.h

Issue 15203004: Disk cache: Reference CL for the implementation of file format version 3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: IndexTable review Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/disk_cache/backend_unittest.cc ('k') | net/disk_cache/block_files.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/block_files.h
===================================================================
--- net/disk_cache/block_files.h (revision 199883)
+++ net/disk_cache/block_files.h (working copy)
@@ -14,6 +14,7 @@
#include "base/memory/scoped_ptr.h"
#include "net/base/net_export.h"
#include "net/disk_cache/addr.h"
+#include "net/disk_cache/disk_format_base.h"
#include "net/disk_cache/mapped_file.h"
namespace base {
@@ -22,6 +23,67 @@
namespace disk_cache {
+// An instance of this class represents the header of a block file in memory.
+// Note that this class doesn't perform any file operation (as in it only deals
+// with entities in memory).
+// The header of a block file (and hence, this object) is all that is needed to
+// perform common operations like allocating or releasing space for storage;
+// actual access to that storage, however, is not performed through this class.
+class NET_EXPORT_PRIVATE BlockHeader {
+ public:
+ BlockHeader();
+ explicit BlockHeader(BlockFileHeader* header);
+ explicit BlockHeader(MappedFile* file);
+ BlockHeader(const BlockHeader& other);
+ ~BlockHeader();
+
+ // Creates a new entry of |size| blocks on the allocation map, updating the
+ // apropriate counters.
+ bool CreateMapBlock(int size, int* index);
+
+ // Deletes the block pointed by |index|.
+ void DeleteMapBlock(int index, int block_size);
+
+ // Returns true if the specified block is used.
+ bool UsedMapBlock(int index, int size);
+
+ // Restores the "empty counters" and allocation hints.
+ void FixAllocationCounters();
+
+ // Returns true if the current block file should not be used as-is to store
+ // more records. |block_count| is the number of blocks to allocate.
+ bool NeedToGrowBlockFile(int block_count) const;
+
+ // Returns true if this block file can be used to store an extra record of
+ // size |block_count|.
+ bool CanAllocate(int block_count) const;
+
+ // Returns the number of empty blocks for this file.
+ int EmptyBlocks() const;
+
+ // Returns the minumum number of allocations that can be satisfied.
+ int MinimumAllocations() const;
+
+ // Returns the number of blocks that this file can store.
+ int Capacity() const;
+
+ // Returns true if the counters look OK.
+ bool ValidateCounters() const;
+
+ // Returns the identifiers of this and the next file (0 if there is none).
+ int FileId() const;
+ int NextFileId() const;
+
+ // Returns a pointer to the underlying BlockFileHeader.
+ // TODO(rvargas): This may be removed with the support for V2.
+ BlockFileHeader* Header();
+
+ private:
+ BlockFileHeader* header_;
+};
+
+typedef std::vector<BlockHeader> BlockFilesBitmaps;
+
// This class handles the set of block-files open by the disk cache.
class NET_EXPORT_PRIVATE BlockFiles {
public:
@@ -30,8 +92,11 @@
// Performs the object initialization. create_files indicates if the backing
// files should be created or just open.
- bool Init(bool create_files);
+ bool Init(bool create_files, int num_files);
+ // Returns the allocation bitmaps for all the files managed by this object.
+ void GetBitmaps(int num_files, BlockFilesBitmaps* bitmaps);
+
// Returns the file that stores a given address.
MappedFile* GetFile(Addr address);
@@ -56,13 +121,16 @@
// This method is only intended for debugging.
bool IsValid(Addr address);
+ // Increments the size of files very slowly.
+ void UseSmallSizeIncrementsForTest() { small_steps_ = true; }
+
private:
// Set force to true to overwrite the file if it exists.
bool CreateBlockFile(int index, FileType file_type, bool force);
bool OpenBlockFile(int index);
// Attemp to grow this file. Fails if the file cannot be extended anymore.
- bool GrowBlockFile(MappedFile* file, BlockFileHeader* header);
+ bool GrowBlockFile(BlockFileHeader* header);
// Returns the appropriate file to use for a new block.
MappedFile* FileForNewBlock(FileType block_type, int block_count);
@@ -70,25 +138,40 @@
// Returns the next block file on this chain, creating new files if needed.
MappedFile* NextFile(MappedFile* file);
+ // Returns the file index that stores a given address, or -1 on failure.
+ int GetFileIndex(Addr address);
+
+ // Returns the header file that stores a given address.
+ MappedFile* GetFileHeader(Addr address);
+
// Creates an empty block file and returns its index.
int CreateNextBlockFile(FileType block_type);
// Removes a chained block file that is now empty.
bool RemoveEmptyFile(FileType block_type);
+ bool PreallocateSpace(FileType block_type);
+
// Restores the header of a potentially inconsistent file.
- bool FixBlockFileHeader(MappedFile* file);
+ bool FixBlockFileHeader(int index);//pass BlockHeader instead.
// Retrieves stats for the given file index.
void GetFileStats(int index, int* used_count, int* load);
- // Returns the filename for a given file index.
- base::FilePath Name(int index);
+ // Returns the filename for the header section, given a file index.
+ base::FilePath HeaderName(int index);
+ // Returns the filename for the data portion, given a file index.
+ base::FilePath DataName(int index);
+
bool init_;
+ bool small_steps_;
+ int data_offset_; // Zero for V3.
char* zero_buffer_; // Buffer to speed-up cleaning deleted entries.
base::FilePath path_; // Path to the backing folder.
- std::vector<MappedFile*> block_files_; // The actual files.
+ std::vector<MappedFile*> block_headers_; // The block file headers.
+ std::vector<MappedFile*> block_data_; // The user data (if not stored with
+ // the header).
scoped_ptr<base::ThreadChecker> thread_checker_;
FRIEND_TEST_ALL_PREFIXES(DiskCacheTest, BlockFiles_ZeroSizeFile);
« no previous file with comments | « net/disk_cache/backend_unittest.cc ('k') | net/disk_cache/block_files.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698