| OLD | NEW |
| 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_DISK_CACHE_ENTRY_IMPL_H_ | 5 #ifndef NET_DISK_CACHE_ENTRY_IMPL_H_ |
| 6 #define NET_DISK_CACHE_ENTRY_IMPL_H_ | 6 #define NET_DISK_CACHE_ENTRY_IMPL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 10 #include "net/disk_cache/disk_cache.h" | 10 #include "net/disk_cache/disk_cache.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 // the upgrade tool. | 126 // the upgrade tool. |
| 127 void SetTimes(base::Time last_used, base::Time last_modified); | 127 void SetTimes(base::Time last_used, base::Time last_modified); |
| 128 | 128 |
| 129 // Generates a histogram for the time spent working on this operation. | 129 // Generates a histogram for the time spent working on this operation. |
| 130 void ReportIOTime(Operation op, const base::TimeTicks& start); | 130 void ReportIOTime(Operation op, const base::TimeTicks& start); |
| 131 | 131 |
| 132 private: | 132 private: |
| 133 enum { | 133 enum { |
| 134 kNumStreams = 3 | 134 kNumStreams = 3 |
| 135 }; | 135 }; |
| 136 class UserBuffer; |
| 136 | 137 |
| 137 ~EntryImpl(); | 138 ~EntryImpl(); |
| 138 | 139 |
| 139 // Initializes the storage for an internal or external data block. | 140 // Initializes the storage for an internal or external data block. |
| 140 bool CreateDataBlock(int index, int size); | 141 bool CreateDataBlock(int index, int size); |
| 141 | 142 |
| 142 // Initializes the storage for an internal or external generic block. | 143 // Initializes the storage for an internal or external generic block. |
| 143 bool CreateBlock(int size, Addr* address); | 144 bool CreateBlock(int size, Addr* address); |
| 144 | 145 |
| 145 // Deletes the data pointed by address, maybe backed by files_[index]. | 146 // Deletes the data pointed by address, maybe backed by files_[index]. |
| 146 void DeleteData(Addr address, int index); | 147 void DeleteData(Addr address, int index); |
| 147 | 148 |
| 148 // Updates ranking information. | 149 // Updates ranking information. |
| 149 void UpdateRank(bool modified); | 150 void UpdateRank(bool modified); |
| 150 | 151 |
| 151 // Returns a pointer to the file that stores the given address. | 152 // Returns a pointer to the file that stores the given address. |
| 152 File* GetBackingFile(Addr address, int index); | 153 File* GetBackingFile(Addr address, int index); |
| 153 | 154 |
| 154 // Returns a pointer to the file that stores external data. | 155 // Returns a pointer to the file that stores external data. |
| 155 File* GetExternalFile(Addr address, int index); | 156 File* GetExternalFile(Addr address, int index); |
| 156 | 157 |
| 157 // Prepares the target file or buffer for a write of buf_len bytes at the | 158 // Prepares the target file or buffer for a write of buf_len bytes at the |
| 158 // given offset. | 159 // given offset. |
| 159 bool PrepareTarget(int index, int offset, int buf_len, bool truncate); | 160 bool PrepareTarget(int index, int offset, int buf_len, bool truncate); |
| 160 | 161 |
| 161 // Grows the size of the storage used to store user data, if needed. | 162 // Adjusts the internal buffer and file handle for a write that truncates this |
| 162 bool GrowUserBuffer(int index, int offset, int buf_len, bool truncate); | 163 // stream. |
| 164 bool HandleTruncation(int index, int offset, int buf_len); |
| 165 |
| 166 // Copies data from disk to the internal buffer. |
| 167 bool CopyToLocalBuffer(int index); |
| 163 | 168 |
| 164 // Reads from a block data file to this object's memory buffer. | 169 // Reads from a block data file to this object's memory buffer. |
| 165 bool MoveToLocalBuffer(int index); | 170 bool MoveToLocalBuffer(int index); |
| 166 | 171 |
| 167 // Loads the external file to this object's memory buffer. | 172 // Loads the external file to this object's memory buffer. |
| 168 bool ImportSeparateFile(int index, int offset, int buf_len); | 173 bool ImportSeparateFile(int index, int new_size); |
| 169 | 174 |
| 170 // Flush the in-memory data to the backing storage. | 175 // Makes sure that the internal buffer can handle the a write of |buf_len| |
| 171 bool Flush(int index, int size, bool async); | 176 // bytes to |offset|. |
| 177 bool PrepareBuffer(int index, int offset, int buf_len); |
| 178 |
| 179 // Flushes the in-memory data to the backing storage. |
| 180 bool Flush(int index); |
| 181 |
| 182 // Updates the size of a given data stream. |
| 183 void UpdateSize(int index, int old_size, int new_size); |
| 172 | 184 |
| 173 // Initializes the sparse control object. Returns a net error code. | 185 // Initializes the sparse control object. Returns a net error code. |
| 174 int InitSparseData(); | 186 int InitSparseData(); |
| 175 | 187 |
| 176 // Adds the provided |flags| to the current EntryFlags for this entry. | 188 // Adds the provided |flags| to the current EntryFlags for this entry. |
| 177 void SetEntryFlags(uint32 flags); | 189 void SetEntryFlags(uint32 flags); |
| 178 | 190 |
| 179 // Returns the current EntryFlags for this entry. | 191 // Returns the current EntryFlags for this entry. |
| 180 uint32 GetEntryFlags(); | 192 uint32 GetEntryFlags(); |
| 181 | 193 |
| 182 // Gets the data stored at the given index. If the information is in memory, | 194 // Gets the data stored at the given index. If the information is in memory, |
| 183 // a buffer will be allocated and the data will be copied to it (the caller | 195 // a buffer will be allocated and the data will be copied to it (the caller |
| 184 // can find out the size of the buffer before making this call). Otherwise, | 196 // can find out the size of the buffer before making this call). Otherwise, |
| 185 // the cache address of the data will be returned, and that address will be | 197 // the cache address of the data will be returned, and that address will be |
| 186 // removed from the regular book keeping of this entry so the caller is | 198 // removed from the regular book keeping of this entry so the caller is |
| 187 // responsible for deleting the block (or file) from the backing store at some | 199 // responsible for deleting the block (or file) from the backing store at some |
| 188 // point; there is no need to report any storage-size change, only to do the | 200 // point; there is no need to report any storage-size change, only to do the |
| 189 // actual cleanup. | 201 // actual cleanup. |
| 190 void GetData(int index, char** buffer, Addr* address); | 202 void GetData(int index, char** buffer, Addr* address); |
| 191 | 203 |
| 192 // Logs this entry to the internal trace buffer. | 204 // Logs this entry to the internal trace buffer. |
| 193 void Log(const char* msg); | 205 void Log(const char* msg); |
| 194 | 206 |
| 195 CacheEntryBlock entry_; // Key related information for this entry. | 207 CacheEntryBlock entry_; // Key related information for this entry. |
| 196 CacheRankingsBlock node_; // Rankings related information for this entry. | 208 CacheRankingsBlock node_; // Rankings related information for this entry. |
| 197 BackendImpl* backend_; // Back pointer to the cache. | 209 BackendImpl* backend_; // Back pointer to the cache. |
| 198 scoped_array<char> user_buffers_[kNumStreams]; // Store user data. | 210 scoped_ptr<UserBuffer> user_buffers_[kNumStreams]; // Stores user data. |
| 199 // Files to store external user data and key. | 211 // Files to store external user data and key. |
| 200 scoped_refptr<File> files_[kNumStreams + 1]; | 212 scoped_refptr<File> files_[kNumStreams + 1]; |
| 201 mutable std::string key_; // Copy of the key. | 213 mutable std::string key_; // Copy of the key. |
| 202 int unreported_size_[kNumStreams]; // Bytes not reported yet to the backend. | 214 int unreported_size_[kNumStreams]; // Bytes not reported yet to the backend. |
| 203 bool doomed_; // True if this entry was removed from the cache. | 215 bool doomed_; // True if this entry was removed from the cache. |
| 204 scoped_ptr<SparseControl> sparse_; // Support for sparse entries. | 216 scoped_ptr<SparseControl> sparse_; // Support for sparse entries. |
| 205 | 217 |
| 206 DISALLOW_COPY_AND_ASSIGN(EntryImpl); | 218 DISALLOW_COPY_AND_ASSIGN(EntryImpl); |
| 207 }; | 219 }; |
| 208 | 220 |
| 209 } // namespace disk_cache | 221 } // namespace disk_cache |
| 210 | 222 |
| 211 #endif // NET_DISK_CACHE_ENTRY_IMPL_H_ | 223 #endif // NET_DISK_CACHE_ENTRY_IMPL_H_ |
| OLD | NEW |