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
3 // found in the LICENSE file.
5 // See net/disk_cache/disk_cache.h for the public interface.
7 #ifndef NET_DISK_CACHE_BLOCK_FILES_H_
8 #define NET_DISK_CACHE_BLOCK_FILES_H_
12 #include "base/files/file_path.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "net/base/net_export.h"
16 #include "net/disk_cache/addr.h"
17 #include "net/disk_cache/mapped_file.h"
19 namespace disk_cache
{
21 // This class handles the set of block-files open by the disk cache.
22 class NET_EXPORT_PRIVATE BlockFiles
{
24 explicit BlockFiles(const base::FilePath
& path
);
27 // Performs the object initialization. create_files indicates if the backing
28 // files should be created or just open.
29 bool Init(bool create_files
);
31 // Creates a new entry on a block file. block_type indicates the size of block
32 // to be used (as defined on cache_addr.h), block_count is the number of
33 // blocks to allocate, and block_address is the address of the new entry.
34 bool CreateBlock(FileType block_type
, int block_count
, Addr
* block_address
);
36 // Removes an entry from the block files. If deep is true, the storage is zero
37 // filled; otherwise the entry is removed but the data is not altered (must be
39 void DeleteBlock(Addr address
, bool deep
);
41 // Close all the files and set the internal state to be initializad again. The
42 // cache is being purged.
48 // Returns true if the blocks pointed by a given address are currently used.
49 // This method is only intended for debugging.
50 bool IsValid(Addr address
);
53 // Returns the file that stores a given address.
54 MappedFile
* GetFile(Addr address
);
56 // Attemp to grow this file. Fails if the file cannot be extended anymore.
57 bool GrowBlockFile(MappedFile
* file
, BlockFileHeader
* header
);
59 // Returns the appropriate file to use for a new block.
60 MappedFile
* FileForNewBlock(FileType block_type
, int block_count
);
62 // Restores the header of a potentially inconsistent file.
63 bool FixBlockFileHeader(MappedFile
* file
);
65 // Retrieves stats for the given file index.
66 void GetFileStats(int index
, int* used_count
, int* load
);
70 DISALLOW_COPY_AND_ASSIGN(BlockFiles
);
73 } // namespace disk_cache
75 #endif // NET_DISK_CACHE_BLOCK_FILES_H_