Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_SIMPLE_SIMPLE_ENTRY_IMPL_H_ | 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ |
| 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ | 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ |
| 7 | 7 |
| 8 #include <queue> | 8 #include <queue> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 void EntryOperationComplete(int stream_index, | 200 void EntryOperationComplete(int stream_index, |
| 201 const CompletionCallback& completion_callback, | 201 const CompletionCallback& completion_callback, |
| 202 const SimpleEntryStat& entry_stat, | 202 const SimpleEntryStat& entry_stat, |
| 203 scoped_ptr<int> result); | 203 scoped_ptr<int> result); |
| 204 | 204 |
| 205 // Called after an asynchronous read. Updates |crc32s_| if possible. | 205 // Called after an asynchronous read. Updates |crc32s_| if possible. |
| 206 void ReadOperationComplete(int stream_index, | 206 void ReadOperationComplete(int stream_index, |
| 207 int offset, | 207 int offset, |
| 208 const CompletionCallback& completion_callback, | 208 const CompletionCallback& completion_callback, |
| 209 scoped_ptr<uint32> read_crc32, | 209 scoped_ptr<uint32> read_crc32, |
| 210 scoped_ptr<base::Time> last_used, | 210 scoped_ptr<SimpleEntryStat> entry_stat, |
| 211 scoped_ptr<int> result); | 211 scoped_ptr<int> result); |
| 212 | 212 |
| 213 // Called after an asynchronous write completes. | 213 // Called after an asynchronous write completes. |
| 214 void WriteOperationComplete(int stream_index, | 214 void WriteOperationComplete(int stream_index, |
| 215 const CompletionCallback& completion_callback, | 215 const CompletionCallback& completion_callback, |
| 216 scoped_ptr<SimpleEntryStat> entry_stat, | 216 scoped_ptr<SimpleEntryStat> entry_stat, |
| 217 scoped_ptr<int> result); | 217 scoped_ptr<int> result); |
| 218 | 218 |
| 219 // Called after validating the checksums on an entry. Passes through the | 219 // Called after validating the checksums on an entry. Passes through the |
| 220 // original result if successful, propogates the error if the checksum does | 220 // original result if successful, propogates the error if the checksum does |
| 221 // not validate. | 221 // not validate. |
| 222 void ChecksumOperationComplete( | 222 void ChecksumOperationComplete( |
| 223 int stream_index, | 223 int stream_index, |
| 224 int orig_result, | 224 int orig_result, |
| 225 const CompletionCallback& completion_callback, | 225 const CompletionCallback& completion_callback, |
| 226 scoped_ptr<int> result); | 226 scoped_ptr<int> result); |
| 227 | 227 |
| 228 // Called after completion of asynchronous IO and receiving file metadata for | 228 // Called after completion of asynchronous IO and receiving file metadata for |
| 229 // the entry in |entry_stat|. Updates the metadata in the entry and in the | 229 // the entry in |entry_stat|. Updates the metadata in the entry and in the |
| 230 // index to make them available on next IO operations. | 230 // index to make them available on next IO operations. |
| 231 void UpdateDataFromEntryStat(const SimpleEntryStat& entry_stat); | 231 void UpdateDataFromEntryStat(const SimpleEntryStat& entry_stat); |
| 232 | 232 |
| 233 int64 GetDiskUsage() const; | 233 int64 GetDiskUsage() const; |
| 234 | 234 |
| 235 // Used to report histograms. | 235 // Used to report histograms. |
| 236 void RecordReadIsParallelizable(const SimpleEntryOperation& operation) const; | 236 void RecordReadIsParallelizable(const SimpleEntryOperation& operation) const; |
| 237 void RecordWriteDependencyType(const SimpleEntryOperation& operation) const; | 237 void RecordWriteDependencyType(const SimpleEntryOperation& operation) const; |
| 238 | 238 |
| 239 // Reads from the stream 0 data kept in memory. | |
| 240 int ReadStream0Data(net::IOBuffer* buf, int offset, int buf_len); | |
| 241 | |
| 242 // Writes to the stream 0 data kept in memory. | |
| 243 int WriteStream0Data(net::IOBuffer* buf, | |
|
pasko
2013/09/09 20:01:22
I find this name confusing. I would prefer CopyStr
clamy
2013/09/10 14:35:59
Done.
| |
| 244 int offset, int buf_len, | |
| 245 bool truncate); | |
| 246 | |
| 239 // All nonstatic SimpleEntryImpl methods should always be called on the IO | 247 // All nonstatic SimpleEntryImpl methods should always be called on the IO |
| 240 // thread, in all cases. |io_thread_checker_| documents and enforces this. | 248 // thread, in all cases. |io_thread_checker_| documents and enforces this. |
| 241 base::ThreadChecker io_thread_checker_; | 249 base::ThreadChecker io_thread_checker_; |
| 242 | 250 |
| 243 base::WeakPtr<SimpleBackendImpl> backend_; | 251 base::WeakPtr<SimpleBackendImpl> backend_; |
| 244 const net::CacheType cache_type_; | 252 const net::CacheType cache_type_; |
| 245 const scoped_refptr<base::TaskRunner> worker_pool_; | 253 const scoped_refptr<base::TaskRunner> worker_pool_; |
| 246 const base::FilePath path_; | 254 const base::FilePath path_; |
| 247 const uint64 entry_hash_; | 255 const uint64 entry_hash_; |
| 248 const bool use_optimistic_operations_; | 256 const bool use_optimistic_operations_; |
| 249 std::string key_; | 257 std::string key_; |
| 250 | 258 |
| 251 // |last_used_|, |last_modified_| and |data_size_| are copied from the | 259 // |last_used_|, |last_modified_| and |data_size_| are copied from the |
| 252 // synchronous entry at the completion of each item of asynchronous IO. | 260 // synchronous entry at the completion of each item of asynchronous IO. |
| 253 // TODO(clamy): Unify last_used_ with data in the index. | 261 // TODO(clamy): Unify last_used_ with data in the index. |
| 254 base::Time last_used_; | 262 base::Time last_used_; |
| 255 base::Time last_modified_; | 263 base::Time last_modified_; |
| 256 int32 data_size_[kSimpleEntryFileCount]; | 264 int32 data_size_[kSimpleEntryStreamCount]; |
| 257 | 265 |
| 258 // Number of times this object has been returned from Backend::OpenEntry() and | 266 // Number of times this object has been returned from Backend::OpenEntry() and |
| 259 // Backend::CreateEntry() without subsequent Entry::Close() calls. Used to | 267 // Backend::CreateEntry() without subsequent Entry::Close() calls. Used to |
| 260 // notify the backend when this entry not used by any callers. | 268 // notify the backend when this entry not used by any callers. |
| 261 int open_count_; | 269 int open_count_; |
| 262 | 270 |
| 263 State state_; | 271 State state_; |
| 264 | 272 |
| 265 // When possible, we compute a crc32, for the data in each entry as we read or | 273 // When possible, we compute a crc32, for the data in each entry as we read or |
| 266 // write. For each stream, |crc32s_[index]| is the crc32 of that stream from | 274 // write. For each stream, |crc32s_[index]| is the crc32 of that stream from |
| 267 // [0 .. |crc32s_end_offset_|). If |crc32s_end_offset_[index] == 0| then the | 275 // [0 .. |crc32s_end_offset_|). If |crc32s_end_offset_[index] == 0| then the |
| 268 // value of |crc32s_[index]| is undefined. | 276 // value of |crc32s_[index]| is undefined. |
| 269 int32 crc32s_end_offset_[kSimpleEntryFileCount]; | 277 int32 crc32s_end_offset_[kSimpleEntryStreamCount]; |
| 270 uint32 crc32s_[kSimpleEntryFileCount]; | 278 uint32 crc32s_[kSimpleEntryStreamCount]; |
| 271 | 279 |
| 272 // If |have_written_[index]| is true, we have written to the stream |index|. | 280 // If |have_written_[index]| is true, we have written to the stream |index|. |
| 273 bool have_written_[kSimpleEntryFileCount]; | 281 bool have_written_[kSimpleEntryStreamCount]; |
| 274 | 282 |
| 275 // Reflects how much CRC checking has been done with the entry. This state is | 283 // Reflects how much CRC checking has been done with the entry. This state is |
| 276 // reported on closing each entry stream. | 284 // reported on closing each entry stream. |
| 277 CheckCrcResult crc_check_state_[kSimpleEntryFileCount]; | 285 CheckCrcResult crc_check_state_[kSimpleEntryStreamCount]; |
| 278 | 286 |
| 279 // The |synchronous_entry_| is the worker thread object that performs IO on | 287 // The |synchronous_entry_| is the worker thread object that performs IO on |
| 280 // entries. It's owned by this SimpleEntryImpl whenever |operation_running_| | 288 // entries. It's owned by this SimpleEntryImpl whenever |operation_running_| |
| 281 // is false (i.e. when an operation is not pending on the worker pool). | 289 // is false (i.e. when an operation is not pending on the worker pool). |
| 282 SimpleSynchronousEntry* synchronous_entry_; | 290 SimpleSynchronousEntry* synchronous_entry_; |
| 283 | 291 |
| 284 std::queue<SimpleEntryOperation> pending_operations_; | 292 std::queue<SimpleEntryOperation> pending_operations_; |
| 285 | 293 |
| 286 net::BoundNetLog net_log_; | 294 net::BoundNetLog net_log_; |
| 287 | 295 |
| 288 scoped_ptr<SimpleEntryOperation> executing_operation_; | 296 scoped_ptr<SimpleEntryOperation> executing_operation_; |
| 297 | |
| 298 scoped_refptr<net::IOBuffer> stream_0_data_; | |
|
pasko
2013/09/09 20:01:22
We should have an explanation why stream 0 is spec
clamy
2013/09/10 14:35:59
Done.
| |
| 289 }; | 299 }; |
| 290 | 300 |
| 291 } // namespace disk_cache | 301 } // namespace disk_cache |
| 292 | 302 |
| 293 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ | 303 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ |
| OLD | NEW |