1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file. 4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// See net/disk_cache/disk_cache.h for the public interface. 6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#ifndef NET_DISK_CACHE_BLOCKFILE_BLOCK_BITMAPS_V3_H_ 8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#define NET_DISK_CACHE_BLOCKFILE_BLOCK_BITMAPS_V3_H_ 9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/files/file_path.h" 11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "net/base/net_export.h" 12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "net/disk_cache/blockfile/addr.h" 13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "net/disk_cache/blockfile/block_files.h" 14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace disk_cache { 16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 17d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)class BackendImplV3; 18d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 19d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// This class is the interface in the v3 disk cache to the set of files holding 20d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// cached data that is small enough to not be efficiently stored in a dedicated 21d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// file (i.e. < kMaxBlockSize). It is primarily used to allocate and free 22d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// regions in those files used to store data. 23d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)class NET_EXPORT_PRIVATE BlockBitmaps { 24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public: 25d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) BlockBitmaps(); 26d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ~BlockBitmaps(); 27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 28d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) void Init(const BlockFilesBitmaps& bitmaps); 29868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Creates a new entry on a block file. block_type indicates the size of block 31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // to be used (as defined on cache_addr.h), block_count is the number of 32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // blocks to allocate, and block_address is the address of the new entry. 33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bool CreateBlock(FileType block_type, int block_count, Addr* block_address); 34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 35d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Removes an entry from the block files. 36d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) void DeleteBlock(Addr address); 37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 38d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Releases the internal bitmaps. The cache is being purged. 39d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) void Clear(); 40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Sends UMA stats. 42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) void ReportStats(); 43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Returns true if the blocks pointed by a given address are currently used. 45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // This method is only intended for debugging. 46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bool IsValid(Addr address); 47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private: 49d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Returns the header number that stores a given address. 50d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) int GetHeaderNumber(Addr address); 51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 52d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Returns the appropriate header to use for a new block. 53d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) int HeaderNumberForNewBlock(FileType block_type, int block_count); 54868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Retrieves stats for the given file index. 56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) void GetFileStats(int index, int* used_count, int* load); 57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 58d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) BlockFilesBitmaps bitmaps_; 59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 60d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(BlockBitmaps); 61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}; 62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} // namespace disk_cache 64868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 65a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif // NET_DISK_CACHE_BLOCKFILE_BLOCK_BITMAPS_V3_H_ 66