Chromium Code Reviews| Index: net/disk_cache/simple/simple_entry_impl.cc |
| diff --git a/net/disk_cache/simple/simple_entry_impl.cc b/net/disk_cache/simple/simple_entry_impl.cc |
| index 4fa31adb26e38ed8ede677fab3afc45e69d75a7b..175ec22fcf869605baf37aa5012280b9cd8b487f 100644 |
| --- a/net/disk_cache/simple/simple_entry_impl.cc |
| +++ b/net/disk_cache/simple/simple_entry_impl.cc |
| @@ -42,6 +42,14 @@ int SimpleEntryImpl::OpenEntry(SimpleIndex* index, |
| // TODO(gavinp): More closely unify the last_used_ in the |
| // SimpleSynchronousEntry and the SimpleIndex. |
| if (!index || index->UseIfExists(key)) { |
| + // We insert the entry in the index before creating the entry files in the |
| + // SimpleSynchronousEntry, because this way the worse scenario is when we |
| + // have the entry in the index but we don't have the created files yet, this |
| + // way we never leak files. CreationOperationComplete will remove the entry |
| + // from the index if the creation fails. |
| + // Same is true for the CreateEntry() bellow. |
| + if (index) |
| + index->Insert(key); |
|
gavinp
2013/04/19 09:30:17
This is dead code. Either index is null, or index-
felipeg
2013/04/19 10:14:05
Done.
|
| scoped_refptr<SimpleEntryImpl> new_entry = |
| new SimpleEntryImpl(index, path, key); |
| SynchronousCreationCallback sync_creation_callback = |
| @@ -63,6 +71,9 @@ int SimpleEntryImpl::CreateEntry(SimpleIndex* index, |
| const std::string& key, |
| Entry** entry, |
| const CompletionCallback& callback) { |
| + // See comment on OpenEntry regarding inserting the entry in the index. |
| + if (index) |
| + index->Insert(key); |
| scoped_refptr<SimpleEntryImpl> new_entry = |
| new SimpleEntryImpl(index, path, key); |
| SynchronousCreationCallback sync_creation_callback = |
| @@ -334,8 +345,6 @@ void SimpleEntryImpl::CreationOperationComplete( |
| AddRef(); // Balanced in CloseInternal(). |
| synchronous_entry_ = sync_entry; |
| SetSynchronousData(); |
| - if (index_) |
| - index_->Insert(key_); |
| *out_entry = this; |
| completion_callback.Run(net::OK); |
| } |