OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef NET_DISK_CACHE_V3_ENTRY_OPERATION_H_ |
| 6 #define NET_DISK_CACHE_V3_ENTRY_OPERATION_H_ |
| 7 |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "net/base/net_log.h" |
| 10 #include "net/disk_cache/disk_cache.h" |
| 11 #include "net/disk_cache/v3/storage_block.h" |
| 12 #include "net/disk_cache/v3/disk_format_v3.h" |
| 13 |
| 14 namespace disk_cache { |
| 15 |
| 16 |
| 17 // This class implements the Entry interface. An object of this |
| 18 // class represents a single entry on the cache. |
| 19 class EntryOperation : public base::RefCounted<EntryOperation> { |
| 20 friend class base::RefCounted<EntryOperation>; |
| 21 public: |
| 22 enum OperationType { |
| 23 |
| 24 }; |
| 25 |
| 26 EntryOperation(BackendImplV3* backend, Addr address, bool read_only); |
| 27 EntryOperation(BackendImplV3* backend, Addr address, const std::string& key, |
| 28 scoped_ptr<EntryRecord> record); |
| 29 |
| 30 |
| 31 private: |
| 32 ~EntryOperation(); |
| 33 |
| 34 // Do all the work for ReadDataImpl and WriteDataImpl. Implemented as |
| 35 // separate functions to make logging of results simpler. |
| 36 int InternalReadData(int index, int offset, IOBuffer* buf, |
| 37 int buf_len, const CompletionCallback& callback); |
| 38 int InternalWriteData(int index, int offset, IOBuffer* buf, int buf_len, |
| 39 const CompletionCallback& callback, bool truncate); |
| 40 |
| 41 // Initializes the storage for an internal or external data block. |
| 42 bool CreateDataBlock(int index, int size); |
| 43 |
| 44 // Initializes the storage for an internal or external generic block. |
| 45 bool CreateBlock(int size, Addr* address); |
| 46 |
| 47 // Deletes the data pointed by address, maybe backed by files_[index]. |
| 48 // Note that most likely the caller should delete (and store) the reference to |
| 49 // |address| *before* calling this method because we don't want to have an |
| 50 // entry using an address that is already free. |
| 51 void DeleteData(Addr address, int index); |
| 52 |
| 53 // Updates ranking information. |
| 54 void UpdateRank(bool modified); |
| 55 |
| 56 // Returns a pointer to the file that stores the given address. |
| 57 File* GetBackingFile(Addr address, int index); |
| 58 |
| 59 // Returns a pointer to the file that stores external data. |
| 60 File* GetExternalFile(Addr address, int index); |
| 61 |
| 62 // Prepares the target file or buffer for a write of buf_len bytes at the |
| 63 // given offset. |
| 64 bool PrepareTarget(int index, int offset, int buf_len, bool truncate); |
| 65 |
| 66 // Adjusts the internal buffer and file handle for a write that truncates this |
| 67 // stream. |
| 68 bool HandleTruncation(int index, int offset, int buf_len); |
| 69 |
| 70 // Copies data from disk to the internal buffer. |
| 71 bool CopyToLocalBuffer(int index); |
| 72 |
| 73 // Reads from a block data file to this object's memory buffer. |
| 74 bool MoveToLocalBuffer(int index); |
| 75 |
| 76 // Loads the external file to this object's memory buffer. |
| 77 bool ImportSeparateFile(int index, int new_size); |
| 78 |
| 79 // Makes sure that the internal buffer can handle the a write of |buf_len| |
| 80 // bytes to |offset|. |
| 81 bool PrepareBuffer(int index, int offset, int buf_len); |
| 82 |
| 83 // Flushes the in-memory data to the backing storage. The data destination |
| 84 // is determined based on the current data length and |min_len|. |
| 85 bool Flush(int index, int min_len); |
| 86 |
| 87 // Updates the size of a given data stream. |
| 88 void UpdateSize(int index, int old_size, int new_size); |
| 89 |
| 90 // Initializes the sparse control object. Returns a net error code. |
| 91 int InitSparseData(); |
| 92 |
| 93 // Adds the provided |flags| to the current EntryFlags for this entry. |
| 94 void SetEntryFlags(uint32 flags); |
| 95 |
| 96 // Returns the current EntryFlags for this entry. |
| 97 uint32 GetEntryFlags(); |
| 98 |
| 99 // Gets the data stored at the given index. If the information is in memory, |
| 100 // a buffer will be allocated and the data will be copied to it (the caller |
| 101 // can find out the size of the buffer before making this call). Otherwise, |
| 102 // the cache address of the data will be returned, and that address will be |
| 103 // removed from the regular book keeping of this entry so the caller is |
| 104 // responsible for deleting the block (or file) from the backing store at some |
| 105 // point; there is no need to report any storage-size change, only to do the |
| 106 // actual cleanup. |
| 107 void GetData(int index, char** buffer, Addr* address); |
| 108 |
| 109 |
| 110 DISALLOW_COPY_AND_ASSIGN(EntryOperation); |
| 111 }; |
| 112 |
| 113 } // namespace disk_cache |
| 114 |
| 115 #endif // NET_DISK_CACHE_V3_ENTRY_OPERATION_H_ |
OLD | NEW |