| Index: net/disk_cache/v3/entry_impl_v3.h
|
| ===================================================================
|
| --- net/disk_cache/v3/entry_impl_v3.h (revision 232523)
|
| +++ net/disk_cache/v3/entry_impl_v3.h (working copy)
|
| @@ -2,28 +2,33 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#ifndef NET_DISK_CACHE_ENTRY_IMPL_H_
|
| -#define NET_DISK_CACHE_ENTRY_IMPL_H_
|
| +#ifndef NET_DISK_CACHE_V3_ENTRY_IMPL_V3_H_
|
| +#define NET_DISK_CACHE_V3_ENTRY_IMPL_V3_H_
|
|
|
| +#include <queue>
|
| +#include <string>
|
| +
|
| #include "base/memory/scoped_ptr.h"
|
| #include "net/base/net_log.h"
|
| #include "net/disk_cache/disk_cache.h"
|
| #include "net/disk_cache/storage_block.h"
|
| -#include "net/disk_cache/storage_block-inl.h"
|
| +#include "net/disk_cache/v3/disk_format_v3.h"
|
|
|
| namespace disk_cache {
|
|
|
| -class BackendImpl;
|
| -class InFlightBackendIO;
|
| -class SparseControl;
|
| +class BackendImplV3;
|
| +class SparseControlV3;
|
|
|
| +//typedef StorageBlock<EntryRecord> CacheEntryBlockV3;//?
|
| +//typedef StorageBlock<ShortEntryRecord> CacheShortEntryBlock;
|
| +
|
| // This class implements the Entry interface. An object of this
|
| // class represents a single entry on the cache.
|
| -class NET_EXPORT_PRIVATE EntryImpl
|
| +class NET_EXPORT_PRIVATE EntryImplV3
|
| : public Entry,
|
| - public base::RefCounted<EntryImpl> {
|
| - friend class base::RefCounted<EntryImpl>;
|
| - friend class SparseControl;
|
| + public base::RefCounted<EntryImplV3> {
|
| + friend class base::RefCounted<EntryImplV3>;
|
| + friend class SparseControlV3;
|
| public:
|
| enum Operation {
|
| kRead,
|
| @@ -35,45 +40,38 @@
|
| kWriteAsync1
|
| };
|
|
|
| - EntryImpl(BackendImpl* backend, Addr address, bool read_only);
|
| + EntryImplV3(BackendImplV3* backend, Addr address, bool read_only);
|
| + EntryImplV3(BackendImplV3* backend, Addr address, const std::string& key,
|
| + scoped_ptr<EntryRecord> record);
|
| + EntryImplV3(BackendImplV3* backend, Addr address, const std::string& key,
|
| + scoped_ptr<ShortEntryRecord> record);
|
|
|
| - // Background implementation of the Entry interface.
|
| - void DoomImpl();
|
| - int ReadDataImpl(int index, int offset, IOBuffer* buf, int buf_len,
|
| - const CompletionCallback& callback);
|
| - int WriteDataImpl(int index, int offset, IOBuffer* buf, int buf_len,
|
| - const CompletionCallback& callback, bool truncate);
|
| - int ReadSparseDataImpl(int64 offset, IOBuffer* buf, int buf_len,
|
| - const CompletionCallback& callback);
|
| - int WriteSparseDataImpl(int64 offset, IOBuffer* buf, int buf_len,
|
| - const CompletionCallback& callback);
|
| - int GetAvailableRangeImpl(int64 offset, int len, int64* start);
|
| - void CancelSparseIOImpl();
|
| - int ReadyForSparseIOImpl(const CompletionCallback& callback);
|
| -
|
| - // Performs the initialization of a EntryImpl that will be added to the
|
| + // Performs the initialization of a EntryImplV3 that will be added to the
|
| // cache.
|
| - bool CreateEntry(Addr node_address, const std::string& key, uint32 hash);
|
| + void CreateEntry(const std::string& key, uint32 hash,
|
| + ShortEntryRecord* old_info);
|
| + void OnOpenEntry();
|
|
|
| - uint32 GetHash();
|
| + scoped_ptr<ShortEntryRecord> GetShortEntryRecord();
|
|
|
| + uint32 GetHash() const;
|
| + Addr GetAddress() const;
|
| + int GetReuseCounter() const;
|
| + void SetReuseCounter(int count);
|
| + int GetRefetchCounter() const;
|
| + void SetRefetchCounter(int count);
|
| +
|
| // Returns true if this entry matches the lookup arguments.
|
| bool IsSameEntry(const std::string& key, uint32 hash);
|
|
|
| // Permamently destroys this entry.
|
| void InternalDoom();
|
|
|
| - bool dirty() {
|
| - return dirty_;
|
| - }
|
| -
|
| - bool doomed() {
|
| - return doomed_;
|
| - }
|
| -
|
| // Returns false if the entry is clearly invalid.
|
| bool SanityCheck();
|
| bool DataSanityCheck();
|
| + static bool BasicSanityCheck(const EntryRecord& record);
|
| + static bool DeletedSanityCheck(const ShortEntryRecord& record);
|
|
|
| // Attempts to make this entry reachable though the key.
|
| void FixForDelete();
|
| @@ -82,14 +80,16 @@
|
| // the upgrade tool.
|
| void SetTimes(base::Time last_used, base::Time last_modified);
|
|
|
| - // Logs a begin event and enables logging for the EntryImpl. Will also cause
|
| - // an end event to be logged on destruction. The EntryImpl must have its key
|
| + // Logs a begin event and enables logging for the EntryImplV3. Will also cause
|
| + // an end event to be logged on destruction. The EntryImplV3 must have its key
|
| // initialized before this is called. |created| is true if the Entry was
|
| // created rather than opened.
|
| void BeginLogging(net::NetLog* net_log, bool created);
|
|
|
| const net::BoundNetLog& net_log() const;
|
|
|
| + void NotifyDestructionForTest(const CompletionCallback& callback);
|
| +
|
| // Entry interface.
|
| virtual void Doom() OVERRIDE;
|
| virtual void Close() OVERRIDE;
|
| @@ -118,13 +118,37 @@
|
| };
|
| class UserBuffer;
|
|
|
| - virtual ~EntryImpl();
|
| + enum OperationAction {
|
| + PENDING_READ,
|
| + PENDING_WRITE,
|
| + PENDING_FLUSH,
|
| + PENDING_CLEANUP,
|
| + PENDING_DONE
|
| + };
|
| + struct PendingOperation {
|
| + OperationAction action;
|
| + int index;
|
| + int offset;
|
| + scoped_refptr<IOBuffer> buf;
|
| + int buf_len;
|
| + CompletionCallback callback;
|
| + bool truncate;
|
| + };
|
| + typedef std::queue<PendingOperation> PendingOperations;
|
|
|
| + virtual ~EntryImplV3();
|
| +
|
| + void Cleanup();
|
| +
|
| + void WriteKey();
|
| +
|
| // Do all the work for ReadDataImpl and WriteDataImpl. Implemented as
|
| // separate functions to make logging of results simpler.
|
| - int InternalReadData(int index, int offset, IOBuffer* buf,
|
| - int buf_len, const CompletionCallback& callback);
|
| - int InternalWriteData(int index, int offset, IOBuffer* buf, int buf_len,
|
| + int ReadDataImpl(int index, int offset, IOBuffer* buf,
|
| + int buf_len, PendingOperation* operation,
|
| + const CompletionCallback& callback);
|
| + int WriteDataImpl(int index, int offset, IOBuffer* buf, int buf_len,
|
| + PendingOperation* operation,
|
| const CompletionCallback& callback, bool truncate);
|
|
|
| // Initializes the storage for an internal or external data block.
|
| @@ -133,49 +157,41 @@
|
| // Initializes the storage for an internal or external generic block.
|
| bool CreateBlock(int size, Addr* address);
|
|
|
| - // Deletes the data pointed by address, maybe backed by files_[index].
|
| + // Deletes the data pointed by address.
|
| // Note that most likely the caller should delete (and store) the reference to
|
| // |address| *before* calling this method because we don't want to have an
|
| // entry using an address that is already free.
|
| - void DeleteData(Addr address, int index);
|
| + void DeleteData(Addr address);
|
|
|
| // Updates ranking information.
|
| void UpdateRank(bool modified);
|
|
|
| - // Deletes this entry from disk. If |everything| is false, only the user data
|
| - // will be removed, leaving the key and control data intact.
|
| - void DeleteEntryData(bool everything);
|
| + // Deletes this entry from disk.
|
| + bool DeleteEntryData();
|
|
|
| // Prepares the target file or buffer for a write of buf_len bytes at the
|
| // given offset.
|
| - bool PrepareTarget(int index, int offset, int buf_len, bool truncate);
|
| + int PrepareTarget(int index, int offset, int buf_len, bool truncate);
|
|
|
| // Adjusts the internal buffer and file handle for a write that truncates this
|
| // stream.
|
| - bool HandleTruncation(int index, int offset, int buf_len);
|
| + int HandleTruncation(int index, int offset, int buf_len);
|
|
|
| - // Copies data from disk to the internal buffer.
|
| - bool CopyToLocalBuffer(int index);
|
| + bool IsSimpleWrite(int index, int offset, int buf_len);
|
| + int HandleOldData(int index, int offset, int buf_len);
|
|
|
| - // Reads from a block data file to this object's memory buffer.
|
| - bool MoveToLocalBuffer(int index);
|
| -
|
| - // Loads the external file to this object's memory buffer.
|
| - bool ImportSeparateFile(int index, int new_size);
|
| -
|
| // Makes sure that the internal buffer can handle the a write of |buf_len|
|
| // bytes to |offset|.
|
| - bool PrepareBuffer(int index, int offset, int buf_len);
|
| + int PrepareBuffer(int index, int offset, int buf_len);
|
|
|
| // Flushes the in-memory data to the backing storage. The data destination
|
| // is determined based on the current data length and |min_len|.
|
| - bool Flush(int index, int min_len);
|
| + int Flush(int index, int min_len);
|
|
|
| // Updates the size of a given data stream.
|
| void UpdateSize(int index, int old_size, int new_size);
|
|
|
| - // Initializes the sparse control object. Returns a net error code.
|
| - int InitSparseData();
|
| + void WriteEntryData();
|
|
|
| // Adds the provided |flags| to the current EntryFlags for this entry.
|
| void SetEntryFlags(uint32 flags);
|
| @@ -183,6 +199,10 @@
|
| // Returns the current EntryFlags for this entry.
|
| uint32 GetEntryFlags();
|
|
|
| + void OnEntryModified();
|
| +
|
| + int GetAdjustedSize(int index, int real_size) const;
|
| +
|
| // Gets the data stored at the given index. If the information is in memory,
|
| // a buffer will be allocated and the data will be copied to it (the caller
|
| // can find out the size of the buffer before making this call). Otherwise,
|
| @@ -191,7 +211,7 @@
|
| // responsible for deleting the block (or file) from the backing store at some
|
| // point; there is no need to report any storage-size change, only to do the
|
| // actual cleanup.
|
| - void GetData(int index, char** buffer, Addr* address);
|
| + void GetData(int index, scoped_refptr<IOBuffer>* buffer, Addr* address);
|
|
|
| // Generates a histogram for the time spent working on this operation.
|
| void ReportIOTime(Operation op, const base::TimeTicks& start);
|
| @@ -199,25 +219,32 @@
|
| // Logs this entry to the internal trace buffer.
|
| void Log(const char* msg);
|
|
|
| - CacheEntryBlock entry_; // Key related information for this entry.
|
| - CacheRankingsBlock node_; // Rankings related information for this entry.
|
| - base::WeakPtr<BackendImpl> backend_; // Back pointer to the cache.
|
| - base::WeakPtr<InFlightBackendIO> background_queue_; // In-progress queue.
|
| + void OnIOComplete(int result);
|
| +
|
| + scoped_ptr<EntryRecord> entry_; // Basic record for this entry.
|
| + scoped_ptr<ShortEntryRecord> short_entry_; // Valid for evicted entries.
|
| + base::WeakPtr<BackendImplV3> backend_; // Back pointer to the cache.
|
| scoped_ptr<UserBuffer> user_buffers_[kNumStreams]; // Stores user data.
|
| // Files to store external user data and key.
|
| - scoped_refptr<File> files_[kNumStreams + 1];
|
| + //scoped_refptr<File> files_[kNumStreams + 1];
|
| mutable std::string key_; // Copy of the key.
|
| + Addr address_;
|
| int unreported_size_[kNumStreams]; // Bytes not reported yet to the backend.
|
| + int num_handles_; // References held by "real" users.
|
| bool doomed_; // True if this entry was removed from the cache.
|
| - bool read_only_; // True if not yet writing.
|
| - bool dirty_; // True if we detected that this is a dirty entry.
|
| - scoped_ptr<SparseControl> sparse_; // Support for sparse entries.
|
| + bool read_only_;
|
| + bool dirty_; // True if there is something to write.
|
| + bool modified_;
|
| + scoped_ptr<SparseControlV3> sparse_; // Support for sparse entries.
|
| + PendingOperations pending_operations_;
|
| + CompletionCallback callback_;
|
| + CompletionCallback destruction_callback_;
|
|
|
| net::BoundNetLog net_log_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(EntryImpl);
|
| + DISALLOW_COPY_AND_ASSIGN(EntryImplV3);
|
| };
|
|
|
| } // namespace disk_cache
|
|
|
| -#endif // NET_DISK_CACHE_ENTRY_IMPL_H_
|
| +#endif // NET_DISK_CACHE_V3_ENTRY_IMPL_V3_H_
|
|
|