1ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// Use of this source code is governed by a BSD-style license that can be 3c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// found in the LICENSE file. 4c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 5c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#ifndef NET_DISK_CACHE_ENTRY_IMPL_H_ 6c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#define NET_DISK_CACHE_ENTRY_IMPL_H_ 73345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#pragma once 8c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 9ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "base/memory/scoped_ptr.h" 103f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen#include "net/base/net_log.h" 11c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "net/disk_cache/disk_cache.h" 12c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "net/disk_cache/storage_block.h" 13c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "net/disk_cache/storage_block-inl.h" 14c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 15c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottnamespace disk_cache { 16c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 17c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass BackendImpl; 18c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass SparseControl; 19c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 20c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// This class implements the Entry interface. An object of this 21c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// class represents a single entry on the cache. 22c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass EntryImpl : public Entry, public base::RefCounted<EntryImpl> { 23c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott friend class base::RefCounted<EntryImpl>; 24c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott friend class SparseControl; 25c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott public: 26c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott enum Operation { 27c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott kRead, 28c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott kWrite, 29c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott kSparseRead, 30c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott kSparseWrite, 31c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott kAsyncIO 32c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott }; 33c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 343345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick EntryImpl(BackendImpl* backend, Addr address, bool read_only); 35c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 36c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Background implementation of the Entry interface. 37c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void DoomImpl(); 38c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch int ReadDataImpl(int index, int offset, net::IOBuffer* buf, int buf_len, 39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch CompletionCallback* callback); 40c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch int WriteDataImpl(int index, int offset, net::IOBuffer* buf, int buf_len, 41c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch CompletionCallback* callback, bool truncate); 42c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch int ReadSparseDataImpl(int64 offset, net::IOBuffer* buf, int buf_len, 43c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch CompletionCallback* callback); 44c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch int WriteSparseDataImpl(int64 offset, net::IOBuffer* buf, int buf_len, 45c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch CompletionCallback* callback); 46c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch int GetAvailableRangeImpl(int64 offset, int len, int64* start); 47c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void CancelSparseIOImpl(); 48c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch int ReadyForSparseIOImpl(CompletionCallback* callback); 49c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 50c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott inline CacheEntryBlock* entry() { 51c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott return &entry_; 52c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 53c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 54c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott inline CacheRankingsBlock* rankings() { 55c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott return &node_; 56c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott } 57c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 58c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott uint32 GetHash(); 59c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 60c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Performs the initialization of a EntryImpl that will be added to the 61c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // cache. 62c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool CreateEntry(Addr node_address, const std::string& key, uint32 hash); 63c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 64c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Returns true if this entry matches the lookup arguments. 65c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool IsSameEntry(const std::string& key, uint32 hash); 66c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 67c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Permamently destroys this entry. 68c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott void InternalDoom(); 69c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 70c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Deletes this entry from disk. If |everything| is false, only the user data 71c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // will be removed, leaving the key and control data intact. 72c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott void DeleteEntryData(bool everything); 73c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 74c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Returns the address of the next entry on the list of entries with the same 75c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // hash. 76c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott CacheAddr GetNextAddress(); 77c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 78c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Sets the address of the next entry on the list of entries with the same 79c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // hash. 80c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott void SetNextAddress(Addr address); 81c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 82c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Reloads the rankings node information. 83c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool LoadNodeAddress(); 84c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 85c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Updates the stored data to reflect the run-time information for this entry. 86c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Returns false if the data could not be updated. The purpose of this method 87c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // is to be able to detect entries that are currently in use. 88c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool Update(); 89c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 90dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen bool dirty() { 91dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen return dirty_; 92dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen } 93dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen 94dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen bool doomed() { 95dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen return doomed_; 96dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen } 97dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen 98dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen // Marks this entry as dirty (in memory) if needed. This is intended only for 99dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen // entries that are being read from disk, to be called during loading. 100dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen void SetDirtyFlag(int32 current_id); 101c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 102c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Fixes this entry so it can be treated as valid (to delete it). 103c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott void SetPointerForInvalidEntry(int32 new_id); 104c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 105ae2796cabb52f6a27c50818b78107d3ebc858e0cKristian Monsen // Returns true if this entry is so meesed up that not everything is going to 106ae2796cabb52f6a27c50818b78107d3ebc858e0cKristian Monsen // be removed. 107ae2796cabb52f6a27c50818b78107d3ebc858e0cKristian Monsen bool LeaveRankingsBehind(); 108ae2796cabb52f6a27c50818b78107d3ebc858e0cKristian Monsen 109c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Returns false if the entry is clearly invalid. 110c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool SanityCheck(); 111ae2796cabb52f6a27c50818b78107d3ebc858e0cKristian Monsen bool DataSanityCheck(); 112ae2796cabb52f6a27c50818b78107d3ebc858e0cKristian Monsen 113ae2796cabb52f6a27c50818b78107d3ebc858e0cKristian Monsen // Attempts to make this entry reachable though the key. 114ae2796cabb52f6a27c50818b78107d3ebc858e0cKristian Monsen void FixForDelete(); 115c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 116c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Handle the pending asynchronous IO count. 117c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott void IncrementIoCount(); 118c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott void DecrementIoCount(); 119c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 120c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Set the access times for this entry. This method provides support for 121c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // the upgrade tool. 122c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott void SetTimes(base::Time last_used, base::Time last_modified); 123c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 124c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Generates a histogram for the time spent working on this operation. 125c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void ReportIOTime(Operation op, const base::TimeTicks& start); 126c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1273f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen // Logs a begin event and enables logging for the EntryImpl. Will also cause 1283f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen // an end event to be logged on destruction. The EntryImpl must have its key 1293f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen // initialized before this is called. |created| is true if the Entry was 1303f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen // created rather than opened. 1313f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen void BeginLogging(net::NetLog* net_log, bool created); 1323f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen 1333f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen const net::BoundNetLog& net_log() const; 1343f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen 135ea380985f4dd3c72953f7df161674e1644d6de90Kristian Monsen // Returns the number of blocks needed to store an EntryStore. 136ea380985f4dd3c72953f7df161674e1644d6de90Kristian Monsen static int NumBlocksForEntry(int key_size); 137ea380985f4dd3c72953f7df161674e1644d6de90Kristian Monsen 1383f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen // Entry interface. 1393f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen virtual void Doom(); 1403f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen virtual void Close(); 1413f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen virtual std::string GetKey() const; 1423f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen virtual base::Time GetLastUsed() const; 1433f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen virtual base::Time GetLastModified() const; 1443f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen virtual int32 GetDataSize(int index) const; 1453f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, 1463f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen net::CompletionCallback* completion_callback); 1473f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, 1483f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen net::CompletionCallback* completion_callback, 1493f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen bool truncate); 1503f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen virtual int ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, 1513f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen net::CompletionCallback* completion_callback); 1523f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen virtual int WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len, 1533f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen net::CompletionCallback* completion_callback); 1543f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen virtual int GetAvailableRange(int64 offset, int len, int64* start, 1553f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen CompletionCallback* callback); 1563f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen virtual bool CouldBeSparse() const; 1573f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen virtual void CancelSparseIO(); 1583f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen virtual int ReadyForSparseIO(net::CompletionCallback* completion_callback); 1593f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen 160c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott private: 161c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott enum { 162c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott kNumStreams = 3 163c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott }; 1643345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick class UserBuffer; 165c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 166c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott ~EntryImpl(); 167c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 1683f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen // Do all the work for ReadDataImpl and WriteDataImpl. Implemented as 1693f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen // separate functions to make logging of results simpler. 1703f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen int InternalReadData(int index, int offset, net::IOBuffer* buf, 1713f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen int buf_len, CompletionCallback* callback); 1723f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen int InternalWriteData(int index, int offset, net::IOBuffer* buf, int buf_len, 1733f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen CompletionCallback* callback, bool truncate); 1743f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen 175c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Initializes the storage for an internal or external data block. 176c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool CreateDataBlock(int index, int size); 177c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 178c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Initializes the storage for an internal or external generic block. 179c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool CreateBlock(int size, Addr* address); 180c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 181c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Deletes the data pointed by address, maybe backed by files_[index]. 1823345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // Note that most likely the caller should delete (and store) the reference to 1833345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // |address| *before* calling this method because we don't want to have an 1843345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // entry using an address that is already free. 185c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott void DeleteData(Addr address, int index); 186c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 187c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Updates ranking information. 188c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott void UpdateRank(bool modified); 189c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 190c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Returns a pointer to the file that stores the given address. 191c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott File* GetBackingFile(Addr address, int index); 192c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 193c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Returns a pointer to the file that stores external data. 194c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott File* GetExternalFile(Addr address, int index); 195c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 196c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Prepares the target file or buffer for a write of buf_len bytes at the 197c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // given offset. 198c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool PrepareTarget(int index, int offset, int buf_len, bool truncate); 199c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 2003345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // Adjusts the internal buffer and file handle for a write that truncates this 2013345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // stream. 2023345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick bool HandleTruncation(int index, int offset, int buf_len); 2033345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick 2043345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // Copies data from disk to the internal buffer. 2053345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick bool CopyToLocalBuffer(int index); 206c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 207c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Reads from a block data file to this object's memory buffer. 208c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool MoveToLocalBuffer(int index); 209c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 210c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Loads the external file to this object's memory buffer. 2113345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick bool ImportSeparateFile(int index, int new_size); 2123345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick 2133345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // Makes sure that the internal buffer can handle the a write of |buf_len| 2143345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // bytes to |offset|. 2153345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick bool PrepareBuffer(int index, int offset, int buf_len); 2163345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick 2173345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // Flushes the in-memory data to the backing storage. The data destination 2183345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // is determined based on the current data length and |min_len|. 2193345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick bool Flush(int index, int min_len); 220c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 2213345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick // Updates the size of a given data stream. 2223345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick void UpdateSize(int index, int old_size, int new_size); 223c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 224c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Initializes the sparse control object. Returns a net error code. 225c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott int InitSparseData(); 226c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 227c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Adds the provided |flags| to the current EntryFlags for this entry. 228c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott void SetEntryFlags(uint32 flags); 229c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 230c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Returns the current EntryFlags for this entry. 231c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott uint32 GetEntryFlags(); 232c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 233c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Gets the data stored at the given index. If the information is in memory, 234c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // a buffer will be allocated and the data will be copied to it (the caller 235c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // can find out the size of the buffer before making this call). Otherwise, 236c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // the cache address of the data will be returned, and that address will be 237c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // removed from the regular book keeping of this entry so the caller is 238c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // responsible for deleting the block (or file) from the backing store at some 239c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // point; there is no need to report any storage-size change, only to do the 240c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // actual cleanup. 241c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott void GetData(int index, char** buffer, Addr* address); 242c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 243c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Logs this entry to the internal trace buffer. 244c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott void Log(const char* msg); 245c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 246c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott CacheEntryBlock entry_; // Key related information for this entry. 247c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott CacheRankingsBlock node_; // Rankings related information for this entry. 248c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott BackendImpl* backend_; // Back pointer to the cache. 2493345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick scoped_ptr<UserBuffer> user_buffers_[kNumStreams]; // Stores user data. 250c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott // Files to store external user data and key. 251c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott scoped_refptr<File> files_[kNumStreams + 1]; 252c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch mutable std::string key_; // Copy of the key. 253c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott int unreported_size_[kNumStreams]; // Bytes not reported yet to the backend. 254c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott bool doomed_; // True if this entry was removed from the cache. 2553345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick bool read_only_; // True if not yet writing. 256dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen bool dirty_; // True if we detected that this is a dirty entry. 257c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott scoped_ptr<SparseControl> sparse_; // Support for sparse entries. 258c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 2593f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen net::BoundNetLog net_log_; 2603f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen 261c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch DISALLOW_COPY_AND_ASSIGN(EntryImpl); 262c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}; 263c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 264c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} // namespace disk_cache 265c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 266c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#endif // NET_DISK_CACHE_ENTRY_IMPL_H_ 267