backend_impl_v3.h revision effb81e5f8246d0db0270817048dc992db66e9fb
1179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// Use of this source code is governed by a BSD-style license that can be 3179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// found in the LICENSE file. 4179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 5179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// See net/disk_cache/disk_cache.h for the public interface of the cache. 6179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 7179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#ifndef NET_DISK_CACHE_BLOCKFILE_BACKEND_IMPL_V3_H_ 8179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#define NET_DISK_CACHE_BLOCKFILE_BACKEND_IMPL_V3_H_ 9179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 10179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#include "base/containers/hash_tables.h" 11179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#include "base/files/file_path.h" 12179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#include "base/timer/timer.h" 13179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#include "net/disk_cache/blockfile/block_bitmaps_v3.h" 14179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#include "net/disk_cache/blockfile/block_files.h" 15179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#include "net/disk_cache/blockfile/eviction_v3.h" 16179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#include "net/disk_cache/blockfile/index_table_v3.h" 17179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#include "net/disk_cache/blockfile/stats.h" 18179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#include "net/disk_cache/blockfile/stress_support.h" 19179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#include "net/disk_cache/blockfile/trace.h" 20179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#include "net/disk_cache/disk_cache.h" 21179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 22179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgnamespace net { 23179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgclass NetLog; 24179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org} // namespace net 25179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 26179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgnamespace disk_cache { 27179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 28179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgclass EntryImplV3; 29179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 30179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// This class implements the Backend interface. An object of this 31179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// class handles the operations of the cache for a particular profile. 32179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgclass NET_EXPORT_PRIVATE BackendImplV3 : public Backend { 33179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org public: 34179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org enum BackendFlags { 35179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org MAX_SIZE = 1 << 1, // A maximum size was provided. 36179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org UNIT_TEST_MODE = 1 << 2, // We are modifying the behavior for testing. 37179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org UPGRADE_MODE = 1 << 3, // This is the upgrade tool (dump). 38179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org EVICTION_V2 = 1 << 4, // Use of new eviction was specified. 39179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org BASIC_UNIT_TEST = 1 << 5, // Identifies almost all unit tests. 40179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org NO_LOAD_PROTECTION = 1 << 6, // Don't act conservatively under load. 41179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org NO_BUFFERING = 1 << 7, // Disable extended IO buffering. 42179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org NO_CLEAN_ON_EXIT = 1 << 8 // Avoid saving data at exit time. 43179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org }; 44179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 45179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org BackendImplV3(const base::FilePath& path, 46179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org base::MessageLoopProxy* cache_thread, 47179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org net::NetLog* net_log); 48179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org virtual ~BackendImplV3(); 49179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 50179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Performs general initialization for this current instance of the cache. 51179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org int Init(const CompletionCallback& callback); 52179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 53179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Same behavior as OpenNextEntry but walks the list from back to front. 54179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org int OpenPrevEntry(void** iter, Entry** prev_entry, 55179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org const CompletionCallback& callback); 56179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 57179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Sets the maximum size for the total amount of data stored by this instance. 58179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org bool SetMaxSize(int max_bytes); 59179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 60179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Sets the cache type for this backend. 61179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void SetType(net::CacheType type); 62179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 63179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Creates a new storage block of size block_count. 64179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org bool CreateBlock(FileType block_type, int block_count, 65179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org Addr* block_address); 66179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 67179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Updates the ranking information for an entry. 68179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void UpdateRank(EntryImplV3* entry, bool modified); 69179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 70179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Permanently deletes an entry, but still keeps track of it. 71179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void InternalDoomEntry(EntryImplV3* entry); 72179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 73179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // This method must be called when an entry is released for the last time, so 74179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // the entry should not be used anymore. |address| is the cache address of the 75179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // entry. 76179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void OnEntryDestroyBegin(Addr address); 77179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 78179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // This method must be called after all resources for an entry have been 79179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // released. 80179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void OnEntryDestroyEnd(); 81179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 82179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // If the |address| corresponds to an open entry, returns a pointer to that 83179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // entry, otherwise returns NULL. Note that this method does not increase the 84179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // ref counter for the entry. 85179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org EntryImplV3* GetOpenEntry(Addr address) const; 86179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 87179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Returns the id being used on this run of the cache. 88179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org int32 GetCurrentEntryId() const; 89179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 90179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Returns the maximum size for a file to reside on the cache. 91179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org int MaxFileSize() const; 92179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 93179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // A user data block is being created, extended or truncated. 94179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void ModifyStorageSize(int32 old_size, int32 new_size); 95179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 96179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Logs requests that are denied due to being too big. 97179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void TooMuchStorageRequested(int32 size); 98179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 99179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Returns true if a temporary buffer is allowed to be extended. 100179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org bool IsAllocAllowed(int current_size, int new_size); 101179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 102179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Tracks the release of |size| bytes by an entry buffer. 103179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void BufferDeleted(int size); 104179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 105179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Only intended for testing the two previous methods. 106179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org int GetTotalBuffersSize() const { 107179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org return buffer_bytes_; 108bf10812927b9a05a7b671eb32504eaa5972725d7sanjay@google.com } 109bf10812927b9a05a7b671eb32504eaa5972725d7sanjay@google.com 110179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Returns true if this instance seems to be under heavy load. 111179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org bool IsLoaded() const; 112179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 113179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Returns the full histogram name, for the given base |name| and the current 114179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // cache type. The name will be "DiskCache3.name_type". 115179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org std::string HistogramName(const char* name) const; 116179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 117179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org net::CacheType cache_type() const { 118179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org return cache_type_; 119179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org } 120179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 121179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org bool read_only() const { 122179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org return read_only_; 123179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org } 124179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 125179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Returns a weak pointer to this object. 126179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org base::WeakPtr<BackendImplV3> GetWeakPtr(); 127179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 128179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Returns true if we should send histograms for this user again. The caller 129179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // must call this function only once per run (because it returns always the 130179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // same thing on a given run). 131179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org bool ShouldReportAgain(); 132179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 133179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Reports some data when we filled up the cache. 134179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void FirstEviction(); 135179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 136179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Called when an interesting event should be logged (counted). 137179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void OnEvent(Stats::Counters an_event); 138179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 139179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Keeps track of payload access (doesn't include metadata). 140179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void OnRead(int bytes); 141179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void OnWrite(int bytes); 142179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 143179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Timer callback to calculate usage statistics and perform backups. 144179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void OnTimerTick(); 145179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 146179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Sets internal parameters to enable unit testing mode. 147179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void SetUnitTestMode(); 148179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 149179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Sets internal parameters to enable upgrade mode (for internal tools). 150179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void SetUpgradeMode(); 151179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 152179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Sets the eviction algorithm to version 2. 153179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void SetNewEviction(); 154179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 155179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Sets an explicit set of BackendFlags. 156179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void SetFlags(uint32 flags); 157179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 158179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Sends a dummy operation through the operation queue, for unit tests. 159179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org int FlushQueueForTest(const CompletionCallback& callback); 160179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 161179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Trims an entry (all if |empty| is true) from the list of deleted 162179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // entries. This method should be called directly on the cache thread. 163179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void TrimForTest(bool empty); 164179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 165179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Trims an entry (all if |empty| is true) from the list of deleted 166179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // entries. This method should be called directly on the cache thread. 167179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void TrimDeletedListForTest(bool empty); 168179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 169179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Performs a simple self-check, and returns the number of dirty items 170179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // or an error code (negative value). 171179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org int SelfCheck(); 172179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 173179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Backend implementation. 174179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org virtual net::CacheType GetCacheType() const OVERRIDE; 175179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org virtual int32 GetEntryCount() const OVERRIDE; 176179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org virtual int OpenEntry(const std::string& key, Entry** entry, 177179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org const CompletionCallback& callback) OVERRIDE; 178179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org virtual int CreateEntry(const std::string& key, Entry** entry, 179179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org const CompletionCallback& callback) OVERRIDE; 180179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org virtual int DoomEntry(const std::string& key, 181179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org const CompletionCallback& callback) OVERRIDE; 182179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; 183179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org virtual int DoomEntriesBetween(base::Time initial_time, 184179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org base::Time end_time, 185179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org const CompletionCallback& callback) OVERRIDE; 186179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org virtual int DoomEntriesSince(base::Time initial_time, 187179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org const CompletionCallback& callback) OVERRIDE; 188179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org virtual int OpenNextEntry(void** iter, Entry** next_entry, 189179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org const CompletionCallback& callback) OVERRIDE; 190179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org virtual void EndEnumeration(void** iter) OVERRIDE; 191179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org virtual void GetStats(StatsItems* stats) OVERRIDE; 192179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; 193179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 194179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org private: 195179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org friend class EvictionV3; 196179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org typedef base::hash_map<CacheAddr, EntryImplV3*> EntriesMap; 197179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org class Worker; 198179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 199179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void AdjustMaxCacheSize(); 200179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org bool InitStats(void* stats_data); 201179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void StoreStats(); 202179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 203179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Deletes the cache and starts again. 204179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void RestartCache(bool failure); 205179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void PrepareForRestart(); 206179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 207179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Performs final cleanup. 208179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void CleanupCache(); 209179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 210179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Creates a new entry object. Returns zero on success, or a disk_cache error 211179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // on failure. 212179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org int NewEntry(Addr address, EntryImplV3** entry); 213179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 214179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Opens the next or previous entry on a cache iteration. 215179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org int OpenFollowingEntry(bool forward, void** iter, Entry** next_entry, 216179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org const CompletionCallback& callback); 217179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 218179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Handles the used storage count. 219179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void AddStorageSize(int32 bytes); 220179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void SubstractStorageSize(int32 bytes); 221179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 222179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Update the number of referenced cache entries. 223179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void IncreaseNumRefs(); 224179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void DecreaseNumRefs(); 225179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void IncreaseNumEntries(); 226179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void DecreaseNumEntries(); 227179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 228179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Dumps current cache statistics to the log. 229179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void LogStats(); 230179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 231179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Send UMA stats. 232179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void ReportStats(); 233179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 234179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Reports an uncommon, recoverable error. 235179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org void ReportError(int error); 236179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 237179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Performs basic checks on the index file. Returns false on failure. 238179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org bool CheckIndex(); 239179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 240179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Part of the self test. Returns the number or dirty entries, or an error. 241179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org int CheckAllEntries(); 242179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 243179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Part of the self test. Returns false if the entry is corrupt. 244179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org bool CheckEntry(EntryImplV3* cache_entry); 245179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 246179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org // Returns the maximum total memory for the memory buffers. 247179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org int MaxBuffersSize(); 248179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 249179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org IndexTable index_; 250179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org base::FilePath path_; // Path to the folder used as backing storage. 251179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org BlockBitmaps block_files_; 252179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org int32 max_size_; // Maximum data size for this instance. 253179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org EvictionV3 eviction_; // Handler of the eviction algorithm. 254179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org EntriesMap open_entries_; 255179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org int num_refs_; // Number of referenced cache entries. 256179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org int max_refs_; // Max number of referenced cache entries. 257179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org int entry_count_; // Number of entries accessed lately. 258179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org int byte_count_; // Number of bytes read/written lately. 259179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org int buffer_bytes_; // Total size of the temporary entries' buffers. 260179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org int up_ticks_; // The number of timer ticks received (OnTimerTick). 261179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org net::CacheType cache_type_; 262179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org int uma_report_; // Controls transmission of UMA data. 263179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org uint32 user_flags_; // Flags set by the user. 264179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org bool init_; // controls the initialization of the system. 265179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org bool restarted_; 266179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org bool read_only_; // Prevents updates of the rankings data (used by tools). 267179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org bool disabled_; 268179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org bool lru_eviction_; // What eviction algorithm should be used. 269179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org bool first_timer_; // True if the timer has not been called. 270179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org bool user_load_; // True if we see a high load coming from the caller. 271179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 272179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org net::NetLog* net_log_; 273179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 274179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org Stats stats_; // Usage statistics. 275179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org scoped_ptr<base::RepeatingTimer<BackendImplV3> > timer_; // Usage timer. 276179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org scoped_refptr<TraceObject> trace_object_; // Initializes internal tracing. 277179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org base::WeakPtrFactory<BackendImplV3> ptr_factory_; 278179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 279179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org DISALLOW_COPY_AND_ASSIGN(BackendImplV3); 280179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org}; 281179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 282179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org} // namespace disk_cache 283179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 284179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#endif // NET_DISK_CACHE_BLOCKFILE_BACKEND_IMPL_V3_H_ 285179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org