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 #include "net/disk_cache/simple/simple_entry_impl.h" | 5 #include "net/disk_cache/simple/simple_entry_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 24 matching lines...) Expand all Loading... | |
35 | 35 |
36 // static | 36 // static |
37 int SimpleEntryImpl::OpenEntry(SimpleIndex* index, | 37 int SimpleEntryImpl::OpenEntry(SimpleIndex* index, |
38 const FilePath& path, | 38 const FilePath& path, |
39 const std::string& key, | 39 const std::string& key, |
40 Entry** entry, | 40 Entry** entry, |
41 const CompletionCallback& callback) { | 41 const CompletionCallback& callback) { |
42 // TODO(gavinp): More closely unify the last_used_ in the | 42 // TODO(gavinp): More closely unify the last_used_ in the |
43 // SimpleSynchronousEntry and the SimpleIndex. | 43 // SimpleSynchronousEntry and the SimpleIndex. |
44 if (!index || index->UseIfExists(key)) { | 44 if (!index || index->UseIfExists(key)) { |
45 // We insert the entry in the index before creating the entry files in the | |
46 // SimpleSynchronousEntry, because this way the worse scenario is when we | |
47 // have the entry in the index but we don't have the created files yet, this | |
48 // way we never leak files. CreationOperationComplete will remove the entry | |
49 // from the index if the creation fails. | |
50 // Same is true for the CreateEntry() bellow. | |
51 if (index) | |
52 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.
| |
45 scoped_refptr<SimpleEntryImpl> new_entry = | 53 scoped_refptr<SimpleEntryImpl> new_entry = |
46 new SimpleEntryImpl(index, path, key); | 54 new SimpleEntryImpl(index, path, key); |
47 SynchronousCreationCallback sync_creation_callback = | 55 SynchronousCreationCallback sync_creation_callback = |
48 base::Bind(&SimpleEntryImpl::CreationOperationComplete, | 56 base::Bind(&SimpleEntryImpl::CreationOperationComplete, |
49 new_entry, entry, callback); | 57 new_entry, entry, callback); |
50 WorkerPool::PostTask(FROM_HERE, | 58 WorkerPool::PostTask(FROM_HERE, |
51 base::Bind(&SimpleSynchronousEntry::OpenEntry, path, | 59 base::Bind(&SimpleSynchronousEntry::OpenEntry, path, |
52 key, MessageLoopProxy::current(), | 60 key, MessageLoopProxy::current(), |
53 sync_creation_callback), | 61 sync_creation_callback), |
54 true); | 62 true); |
55 return net::ERR_IO_PENDING; | 63 return net::ERR_IO_PENDING; |
56 } | 64 } |
57 return net::ERR_FAILED; | 65 return net::ERR_FAILED; |
58 } | 66 } |
59 | 67 |
60 // static | 68 // static |
61 int SimpleEntryImpl::CreateEntry(SimpleIndex* index, | 69 int SimpleEntryImpl::CreateEntry(SimpleIndex* index, |
62 const FilePath& path, | 70 const FilePath& path, |
63 const std::string& key, | 71 const std::string& key, |
64 Entry** entry, | 72 Entry** entry, |
65 const CompletionCallback& callback) { | 73 const CompletionCallback& callback) { |
74 // See comment on OpenEntry regarding inserting the entry in the index. | |
75 if (index) | |
76 index->Insert(key); | |
66 scoped_refptr<SimpleEntryImpl> new_entry = | 77 scoped_refptr<SimpleEntryImpl> new_entry = |
67 new SimpleEntryImpl(index, path, key); | 78 new SimpleEntryImpl(index, path, key); |
68 SynchronousCreationCallback sync_creation_callback = | 79 SynchronousCreationCallback sync_creation_callback = |
69 base::Bind(&SimpleEntryImpl::CreationOperationComplete, | 80 base::Bind(&SimpleEntryImpl::CreationOperationComplete, |
70 new_entry, entry, callback); | 81 new_entry, entry, callback); |
71 WorkerPool::PostTask(FROM_HERE, | 82 WorkerPool::PostTask(FROM_HERE, |
72 base::Bind(&SimpleSynchronousEntry::CreateEntry, path, | 83 base::Bind(&SimpleSynchronousEntry::CreateEntry, path, |
73 key, MessageLoopProxy::current(), | 84 key, MessageLoopProxy::current(), |
74 sync_creation_callback), | 85 sync_creation_callback), |
75 true); | 86 true); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 // The reference held by the Callback calling us will go out of scope and | 338 // The reference held by the Callback calling us will go out of scope and |
328 // delete |this| on leaving this scope. | 339 // delete |this| on leaving this scope. |
329 return; | 340 return; |
330 } | 341 } |
331 // The Backend interface requires us to return |this|, and keep the Entry | 342 // The Backend interface requires us to return |this|, and keep the Entry |
332 // alive until Entry::Close(). Adding a reference to self will keep |this| | 343 // alive until Entry::Close(). Adding a reference to self will keep |this| |
333 // alive after the scope of the Callback calling us is destroyed. | 344 // alive after the scope of the Callback calling us is destroyed. |
334 AddRef(); // Balanced in CloseInternal(). | 345 AddRef(); // Balanced in CloseInternal(). |
335 synchronous_entry_ = sync_entry; | 346 synchronous_entry_ = sync_entry; |
336 SetSynchronousData(); | 347 SetSynchronousData(); |
337 if (index_) | |
338 index_->Insert(key_); | |
339 *out_entry = this; | 348 *out_entry = this; |
340 completion_callback.Run(net::OK); | 349 completion_callback.Run(net::OK); |
341 } | 350 } |
342 | 351 |
343 void SimpleEntryImpl::EntryOperationComplete( | 352 void SimpleEntryImpl::EntryOperationComplete( |
344 const CompletionCallback& completion_callback, | 353 const CompletionCallback& completion_callback, |
345 int result) { | 354 int result) { |
346 DCHECK(io_thread_checker_.CalledOnValidThread()); | 355 DCHECK(io_thread_checker_.CalledOnValidThread()); |
347 DCHECK(synchronous_entry_); | 356 DCHECK(synchronous_entry_); |
348 DCHECK(operation_running_); | 357 DCHECK(operation_running_); |
(...skipping 19 matching lines...) Expand all Loading... | |
368 // adding an IO thread index (for fast misses etc...), we can store this data | 377 // adding an IO thread index (for fast misses etc...), we can store this data |
369 // in that structure. This also solves problems with last_used() on ext4 | 378 // in that structure. This also solves problems with last_used() on ext4 |
370 // filesystems not being accurate. | 379 // filesystems not being accurate. |
371 last_used_ = synchronous_entry_->last_used(); | 380 last_used_ = synchronous_entry_->last_used(); |
372 last_modified_ = synchronous_entry_->last_modified(); | 381 last_modified_ = synchronous_entry_->last_modified(); |
373 for (int i = 0; i < kSimpleEntryFileCount; ++i) | 382 for (int i = 0; i < kSimpleEntryFileCount; ++i) |
374 data_size_[i] = synchronous_entry_->data_size(i); | 383 data_size_[i] = synchronous_entry_->data_size(i); |
375 } | 384 } |
376 | 385 |
377 } // namespace disk_cache | 386 } // namespace disk_cache |
OLD | NEW |